diff --git a/package.json b/package.json index d375f98..56d26e0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-novelai", "description": "Generate images by NovelAI", - "version": "1.12.1", + "version": "1.12.2", "main": "lib/index.js", "typings": "lib/index.d.ts", "files": [ diff --git a/src/index.ts b/src/index.ts index c5df61d..cd1c24d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { Context, Dict, Logger, omit, Quester, segment, Session, trimSlash } from 'koishi' import { Config, modelMap, models, orientMap, parseForbidden, parseInput, sampler } from './config' import { StableDiffusionWebUI } from './types' -import { closestMultiple, download, getImageSize, login, NetworkError, project, resizeInput, Size } from './utils' +import { closestMultiple, download, getImageSize, login, NetworkError, project, resizeInput, Size, stripDataPrefix } from './utils' import {} from '@koishijs/plugin-help' export * from './config' @@ -255,12 +255,12 @@ export function apply(ctx: Context, config: Config) { data, }).then((res) => { if (config.type === 'sd-webui') { - return (res.data as StableDiffusionWebUI.Response).images[0] + return stripDataPrefix((res.data as StableDiffusionWebUI.Response).images[0]) } // event: newImage // id: 1 // data: - return res.data.slice(27) + return res.data?.slice(27) }) let base64: string, count = 0 diff --git a/src/utils.ts b/src/utils.ts index 9c20dca..717daeb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -185,3 +185,9 @@ export function resizeInput(size: Size): Size { return { width, height } } } + +export function stripDataPrefix(base64: string) { + // workaround for different gradio versions + // https://github.com/koishijs/novelai-bot/issues/90 + return base64.replace(/^data:image\/[\w-]+;base64,/, '') +}