diff --git a/apps/backend/src/web/api/v2/builds/create.ts b/apps/backend/src/web/api/v2/builds/create.ts index f6189833b..99afe0d3c 100644 --- a/apps/backend/src/web/api/v2/builds/create.ts +++ b/apps/backend/src/web/api/v2/builds/create.ts @@ -14,7 +14,6 @@ import { repoAuth } from "../../../middlewares/repoAuth.js"; import { validate } from "../../../middlewares/validate.js"; import { asyncHandler } from "../../../util.js"; import { createBuildFromRequest, getBuildName } from "../util.js"; -import { invariant } from "@/util/invariant.js"; const router = Router(); export default router; @@ -102,16 +101,16 @@ type CreateRequest = express.Request< RequestPayload > & { authProject: Project }; +type ScreenshotFileUpload = { + key: string; + putUrl: string | null; + putTraceUrl: string | null; +}; + const getScreenshots = async ( keys: string[], pwTraces: PayloadPwTrace[], -): Promise< - { - key: string; - putUrl: string; - putTraceUrl: string | null; - }[] -> => { +): Promise => { const pwTraceKeys = pwTraces.map((pwTrace) => pwTrace.traceKey); const allKeys = [...keys, ...pwTraceKeys]; const unknownKeys = await getUnknownFileKeys(allKeys); @@ -130,18 +129,19 @@ const getScreenshots = async ( const putUrlByKey = Object.fromEntries( unknownKeys.map((key, index) => [key, putUrls[index]]), ); - const screenshotUnknownKeys = unknownKeys.filter((key) => keys.includes(key)); - return screenshotUnknownKeys.map((key) => { - const putUrl = putUrlByKey[key]; - invariant(putUrl, `putUrl missing for key ${key}`); + return keys.reduce((screenshots, key) => { + const putUrl = putUrlByKey[key] ?? null; const trace = pwTraces.find((pwTrace) => pwTrace.screenshotKey === key); const putTraceUrl = trace ? putUrlByKey[trace.traceKey] ?? null : null; - return { - key, - putUrl, - putTraceUrl, - }; - }); + if (putUrl || putTraceUrl) { + screenshots.push({ + key, + putUrl, + putTraceUrl, + }); + } + return screenshots; + }, [] as ScreenshotFileUpload[]); }; const handleCreateSingle = async ({ req }: { req: CreateRequest }) => {