img server

This commit is contained in:
2023-02-19 03:54:55 +08:00
parent 830710ae1d
commit 44afb1c797
3 changed files with 21 additions and 3 deletions

View File

@@ -2,7 +2,11 @@ export default defineEventHandler(async event => {
// 获取任务(普通用户只能看到自己的)
if (event.node.req.method === 'GET') {
return await useStorage().getItem(`task:${event.context.params.id}`)
const task = await useStorage().getItem(`task:${event.context.params.id}`)
task.data = task.data.map((image_path: any) => {
return '/api/img/' + image_path.match(/[^\/]+$/)[0]
})
return task
}
// 修改任务(只允许BOT写入)

14
server/api/img/[id].ts Normal file
View File

@@ -0,0 +1,14 @@
import fs from 'fs'
export default defineEventHandler(async event => {
// 获取图片
if (event.node.req.method === 'GET') {
// 判断当前执行目录是否存在 outputs 文件夹, 否则在上一级文件夹
let path = `outputs/outputs/txt2img-samples/samples/${event.context.params.id}`
if (!fs.existsSync('outputs')) {
path = `../outputs/outputs/txt2img-samples/samples/${event.context.params.id}`
}
return await useStorage().getItem(`img:${event.context.params.id}`)
}
})