Migrate from Node.js built-ins to Bun-native APIs (#1)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
2026-03-04 12:49:38 -05:00
committed by GitHub
co-authored by Claude
parent 36afbcb8c0
commit 83456c6a21
15 changed files with 99 additions and 106 deletions
+4 -6
View File
@@ -1,5 +1,3 @@
import { statSync } from "node:fs";
import { readFile } from "node:fs/promises";
import path from "node:path";
import { headers } from "next/headers";
import { type NextRequest, NextResponse } from "next/server";
@@ -26,20 +24,20 @@ export async function GET(
return NextResponse.json({ error: "Invalid filename" }, { status: 400 });
}
const backupPath = getBackupPath(safe);
const backupPath = await getBackupPath(safe);
if (!backupPath) {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}
const buffer = await readFile(backupPath);
const stat = statSync(backupPath);
const file = Bun.file(backupPath);
const buffer = await file.arrayBuffer();
return new NextResponse(new Uint8Array(buffer), {
status: 200,
headers: {
"Content-Type": "application/x-sqlite3",
"Content-Disposition": `attachment; filename="${safe}"`,
"Content-Length": String(stat.size),
"Content-Length": String(file.size),
},
});
}
+1 -1
View File
@@ -27,7 +27,7 @@ export async function POST(req: Request) {
const buffer = Buffer.from(await file.arrayBuffer());
try {
restoreFromBackup(buffer);
await restoreFromBackup(buffer);
return NextResponse.json({ success: true });
} catch (err) {
const message = err instanceof Error ? err.message : "Restore failed";