You've already forked obsidian-visualiser
Fix dynamic character sheet loading.
This commit is contained in:
@@ -14,7 +14,7 @@ export default defineEventHandler(async (e) => {
|
||||
try
|
||||
{
|
||||
const id = getRouterParam(e, "id") ?? '';
|
||||
const body = await readRawBody(e);
|
||||
const body = Buffer.from(await readRawBody(e) ?? '');
|
||||
|
||||
if(!id)
|
||||
{
|
||||
@@ -32,7 +32,7 @@ export default defineEventHandler(async (e) => {
|
||||
}
|
||||
|
||||
db.insert(projectContentTable).values({ id: id, content: body }).onConflictDoUpdate({ set: { content: body }, target: projectContentTable.id }).run();
|
||||
db.update(projectFilesTable).set({ timestamp: new Date() }).where(eq(projectFilesTable.id, id)).run()
|
||||
db.update(projectFilesTable).set({ timestamp: new Date() }).where(eq(projectFilesTable.id, id)).run();
|
||||
}
|
||||
catch(_e)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
import { hasPermissions } from "#shared/auth";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { projectFilesTable } from "~/db/schema";
|
||||
import { projectContentTable, projectFilesTable } from "~/db/schema";
|
||||
import { Project } from "~/schemas/project";
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
@@ -19,23 +19,24 @@ export default defineEventHandler(async (e) => {
|
||||
throw body.error;
|
||||
}
|
||||
|
||||
const db = useDatabase(), items = body.data, blocked: string[] = [];
|
||||
const db = useDatabase(), items = body.data, requested: string[] = [];
|
||||
|
||||
db.transaction((tx) => {
|
||||
const data = tx.select({ id: projectFilesTable.id, timestamp: projectFilesTable.timestamp }).from(projectFilesTable).all();
|
||||
const deletion = tx.delete(projectFilesTable).where(eq(projectFilesTable.id, sql.placeholder('id'))).prepare();
|
||||
const deleteOverview = tx.delete(projectFilesTable).where(eq(projectFilesTable.id, sql.placeholder('id'))).prepare();
|
||||
const deleteContent = tx.delete(projectContentTable).where(eq(projectContentTable.id, sql.placeholder('id'))).prepare();
|
||||
|
||||
for(let i = 0; i < items.length; i++)
|
||||
{
|
||||
const item = items[i];
|
||||
const submitted = items[i]!;
|
||||
|
||||
const index = data.findIndex(e => e.id === item.id);
|
||||
const index = data.findIndex(e => e.id === submitted.id);
|
||||
|
||||
if(index !== -1)
|
||||
{
|
||||
if(data[index].timestamp > new Date(item.timestamp))
|
||||
if(data[index]!.timestamp < new Date(submitted.timestamp))
|
||||
{
|
||||
blocked.push(item.id);
|
||||
requested.push(submitted.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -43,34 +44,36 @@ export default defineEventHandler(async (e) => {
|
||||
}
|
||||
|
||||
tx.insert(projectFilesTable).values({
|
||||
id: item.id,
|
||||
path: item.path,
|
||||
id: submitted.id,
|
||||
path: submitted.path,
|
||||
owner: user.id,
|
||||
title: item.title,
|
||||
type: item.type,
|
||||
navigable: item.navigable,
|
||||
private: item.private,
|
||||
order: item.order,
|
||||
title: submitted.title,
|
||||
type: submitted.type,
|
||||
navigable: submitted.navigable,
|
||||
private: submitted.private,
|
||||
order: submitted.order,
|
||||
}).onConflictDoUpdate({
|
||||
set: {
|
||||
id: item.id,
|
||||
path: item.path,
|
||||
title: item.title,
|
||||
type: item.type,
|
||||
navigable: item.navigable,
|
||||
private: item.private,
|
||||
order: item.order,
|
||||
id: submitted.id,
|
||||
path: submitted.path,
|
||||
title: submitted.title,
|
||||
type: submitted.type,
|
||||
navigable: submitted.navigable,
|
||||
private: submitted.private,
|
||||
order: submitted.order,
|
||||
timestamp: new Date(),
|
||||
},
|
||||
target: projectFilesTable.id,
|
||||
}).run();
|
||||
}
|
||||
|
||||
//Delete the remaining data has they have not been found in the new overview
|
||||
for(let i = 0; i < data.length; i++)
|
||||
{
|
||||
deletion.run({ id: data[i].id });
|
||||
deleteOverview.run({ id: data[i]!.id });
|
||||
deleteContent.run({ id: data[i]!.id });
|
||||
}
|
||||
});
|
||||
|
||||
return blocked;
|
||||
return requested;
|
||||
});
|
||||
Reference in New Issue
Block a user