Skip to content

Commit

Permalink
fix: strip data uri prefix, close koishijs#90
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 29, 2022
1 parent 3f885f8 commit 0fd29ef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,/, '')
}

0 comments on commit 0fd29ef

Please sign in to comment.