You've already forked obsidian-visualiser
Refactoring search, navigation, canvas and others to fit the new data model
This commit is contained in:
20
server/api/project/[projectId].get.ts
Normal file
20
server/api/project/[projectId].get.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
const project = getRouterParam(e, "projectId");
|
||||
|
||||
const where = ["project = $project"];
|
||||
const criteria: Record<string, any> = { $project: project };
|
||||
|
||||
if (!!project) {
|
||||
const db = useDatabase();
|
||||
|
||||
const content = db.query(`SELECT * FROM explorer_projects WHERE ${where.join(" and ")}`).get(criteria) as Project;
|
||||
|
||||
if (content) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
setResponseStatus(e, 404);
|
||||
});
|
||||
20
server/api/project/[projectId].patch.ts
Normal file
20
server/api/project/[projectId].patch.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
const project = getRouterParam(e, "projectId");
|
||||
|
||||
const where = ["project = $project"];
|
||||
const criteria: Record<string, any> = { $project: project };
|
||||
|
||||
if (!!project) {
|
||||
const db = useDatabase();
|
||||
|
||||
const content = db.query(`SELECT * FROM explorer_projects WHERE ${where.join(" and ")}`).all(criteria) as Project[];
|
||||
|
||||
if (content.length > 0) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
setResponseStatus(e, 404);
|
||||
});
|
||||
20
server/api/project/[projectId].post.ts
Normal file
20
server/api/project/[projectId].post.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
const project = getRouterParam(e, "projectId");
|
||||
|
||||
const where = ["project = $project"];
|
||||
const criteria: Record<string, any> = { $project: project };
|
||||
|
||||
if (!!project) {
|
||||
const db = useDatabase();
|
||||
|
||||
const content = db.query(`SELECT * FROM explorer_projects WHERE ${where.join(" and ")}`).all(criteria) as Project[];
|
||||
|
||||
if (content.length > 0) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
setResponseStatus(e, 404);
|
||||
});
|
||||
@@ -1,27 +1,17 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
|
||||
export interface Comment
|
||||
{
|
||||
file: number;
|
||||
user_id: number;
|
||||
sequence: number;
|
||||
position: number;
|
||||
length: number;
|
||||
content: string;
|
||||
}
|
||||
export default defineEventHandler(async (e) => {
|
||||
const project = getRouterParam(e, "projectId");
|
||||
const file = getRouterParam(e, "fileId");
|
||||
const query = getQuery(e);
|
||||
|
||||
if(!project)
|
||||
if(!project || !query.path)
|
||||
{
|
||||
setResponseStatus(e, 404);
|
||||
return;
|
||||
}
|
||||
|
||||
const where = ["project = $project", "file = $file"];
|
||||
const criteria: Record<string, any> = { $project: project, $file: file };
|
||||
const where = ["project = $project", "path = $path"];
|
||||
const criteria: Record<string, any> = { $project: project, $path: query.path };
|
||||
|
||||
if(where.length > 1)
|
||||
{
|
||||
@@ -1,14 +1,5 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
|
||||
export interface File
|
||||
{
|
||||
id: number;
|
||||
path: string;
|
||||
title: string;
|
||||
type: 'Markdown' | 'Canvas' | 'File';
|
||||
content: string;
|
||||
owner: number;
|
||||
}
|
||||
export default defineEventHandler(async (e) => {
|
||||
const project = getRouterParam(e, "projectId");
|
||||
const query = getQuery(e);
|
||||
@@ -37,6 +28,11 @@ export default defineEventHandler(async (e) => {
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
|
||||
export interface Navigation
|
||||
{
|
||||
title: string;
|
||||
path: string;
|
||||
type: string;
|
||||
order: number
|
||||
children?: Navigation[];
|
||||
}
|
||||
export default defineEventHandler(async (e) => {
|
||||
const project = getRouterParam(e, "projectId");
|
||||
|
||||
@@ -19,7 +11,7 @@ export default defineEventHandler(async (e) => {
|
||||
|
||||
const db = useDatabase();
|
||||
|
||||
const content = db.query(`SELECT "path", "title", "type", "order" FROM explorer_files WHERE project = ?1 and navigable = 1`).all(project!).sort((a: any, b: any) => a.path.length - b.path.length) as any[];
|
||||
const content = db.query(`SELECT "path", "title", "type", "order" FROM explorer_files WHERE project = ?1 and navigable = 1 and private = 0`).all(project!).sort((a: any, b: any) => a.path.length - b.path.length) as any[];
|
||||
|
||||
if(content.length > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user