Fix login, registration and made the first database version.

This commit is contained in:
2024-11-05 19:51:56 +01:00
parent 83ddaf19d4
commit 1af78e5ab7
35 changed files with 180 additions and 391 deletions

View File

@@ -0,0 +1,35 @@
import useDatabase from '~/composables/useDatabase';
import type { CommentedFile, CommentSearch, File } from '~/types/api';
export default defineCachedEventHandler(async (e) => {
const path = decodeURIComponent(getRouterParam(e, "path") ?? '');
if(!path)
{
setResponseStatus(e, 404);
return;
}
const where = ["path = $path"];
const criteria: Record<string, any> = { $path: path };
if(where.length > 1)
{
const db = useDatabase();
const content = db.query(`SELECT * FROM explorer_files WHERE ${where.join(" and ")}`).get(criteria) as File;
if(content !== undefined)
{
const comments = db.query(`SELECT comment.*, user.username FROM explorer_comments comment LEFT JOIN users user ON comment.user_id = user.id WHERE ${where.join(" and ")}`).all(criteria) as CommentSearch[];
return { ...content, comments } as CommentedFile;
}
}
setResponseStatus(e, 404);
return;
}, {
maxAge: 60*60*24,
getKey: (e) => `file-${getRouterParam(e, "path")}`
});