KV to D1 migration (this is totally gonna break something)

This commit is contained in:
2024-05-12 01:25:46 -04:00
parent a2b3391bda
commit e00b7e8c55
24 changed files with 1835 additions and 669 deletions

View File

@ -195,33 +195,25 @@ export async function onRequestPost(context: RequestContext) {
attachments.push(new URL(urlResult.value).pathname.replace(/^\/?t?\//, ""));
}
await context.env.DATA.put(
`report_${reportId}`,
JSON.stringify({
attachments,
created_at: Date.now(),
fcm_token: typeof senderTokenId === "string" ? senderTokenId : undefined,
id: reportId,
open: true,
user: currentUser
? {
email: currentUser.email,
id: currentUser.id,
username: currentUser.username,
}
: null,
target_ids: metaIDs,
target_usernames: metaNames,
}),
);
try {
await context.env.D1.prepare(
"INSERT INTO reports (created_at, id, open, user) VALUES (?, ?, ?, ?);",
await context.env.D1.prepare(
"INSERT INTO reports (attachments, created_at, id, open, target_ids, target_usernames, user) VALUES (?, ?, ?, 1, ?, ?, ?);",
)
.bind(
JSON.stringify(attachments),
Date.now(),
reportId,
JSON.stringify(metaIDs),
JSON.stringify(metaNames),
currentUser ? JSON.stringify(currentUser) : null,
)
.bind(Date.now(), reportId, 1, currentUser?.id || null)
.run();
if (typeof senderTokenId === "string")
await context.env.D1.prepare(
"INSERT INTO push_notifications (created_at, event_id, event_type, token) VALUES (?, ?, ?, ?);",
)
.bind(Date.now(), reportId, "report", senderTokenId)
.run();
} catch {}
return jsonResponse(
JSON.stringify({ id: reportId, upload_urls: uploadUrls }),