23 lines
717 B
JavaScript
23 lines
717 B
JavaScript
export async function onRequest(context) {
|
|
if (context.params.dump !== context.env.DUMP_KEY) {
|
|
return new Response("Wrong key");
|
|
}
|
|
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'
|
|
}
|
|
});
|
|
} |