add images api
This commit is contained in:
parent
f49fdd247a
commit
4c05e40a73
1 changed files with 12 additions and 0 deletions
12
server/api/image/[uuid].js
Normal file
12
server/api/image/[uuid].js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import path from 'path'
|
||||||
|
import { sendStream } from 'h3'
|
||||||
|
|
||||||
|
export default defineEventHandler(event => {
|
||||||
|
const uuid = event.context.params.uuid
|
||||||
|
const filePath = path.resolve('./server/public/images/', uuid)
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
throw new Error('File not found!')
|
||||||
|
}
|
||||||
|
return sendStream(event, fs.createReadStream(filePath))
|
||||||
|
})
|
Loading…
Reference in a new issue