Skip to content

Commit

Permalink
fix(manager): screenshot upload concurrency limit
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Oct 25, 2023
1 parent 3552f44 commit e1a59b9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/manager/src/managers/screenshots/ScreenshotsManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as t from "io-ts";
import { fileTypeFromBuffer } from "file-type";
import pLimit from "p-limit";
import fetch, { FormData, Blob, Response } from "../../lib/fetch";

import { checkIsURLAccessible } from "../../lib/checkIsURLAccessible";
Expand Down Expand Up @@ -47,6 +48,8 @@ function assertBrowserContextInitialized(
}
}

const uploadScreenshotLimit = pLimit(10);

/**
* Encodes a part of a Slice Simulator URL to ensure it can be added to a URL
* safely.
Expand Down Expand Up @@ -283,10 +286,13 @@ export class ScreenshotsManager extends BaseManager {

formData.set("file", new Blob([args.data], { type: fileType?.mime }));

const res = await fetch(this._s3ACL.uploadEndpoint, {
method: "POST",
body: formData,
});
const s3ACLEndpoint = this._s3ACL.uploadEndpoint;
const res = await uploadScreenshotLimit(() =>
fetch(s3ACLEndpoint, {
method: "POST",
body: formData,
}),
);

if (res.ok) {
const url = new URL(key, this._s3ACL.imgixEndpoint);
Expand Down

0 comments on commit e1a59b9

Please sign in to comment.