30 lines
978 B
TypeScript
30 lines
978 B
TypeScript
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"})
|
|
})
|