19 lines
684 B
TypeScript
19 lines
684 B
TypeScript
import type { RequestHandler } from './$types';
|
|
import { createBackupStream, backupFilename } from '$lib/server/backup/export';
|
|
import { Readable } from 'node:stream';
|
|
|
|
const DB_PATH = process.env.DATABASE_PATH ?? './data/kochwas.db';
|
|
const IMAGE_DIR = process.env.IMAGE_DIR ?? './data/images';
|
|
|
|
export const GET: RequestHandler = async () => {
|
|
const archive = createBackupStream({ dbPath: DB_PATH, imagesDir: IMAGE_DIR });
|
|
const filename = backupFilename();
|
|
return new Response(Readable.toWeb(archive) as ReadableStream, {
|
|
status: 200,
|
|
headers: {
|
|
'content-type': 'application/zip',
|
|
'content-disposition': `attachment; filename="${filename}"`
|
|
}
|
|
});
|
|
};
|