Skip to content

Commit

Permalink
fix(trace): fix trace upload
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Nov 9, 2023
1 parent 5b4d571 commit 2cedf15
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions apps/backend/src/web/api/v2/builds/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ScreenshotFileUpload[]> => {
const pwTraceKeys = pwTraces.map((pwTrace) => pwTrace.traceKey);
const allKeys = [...keys, ...pwTraceKeys];
const unknownKeys = await getUnknownFileKeys(allKeys);
Expand All @@ -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 }) => {
Expand Down

0 comments on commit 2cedf15

Please sign in to comment.