- Create `BackupService` in `src/service/backup.ts` to encapsulate tar stream creation and restore logic (db connection, fs operations). - Refactor `src/api/backup.ts` and `src/api/restore.ts` to use `BackupService`. - Add unit tests for `BackupService` in `src/service/backup.test.ts`. - Add API tests for backup and restore endpoints in `src/api/backup.test.ts` and `src/api/restore.test.ts`. - Maintain existing functionality: uncompressed tar streaming, safe restore with rollback.
19 lines
452 B
TypeScript
19 lines
452 B
TypeScript
import { Hono } from 'hono'
|
|
import { backupService } from '../service/backup'
|
|
|
|
const app = new Hono()
|
|
|
|
app.get('/', async () => {
|
|
const stream = backupService.createBackupStream()
|
|
|
|
// @ts-ignore: Bun supports Readable in Response, but TS doesn't know fully
|
|
return new Response(stream, {
|
|
headers: {
|
|
'Content-Type': 'application/x-tar',
|
|
'Content-Disposition': 'attachment; filename="backup.tar"',
|
|
},
|
|
})
|
|
})
|
|
|
|
export default app
|