diff --git a/server.py b/server.py index 6f3eaf5..af08530 100644 --- a/server.py +++ b/server.py @@ -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) diff --git a/server/api/drawing/[id].ts b/server/api/drawing/[id].ts index affc40f..386da32 100644 --- a/server/api/drawing/[id].ts +++ b/server/api/drawing/[id].ts @@ -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写入) diff --git a/server/api/img/[id].ts b/server/api/img/[id].ts new file mode 100644 index 0000000..ce19bd2 --- /dev/null +++ b/server/api/img/[id].ts @@ -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}`) + } + +})