Add DB dump support

This commit is contained in:
Your Name
2023-03-15 19:42:52 -04:00
parent bdda2bcb8d
commit 9e6397f038
2 changed files with 17 additions and 0 deletions

14
functions/dump/[dump].js Normal file
View File

@@ -0,0 +1,14 @@
export async function onRequest(context) {
console.log(context);
if (context.params.dump !== context.env.DUMP_KEY) {
return new Response();
}
const db = context.env.D1DB;
const dump = await db.dump();
return new Response(dump, {
status: 200,
headers: {
'Content-Type': 'application/octet-stream'
}
});
}

View File

@@ -1,6 +1,9 @@
name = "cryptopad"
compatibility_date = "2023-03-15"
[vars]
DUMP_KEY = "dump"
[[ d1_databases ]]
binding = "D1DB"
database_name = "cryptopad"