diff --git a/functions/dump/[dump].js b/functions/dump/[dump].js new file mode 100644 index 0000000..dd63939 --- /dev/null +++ b/functions/dump/[dump].js @@ -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' + } + }); +} \ No newline at end of file diff --git a/wrangler.toml b/wrangler.toml index dac8c9b..02cf37b 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,6 +1,9 @@ name = "cryptopad" compatibility_date = "2023-03-15" +[vars] +DUMP_KEY = "dump" + [[ d1_databases ]] binding = "D1DB" database_name = "cryptopad"