From 4c05e40a737f9ab15bde9c65073ef6c78d297a84 Mon Sep 17 00:00:00 2001 From: lesion Date: Fri, 26 Aug 2022 16:31:33 +0200 Subject: [PATCH] add images api --- server/api/image/[uuid].js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 server/api/image/[uuid].js diff --git a/server/api/image/[uuid].js b/server/api/image/[uuid].js new file mode 100644 index 0000000..8ec7581 --- /dev/null +++ b/server/api/image/[uuid].js @@ -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)) +})