You've already forked obsidian-visualiser
Database and markdown refactoring
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
|
||||
export interface Comment
|
||||
{
|
||||
user: number;
|
||||
file: string;
|
||||
position: number;
|
||||
length: number;
|
||||
sequence: number;
|
||||
text: string;
|
||||
}
|
||||
export default defineEventHandler(async (e) => {
|
||||
const query = getQuery(e);
|
||||
|
||||
if(query && query.route !== undefined)
|
||||
{
|
||||
const db = useDatabase();
|
||||
|
||||
const comments = db.query("SELECT * FROM comments WHERE file = ?1").all(query.route as string) as Comment[];
|
||||
|
||||
return comments;
|
||||
}
|
||||
|
||||
setResponseStatus(e, 404);
|
||||
});
|
||||
898
server/api/project.get.ts
Normal file
898
server/api/project.get.ts
Normal file
File diff suppressed because one or more lines are too long
54
server/api/project/[projectId]/file.get.ts
Normal file
54
server/api/project/[projectId]/file.get.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
|
||||
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(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);
|
||||
});
|
||||
0
server/api/project/[projectId]/file.post.ts
Normal file
0
server/api/project/[projectId]/file.post.ts
Normal file
39
server/api/project/[projectId]/file/[fileId]/comment.get.ts
Normal file
39
server/api/project/[projectId]/file/[fileId]/comment.get.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
{
|
||||
setResponseStatus(e, 404);
|
||||
return;
|
||||
}
|
||||
|
||||
const where = ["project = $project", "file = $file"];
|
||||
const criteria: Record<string, any> = { $project: project, $file: file };
|
||||
|
||||
if(where.length > 1)
|
||||
{
|
||||
const db = useDatabase();
|
||||
|
||||
const content = db.query(`SELECT * FROM explorer_comments WHERE ${where.join(" and ")}`).all(criteria) as Comment[];
|
||||
|
||||
if(content.length > 0)
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
setResponseStatus(e, 404);
|
||||
});
|
||||
52
server/api/project/[projectId]/navigation.get.ts
Normal file
52
server/api/project/[projectId]/navigation.get.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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");
|
||||
|
||||
if(!project)
|
||||
{
|
||||
setResponseStatus(e, 404);
|
||||
return;
|
||||
}
|
||||
|
||||
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[];
|
||||
|
||||
if(content.length > 0)
|
||||
{
|
||||
const navigation: Navigation[] = [];
|
||||
|
||||
for(const item of content)
|
||||
addChild(navigation, item);
|
||||
|
||||
return navigation;
|
||||
}
|
||||
|
||||
setResponseStatus(e, 404);
|
||||
});
|
||||
|
||||
function addChild(arr: Navigation[], e: Navigation): void
|
||||
{
|
||||
const parent = arr.find(f => e.path.startsWith(f.path));
|
||||
|
||||
if(parent)
|
||||
{
|
||||
if(!parent.children)
|
||||
parent.children = [];
|
||||
|
||||
addChild(parent.children, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
arr.push({ title: e.title, path: e.path, type: e.type, order: e.order });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user