Skip to content

Commit

Permalink
chore: address review
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 18, 2024
1 parent ea4fe9a commit 96b6d50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions upload-api/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions upload-api/stores/blobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 96b6d50

Please sign in to comment.