file delete manual now

This commit is contained in:
suricatingss
2026-01-19 01:54:02 +00:00
parent 1410dc84f6
commit 9a842cd756
2 changed files with 31 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
import { createReadStream, existsSync, unlink, unlinkSync } from "node:fs"
import { } from "fs/promises"
import { join } from "path"
export default defineEventHandler(async (event) => {
const session = await getUserSession(event)
const conf = await useRuntimeConfig()
//const query = await getQuery(event)
// @ts-ignore
const userId = session.secure?.user_id;
if (userId == undefined || userId == null)
throw createError({ status: 401 })
const file = await getRouterParam(event, 'file');
if (file == undefined)
throw createError({ status: 400, message: "No file"})
//const def_filepath = "/home/suricatingss/Projects/WebStorm/yt2mp3/server/fastapi_server/downloads";
const def_filepath = conf.download_url
const filepath = join(def_filepath, userId.toString(), file.toString())
if ( existsSync(filepath) ) {
unlinkSync(filepath)
return { deleted: true }
} else
throw createError({ status: 404, message: "Not found"})
})

View File

@@ -27,8 +27,9 @@ export default defineEventHandler(async (event) => {
setHeader(event, 'Content-Disposition', `attachment; filename="${file}"`) setHeader(event, 'Content-Disposition', `attachment; filename="${file}"`)
const file_stream = createReadStream(filepath) const file_stream = createReadStream(filepath)
file_stream.on("close", () => unlink(filepath, (err) => { if (err) console.warn(err.message) })) //file_stream.on("close", () => unlink(filepath, (err) => { if (err) console.warn(err.message) }))
return file_stream; return file_stream;
}) })