New Canvas zoom with dbl click and starting to work on tag API

This commit is contained in:
2024-09-03 16:42:57 +02:00
parent c091a6d261
commit 2b293a0c1a
16 changed files with 353 additions and 77 deletions

View File

@@ -1,27 +0,0 @@
import useDatabase from '~/composables/useDatabase';
import { Comment } from '~/types/api';
export default defineEventHandler(async (e) => {
const project = getRouterParam(e, "projectId");
const query = getQuery(e);
if(!project || !query.path)
{
setResponseStatus(e, 404);
return;
}
const where = ["project = $project", "path = $path"];
const criteria: Record<string, any> = { $project: project, $path: query.path };
if(where.length > 1)
{
const db = useDatabase();
const content = db.query(`SELECT * FROM explorer_comments WHERE ${where.join(" and ")}`).all(criteria) as Comment[];
return content;
}
setResponseStatus(e, 404);
});

View File

@@ -0,0 +1,41 @@
import useDatabase from '~/composables/useDatabase';
import type { CommentedFile, CommentSearch, File } from '~/types/api';
export default defineCachedEventHandler(async (e) => {
const project = getRouterParam(e, "projectId");
const path = decodeURIComponent(getRouterParam(e, "path") ?? '');
if(!project)
{
setResponseStatus(e, 404);
return;
}
if(!path)
{
setResponseStatus(e, 404);
return;
}
const where = ["project = $project", "path = $path"];
const criteria: Record<string, any> = { $project: project, $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, "projectId")}-${getRouterParam(e, "path")}`
});

View File

@@ -0,0 +1,39 @@
import useDatabase from '~/composables/useDatabase';
import type { Tag } from '~/types/api';
export default defineCachedEventHandler(async (e) => {
const project = getRouterParam(e, "projectId");
const tag = getRouterParam(e, "tag");
const query = getQuery(e);
if(!project)
{
setResponseStatus(e, 404);
return;
}
if(!tag)
{
setResponseStatus(e, 404);
return;
}
const where = ["project = $project", "tag = $tag"];
const criteria: Record<string, any> = { $project: project, $tag: tag };
if(where.length > 1)
{
const db = useDatabase();
const content = db.query(`SELECT * FROM explorer_tags WHERE ${where.join(" and ")}`).get(criteria) as Tag;
if(content !== undefined)
{
return content;
}
}
setResponseStatus(e, 404);
}, {
maxAge: 60*60*24,
getKey: (e) => `tag-${getRouterParam(e, "projectId")}-${getRouterParam(e, "tag")}`
});