implement export all
This commit is contained in:
21
mod.ts
21
mod.ts
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user