a lot of work, but i'd guess mostly api in the works

This commit is contained in:
2026-05-27 20:45:14 +02:00
parent 68458be71f
commit 50872d8951
22 changed files with 1425 additions and 1257 deletions
+58
View File
@@ -0,0 +1,58 @@
import { db } from '$lib/server/db';
import { filesystem } from '$lib/server/db/schema';
import { MD5 } from '$lib/termos/util/hash';
import { eq } from 'drizzle-orm';
export async function GET({ request }): Promise<Response> {
const row = await db
.select({
data: filesystem.data,
checksum: filesystem.checksum
})
.from(filesystem)
.where(eq(filesystem.id, 1))
.limit(1);
if (!row.length) {
return new Response('Filesystem is not initialized on the database', { status: 500 });
}
const { data, checksum } = row[0];
const clientETag = request.headers.get('if-none-match');
if (clientETag === `"${checksum}"`) {
return new Response(null, {
status: 304,
headers: { ETag: `"${checksum}"` }
});
}
return new Response(data, {
status: 200,
headers: {
'Content-Type': 'application/json',
ETag: `"${checksum}"`,
'Cache-Control': 'no-cache'
}
});
}
export async function POST({ request }) {
const newData = await request.text();
try {
const parsed = JSON.parse(newData);
//TODO: Schema validation
} catch {
//TODO: Change that to a proper http headers error
return new Response(null, {
status: 400
});
}
const checksum: string = MD5.hash(newData);
await db.update(filesystem).set({ data: newData, checksum }).where(eq(filesystem.id, 1));
return new Response(JSON.stringify({ success: true }), { status: 200 });
}