feat(backup): add ZIP export endpoint (DB + images)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
18
src/routes/api/admin/backup/+server.ts
Normal file
18
src/routes/api/admin/backup/+server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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}"`
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user