From 96b6d50fcfee6100b94f314840a99b8548e15683 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 18 Apr 2024 10:18:31 +0100 Subject: [PATCH] chore: address review --- upload-api/scheduler.js | 3 +++ upload-api/stores/blobs.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/upload-api/scheduler.js b/upload-api/scheduler.js index 9c103c84..a756a4af 100644 --- a/upload-api/scheduler.js +++ b/upload-api/scheduler.js @@ -31,6 +31,9 @@ export class TasksScheduler { */ async schedule(invocation) { const connection = this.getServiceConnection() + // This performs a HTTP Request to the Service URL. + // upload-api service URL stores received invocations and produced + // receipts on the server. const [res] = await connection.execute(invocation) if (res.out.error) { diff --git a/upload-api/stores/blobs.js b/upload-api/stores/blobs.js index a7c4b93b..52d4b22a 100644 --- a/upload-api/stores/blobs.js +++ b/upload-api/stores/blobs.js @@ -31,6 +31,8 @@ export function createBlobsStorage(region, bucketName, options) { } /** + * This is quite similar with buckets/car-store with few modifications given new key schema + * and multihash instead of Link. * * @param {S3Client} s3 * @param {string} bucketName @@ -64,18 +66,22 @@ export function useBlobsStorage(s3, bucketName) { * * @param {Uint8Array} multihash * @param {number} size + * @param {number} expiresIn */ - createUploadUrl: async (multihash, size) => { + createUploadUrl: async (multihash, size, expiresIn) => { const encodedMultihash = base58btc.encode(multihash) const multihashDigest = digestDecode(multihash) const checksum = base64pad.baseEncode(multihashDigest.digest) const cmd = new PutObjectCommand({ + // Some cloud bucket implementations like S3 have rate limits applied. + // Rate limits happen across shards that are based on the folders structure + // of the bucket. By relying on folder as a hash, the rate limit from bucket + // providers can be prevented. Key: `${encodedMultihash}/${encodedMultihash}.blob`, Bucket: bucketName, ChecksumSHA256: checksum, ContentLength: size, }) - const expiresIn = 60 * 60 * 24 // 1 day const url = new URL( await getSignedUrl(s3, cmd, { expiresIn,