Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start work on moving transcoding jobs to coconut
  • Loading branch information
regalijan committed Mar 23, 2024
1 parent 523b348 commit c770e67
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions functions/api/reports/submit.ts
@@ -1,5 +1,5 @@
import { GenerateUploadURL } from "../../gcloud.js";
import { jsonError, jsonResponse } from "../../common.js";
import upload from "../upload.js";

export async function onRequestPost(context: RequestContext) {
const {
Expand Down Expand Up @@ -137,6 +137,7 @@ export async function onRequestPost(context: RequestContext) {
}

const uploadUrlPromises: Promise<string>[] = [];
const filesToProcess = [];

for (const file of files) {
const fileParts = file.name.split(".");
Expand All @@ -162,14 +163,12 @@ export async function onRequestPost(context: RequestContext) {
)}${Date.now()}`;

uploadUrlPromises.push(
GenerateUploadURL(
context.env,
`t/${fileUploadKey}`,
file.size,
fileExten,
origin,
),
upload(context.env, `t/${fileUploadKey}`, file.size, fileExten),
);

if (!["mp4", "m4v", "webm"].includes(fileExten)) {
filesToProcess.push(fileUploadKey);
}
}

const uploadUrlResults = await Promise.allSettled(uploadUrlPromises);
Expand All @@ -179,6 +178,17 @@ export async function onRequestPost(context: RequestContext) {
)}${crypto.randomUUID().replaceAll("-", "")}`;

const { current_user: currentUser } = context.data;
if (filesToProcess.length)
await context.env.DATA.put(
`coconutjob_${reportId}`,
JSON.stringify({
attachments: filesToProcess,
token: crypto.randomUUID(),
}),
{
expirationTtl: 1800,
},
);

await context.env.DATA.put(
`reportprocessing_${reportId}`,
Expand Down

0 comments on commit c770e67

Please sign in to comment.