obsidian-visualiser/server/api/project/[projectId]/file.get.ts

50 lines
1.2 KiB
TypeScript

import useDatabase from '~/composables/useDatabase';
export default defineEventHandler(async (e) => {
const project = getRouterParam(e, "projectId");
const query = getQuery(e);
if(!project)
{
setResponseStatus(e, 404);
return;
}
const where = ["project = $project"];
const criteria: Record<string, any> = { $project: project };
if(query && query.path !== undefined)
{
where.push("path = $path");
criteria["$path"] = query.path;
}
if(query && query.title !== undefined)
{
where.push("title = $title");
criteria["$title"] = query.title;
}
if(query && query.type !== undefined)
{
where.push("type = $type");
criteria["$type"] = query.type;
}
if (query && query.search !== undefined)
{
where.push("path LIKE $search");
criteria["$search"] = query.search;
}
if(where.length > 1)
{
const db = useDatabase();
const content = db.query(`SELECT * FROM explorer_files WHERE ${where.join(" and ")}`).all(criteria) as File[];
if(content.length > 0)
{
return content;
}
}
setResponseStatus(e, 404);
});