Add partial report information to d1
This commit is contained in:
parent
7774a04c86
commit
d659a8122f
@ -9,9 +9,14 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
status: 400,
|
status: 400,
|
||||||
});
|
});
|
||||||
|
|
||||||
const userId = await context.env.DATA.get(`reportprocessing_${id}`);
|
const user = await context.env.DATA.get(`reportprocessing_${id}`);
|
||||||
|
|
||||||
if (!userId || userId !== context.data.current_user.id)
|
if (
|
||||||
|
!user ||
|
||||||
|
(context.data.current_user
|
||||||
|
? user !== context.data.current_user.id
|
||||||
|
: user !== context.request.headers.get("CF-Connecting-IP"))
|
||||||
|
)
|
||||||
return new Response('{"error":"No report with that ID is processing"}', {
|
return new Response('{"error":"No report with that ID is processing"}', {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
@ -148,7 +148,7 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
|
|
||||||
await context.env.DATA.put(
|
await context.env.DATA.put(
|
||||||
`reportprocessing_${reportId}`,
|
`reportprocessing_${reportId}`,
|
||||||
context.data.current_user.id,
|
currentUser?.id || context.request.headers.get("CF-Connecting-IP"),
|
||||||
{ expirationTtl: 3600 }
|
{ expirationTtl: 3600 }
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -164,17 +164,27 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
["mkv", "mov", "wmv"].includes(fileExt.toLowerCase()) ? "mp4" : fileExt
|
["mkv", "mov", "wmv"].includes(fileExt.toLowerCase()) ? "mp4" : fileExt
|
||||||
}`,
|
}`,
|
||||||
id: reportId,
|
id: reportId,
|
||||||
user: {
|
user: currentUser
|
||||||
discriminator: currentUser.discriminator,
|
? {
|
||||||
email: currentUser.email,
|
discriminator: currentUser.discriminator,
|
||||||
id: currentUser.id,
|
email: currentUser.email,
|
||||||
username: currentUser.username,
|
id: currentUser.id,
|
||||||
},
|
username: currentUser.username,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
target_ids: metaIDs,
|
target_ids: metaIDs,
|
||||||
target_usernames: metaNames,
|
target_usernames: metaNames,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await context.env.D1.prepare(
|
||||||
|
"INSERT INTO reports (created_at, id, open, user) VALUES (?, ?, ?, ?);"
|
||||||
|
)
|
||||||
|
.bind(Date.now(), reportId, 1, currentUser?.id || null)
|
||||||
|
.run();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
return new Response(JSON.stringify({ id: reportId, upload_url: uploadUrl }), {
|
return new Response(JSON.stringify({ id: reportId, upload_url: uploadUrl }), {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user