You've already forked obsidian-visualiser
Update DB schema to include an ID and split overview and content. Progressing on ContentEditor with the ID fixing many issues. Adding modal and sync features.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import useDatabase from "~/composables/useDatabase";
|
||||
import { extname, basename } from 'node:path';
|
||||
import type { FileType } from '~/types/content';
|
||||
import type { CanvasColor, CanvasContent } from "~/types/canvas";
|
||||
import { explorerContentTable } from "~/db/schema";
|
||||
import { convertToStorableLinks } from "../api/file.post";
|
||||
import type { FileType, ProjectContent } from "#shared/content.util";
|
||||
import { getID, ID_SIZE } from "#shared/general.util";
|
||||
import { projectContentTable, projectFilesTable } from "~/db/schema";
|
||||
|
||||
const typeMapping: Record<string, FileType> = {
|
||||
".md": "markdown",
|
||||
@@ -17,6 +17,7 @@ export default defineTask({
|
||||
},
|
||||
async run(event) {
|
||||
try {
|
||||
//@ts-ignore
|
||||
const tree = await $fetch('https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/git/trees/master', {
|
||||
method: 'get',
|
||||
headers: {
|
||||
@@ -28,21 +29,23 @@ export default defineTask({
|
||||
}
|
||||
}) as { tree: any[] } & Record<string, any>;
|
||||
|
||||
const files: typeof explorerContentTable.$inferInsert[] = await Promise.all(tree.tree.filter((e: any) => !e.path.startsWith(".")).map(async (e, i) => {
|
||||
const files: ProjectContent[] = await Promise.all(tree.tree.filter((e: any) => !e.path.startsWith(".")).map(async (e, i) => {
|
||||
if(e.type === 'tree')
|
||||
{
|
||||
const title = basename(e.path);
|
||||
const order = /(\d+)\. ?(.+)/gsmi.exec(title);
|
||||
const path = (e.path as string).split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/');
|
||||
return {
|
||||
id: getID(ID_SIZE),
|
||||
path: path.toLowerCase().replaceAll(" ", "-").normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
|
||||
order: i,
|
||||
title: order && order[2] ? order[2] : title,
|
||||
type: 'folder',
|
||||
content: null,
|
||||
owner: '1',
|
||||
owner: 1,
|
||||
navigable: true,
|
||||
private: e.path.startsWith('98.Privé'),
|
||||
timestamp: new Date(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,28 +56,26 @@ export default defineTask({
|
||||
const content = (await $fetch(`https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/raw/${encodeURIComponent(e.path)}`));
|
||||
|
||||
return {
|
||||
id: getID(ID_SIZE),
|
||||
path: (extension === '.md' ? path.replace(extension, '') : path).toLowerCase().replaceAll(" ", "-").normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
|
||||
order: i,
|
||||
title: order && order[2] ? order[2] : title,
|
||||
type: (typeMapping[extension] ?? 'file'),
|
||||
content: reshapeContent(content as string, typeMapping[extension] ?? 'File'),
|
||||
owner: '1',
|
||||
owner: 1,
|
||||
navigable: true,
|
||||
private: e.path.startsWith('98.Privé')
|
||||
private: e.path.startsWith('98.Privé'),
|
||||
timestamp: new Date(),
|
||||
}
|
||||
}));
|
||||
|
||||
const pathList = files.map(e => e.path);
|
||||
files.forEach(e => {
|
||||
if(e.type !== 'folder' && e.content)
|
||||
{
|
||||
e.content = Buffer.from(convertToStorableLinks(e.content.toString('utf-8'), files.map(e => e.path)), 'utf-8');
|
||||
}
|
||||
})
|
||||
|
||||
const db = useDatabase();
|
||||
db.delete(explorerContentTable).run();
|
||||
db.insert(explorerContentTable).values(files).run();
|
||||
db.transaction(tx => {
|
||||
db.delete(projectFilesTable).run();
|
||||
db.insert(projectFilesTable).values(files.map(e => {const { content, ...rest } = e; return rest; })).run();
|
||||
db.delete(projectContentTable).run();
|
||||
db.insert(projectContentTable).values(files.map(e => ({ content: e.content ? Buffer.from(e.content as string) : null, id: e.id }))).run();
|
||||
});
|
||||
|
||||
return { result: true };
|
||||
}
|
||||
@@ -99,8 +100,8 @@ function reshapeContent(content: string, type: FileType): string | null
|
||||
return content;
|
||||
case "canvas":
|
||||
const data = JSON.parse(content) as CanvasContent;
|
||||
data.edges.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
|
||||
data.nodes.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
|
||||
data.edges?.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
|
||||
data.nodes?.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
|
||||
return JSON.stringify(data);
|
||||
default:
|
||||
case 'folder':
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import useDatabase from "~/composables/useDatabase";
|
||||
/*import useDatabase from "~/composables/useDatabase";
|
||||
import type { FileType } from '~/types/content';
|
||||
import { explorerContentTable } from "~/db/schema";
|
||||
import { eq, ne } from "drizzle-orm";
|
||||
@@ -27,4 +27,4 @@ export default defineTask({
|
||||
return { result: false, error: e };
|
||||
}
|
||||
},
|
||||
})
|
||||
})*/
|
||||
Reference in New Issue
Block a user