implement export all

This commit is contained in:
Ean Milligan
2026-04-24 14:28:01 -04:00
parent 31e3e13ab9
commit f412f06e10
7 changed files with 85 additions and 24 deletions

21
mod.ts
View File

@@ -1,4 +1,5 @@
import { hash, compare } from '@bcrypt';
import { JSZip } from '@deno-zip';
import { customAlphabet } from '@nanoid';
import { STATUS_CODE, STATUS_TEXT, StatusCode } from '@std/http/status';
@@ -82,14 +83,28 @@ Deno.serve({ port: config.api.port }, async (req) => {
return genericResponse(STATUS_CODE.OK, JSON.stringify(plans));
} else if (path.startsWith('/export/')) {
const userId = path.replace('/export/', '');
const userMatch = await dbClient.query('SELECT id FROM users WHERE id = ?', [userId]).catch(() => {
const userMatch = await dbClient.query('SELECT id, name FROM users WHERE id = ?', [userId]).catch(() => {
failed = true;
});
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB.");
if (!userMatch.length) return genericResponse(STATUS_CODE.NotFound, 'User ID does not exist.');
// WIP: export plans to zip code goes here
return genericResponse(STATUS_CODE.NotImplemented, 'Export function WIP.');
const plans = await dbClient
.query('SELECT name, folder, data FROM plans WHERE ownerId = ? AND deleted = 0 ORDER BY folder ASC,name ASC', [userId])
.catch(() => {
failed = true;
});
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB.");
const zip = new JSZip();
for (const plan of plans) {
zip.addFile(`${plan.folder}${plan.folder ? '/' : ''}${plan.name}.xivplan`, plan.data);
}
return new Response(await zip.generateAsync({ type: 'blob' }), {
status: STATUS_CODE.OK,
statusText: STATUS_TEXT[STATUS_CODE.OK],
});
}
} else if (req.method === 'POST' && path === '/enroll') {
const body = await req.json();