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

@@ -267,8 +267,7 @@ def main_dev(opt):
# 检查输出目录是否存在
os.makedirs(opt.outdir, exist_ok=True)
# 绝对路径
outpath = os.path.join(opt.outdir)
outpath = opt.outdir
# 创建水印编码器
wm = "SDV2"
@@ -329,6 +328,7 @@ def main_dev(opt):
for x_sample in x_samples:
print("Sample count:", sample_count)
imge_path = os.path.join(sample_path, f"{base_count:05}.png")
imge_path = os.path.abspath(imge_path) # 转换为绝对路径
x_sample = 255. * rearrange(x_sample.cpu().numpy(), 'c h w -> h w c')
img = Image.fromarray(x_sample.astype(np.uint8))
img = put_watermark(img, wm_encoder)

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}`)
}
})