fix: response type for naifu (#253)

This commit is contained in:
MieMieMieeeee 2024-06-09 22:28:04 +09:00 committed by GitHub
parent 60ff4a21eb
commit 39cdf4fc93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -413,7 +413,7 @@ export function apply(ctx: Context, config: Config) {
method: 'POST',
timeout: config.requestTimeout,
// Since novelai's latest interface returns an application/x-zip-compressed, a responseType must be passed in
responseType: ['login', 'token'].includes(config.type) ? 'arraybuffer' : 'json',
responseType: config.type === 'naifu' ? 'text' : ['login', 'token'].includes(config.type) ? 'arraybuffer' : 'json',
headers: {
...config.headers,
...getHeaders(),
@ -467,8 +467,7 @@ export function apply(ctx: Context, config: Config) {
const b64 = Buffer.from(firstImageBuffer).toString('base64')
return forceDataPrefix(b64, 'image/png')
}
return forceDataPrefix(res.data?.slice(27))
return forceDataPrefix(res.data?.trimEnd().slice(27))
}
let dataUrl: string, count = 0