Switch to CF KV instead of D1, more appropriate for the purpose

This commit is contained in:
Your Name
2024-07-24 01:47:20 -04:00
parent 491a1a3a4f
commit 808e848561
4 changed files with 23 additions and 10 deletions

View File

@@ -1,11 +1,20 @@
export async function onRequest(context) {
console.log(context);
if (context.params.dump !== context.env.DUMP_KEY) {
return new Response("Wrong key");
}
const db = context.env.D1DB;
const dump = await db.dump();
return new Response(dump, {
const db = context.env.cryptopad;
console.log(db)
let accum = []
let cursor = undefined;
do {
const listResult = await db.list({cursor});
cursor = listResult.cursor;
accum = accum.concat(listResult.keys.map(x => x.name));
} while (cursor !== undefined);
const results = await Promise.all(accum.map(async x => ({key: x, value: await db.get(x)})));
return new Response(JSON.stringify(results), {
status: 200,
headers: {
'Content-Type': 'application/octet-stream'