18 lines
613 B
TypeScript
18 lines
613 B
TypeScript
import fs from 'fs'
|
|
export default defineEventHandler(async event => {
|
|
|
|
// 获取图片
|
|
if (event.node.req.method === 'GET') {
|
|
// 判断当前执行目录是否存在 outputs 文件夹, 否则在上一级文件夹
|
|
let path = `outputs/txt2img-samples/samples/${event.context.params.id}`
|
|
if (!fs.existsSync('outputs')) {
|
|
// 打印当前执行目录
|
|
console.log('cwd:', process.cwd())
|
|
path = `../outputs/txt2img-samples/samples/${event.context.params.id}`
|
|
}
|
|
console.log('path:', path)
|
|
return fs.readFileSync(path)
|
|
}
|
|
|
|
})
|