25 lines
765 B
TypeScript
25 lines
765 B
TypeScript
import useDatabase from '~/composables/useDatabase';
|
|
import { explorerContentTable } from '~/db/schema';
|
|
import { schema } from '~/schemas/file';
|
|
|
|
export default defineEventHandler(async (e) => {
|
|
const body = await readValidatedBody(e, schema.safeParse);
|
|
if(!body.success)
|
|
{
|
|
setResponseStatus(e, 403);
|
|
throw body.error;
|
|
}
|
|
|
|
const buffer = Buffer.from(body.data.content, 'utf-8');
|
|
|
|
const db = useDatabase();
|
|
const content = db.insert(explorerContentTable).values({ ...body.data, content: buffer }).onConflictDoUpdate({ target: explorerContentTable.path, set: { ...body.data, content: buffer } });
|
|
|
|
if(content !== undefined)
|
|
{
|
|
return content;
|
|
}
|
|
|
|
setResponseStatus(e, 404);
|
|
return;
|
|
}); |