Add user deletion, ProseA hover cards, Canvas

This commit is contained in:
2024-11-10 22:29:59 +01:00
parent 057efb848c
commit 42658558c5
23 changed files with 476 additions and 100 deletions

View File

@@ -1,45 +1,41 @@
import { and, eq, like, sql } from 'drizzle-orm';
import useDatabase from '~/composables/useDatabase';
import type { File } from '~/types/api';
import { explorerContentTable } from '~/db/schema';
export default defineEventHandler(async (e) => {
const project = getRouterParam(e, "projectId");
const query = getQuery(e);
if(!project)
{
setResponseStatus(e, 404);
return;
}
const where = [];
const criteria: Record<string, any> = { };
if(query && query.path !== undefined)
{
where.push("path = $path");
criteria["$path"] = query.path;
where.push(eq(explorerContentTable.path, sql.placeholder('path')));
}
if(query && query.title !== undefined)
{
where.push("title = $title");
criteria["$title"] = query.title;
where.push(eq(explorerContentTable.title, sql.placeholder('title')));
}
if(query && query.type !== undefined)
{
where.push("type = $type");
criteria["$type"] = query.type;
where.push(eq(explorerContentTable.type, sql.placeholder('type')));
}
if (query && query.search !== undefined)
{
where.push("path LIKE $search");
criteria["$search"] = query.search;
where.push(like(explorerContentTable.path, sql.placeholder('search')));
}
if(where.length > 1)
if(where.length > 0)
{
const db = useDatabase();
const content = db.query(`SELECT * FROM explorer_files WHERE ${where.join(" and ")}`).all(criteria) as File[];
const content = db.select({
'path': explorerContentTable.path,
'owner': explorerContentTable.owner,
'title': explorerContentTable.title,
'type': explorerContentTable.type,
'content': sql<string>`cast(${explorerContentTable.content} as TEXT)`.as('content'),
'navigable': explorerContentTable.navigable,
'private': explorerContentTable.private,
}).from(explorerContentTable).where(and(...where)).prepare().all(query);
if(content.length > 0)
{

View File

@@ -0,0 +1,30 @@
import { eq } from "drizzle-orm";
import useDatabase from "~/composables/useDatabase";
import { usersTable } from "~/db/schema";
export default defineEventHandler(async (e) => {
const session = await getUserSession(e);
if(!session.user)
{
setResponseStatus(e, 404);
return;
}
const id = getRouterParam(e, 'id');
if(!id)
{
setResponseStatus(e, 400);
return;
}
if(session.user.id.toString() !== id)
{
setResponseStatus(e, 403);
return;
}
const db = useDatabase();
clearUserSession(e);
db.delete(usersTable).where(eq(usersTable.id, session.user.id)).run();
});