img server
This commit is contained in:
		
							
								
								
									
										14
									
								
								server/api/img/[id].ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								server/api/img/[id].ts
									
									
									
									
									
										Normal 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}`)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user