KV to D1 migration (this is totally gonna break something)
This commit is contained in:
@ -15,12 +15,15 @@ export async function onRequestPost(context: RequestContext) {
|
||||
)
|
||||
return jsonError("No processing report with that ID found", 404);
|
||||
|
||||
const data: { [k: string]: any } | null = await context.env.DATA.get(
|
||||
`report_${id}`,
|
||||
{ type: "json" },
|
||||
);
|
||||
const data: Record<string, any> | null = await context.env.D1.prepare(
|
||||
"SELECT attachments FROM reports WHERE id = ?;",
|
||||
)
|
||||
.bind(id)
|
||||
.first();
|
||||
|
||||
if (!data) return jsonError("Report doesn't exist", 404);
|
||||
if (!data) return jsonError("No report with that ID found", 404);
|
||||
|
||||
data.attachments = JSON.parse(data.attachments);
|
||||
|
||||
const accessToken = await GetAccessToken(context.env);
|
||||
const attachmentDeletePromises = [];
|
||||
@ -47,7 +50,6 @@ export async function onRequestPost(context: RequestContext) {
|
||||
);
|
||||
|
||||
await Promise.allSettled(attachmentDeletePromises);
|
||||
await context.env.DATA.delete(`report_${id}`);
|
||||
await context.env.D1.prepare("DELETE FROM reports WHERE id = ?;")
|
||||
.bind(id)
|
||||
.run();
|
||||
|
Reference in New Issue
Block a user