You've already forked obsidian-visualiser
New Canvas zoom with dbl click and starting to work on tag API
This commit is contained in:
41
server/api/project/[projectId]/file/[path].get.ts
Normal file
41
server/api/project/[projectId]/file/[path].get.ts
Normal 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")}`
|
||||
});
|
||||
Reference in New Issue
Block a user