diff --git a/keyserver/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js --- a/keyserver/src/fetchers/upload-fetchers.js +++ b/keyserver/src/fetchers/upload-fetchers.js @@ -114,9 +114,9 @@ return `${baseDomain}${uploadPath}`; } -function makeUploadURI(holder: ?string, id: string, secret: string): string { - if (holder) { - return makeBlobServiceURI(holder); +function makeUploadURI(blobHash: ?string, id: string, secret: string): string { + if (blobHash) { + return makeBlobServiceURI(blobHash); } return getUploadURL(id, secret); } diff --git a/lib/facts/blob-service.js b/lib/facts/blob-service.js --- a/lib/facts/blob-service.js +++ b/lib/facts/blob-service.js @@ -7,7 +7,7 @@ const httpEndpoints = Object.freeze({ GET_BLOB: { - path: '/blob/:holder', + path: '/blob/:blobHash', method: 'GET', }, ASSIGN_HOLDER: { diff --git a/lib/media/media-utils.js b/lib/media/media-utils.js --- a/lib/media/media-utils.js +++ b/lib/media/media-utils.js @@ -10,7 +10,7 @@ import { isBlobServiceURI, getBlobFetchableURL, - holderFromBlobServiceURI, + blobHashFromBlobServiceURI, } from '../utils/blob-service.js'; const maxDimensions = Object.freeze({ width: 1920, height: 1920 }); @@ -52,8 +52,8 @@ function fetchableMediaURI(uri: string): string { if (isBlobServiceURI(uri)) { - const holder = holderFromBlobServiceURI(uri); - return getBlobFetchableURL(holder); + const blobHash = blobHashFromBlobServiceURI(uri); + return getBlobFetchableURL(blobHash); } return uri; diff --git a/lib/utils/blob-service.js b/lib/utils/blob-service.js --- a/lib/utils/blob-service.js +++ b/lib/utils/blob-service.js @@ -7,24 +7,32 @@ const BLOB_SERVICE_URI_PREFIX = 'comm-blob-service://'; -function makeBlobServiceURI(holder: string): string { - return `${BLOB_SERVICE_URI_PREFIX}${holder}`; +function makeBlobServiceURI(blobHash: string): string { + return `${BLOB_SERVICE_URI_PREFIX}${blobHash}`; } function isBlobServiceURI(uri: string): boolean { return uri.startsWith(BLOB_SERVICE_URI_PREFIX); } -function holderFromBlobServiceURI(uri: string): string { +/** + * Returns the base64url-encoded blob hash from a blob service URI. + * Throws an error if the URI is not a blob service URI. + */ +function blobHashFromBlobServiceURI(uri: string): string { invariant(isBlobServiceURI(uri), 'Not a blob service URI'); return uri.slice(BLOB_SERVICE_URI_PREFIX.length); } -function holderFromURI(uri: string): ?string { +/** + * Returns the base64url-encoded blob hash from a blob service URI. + * Returns null if the URI is not a blob service URI. + */ +function blobHashFromURI(uri: string): ?string { if (!isBlobServiceURI(uri)) { return null; } - return holderFromBlobServiceURI(uri); + return blobHashFromBlobServiceURI(uri); } function makeBlobServiceEndpointURL( @@ -38,17 +46,17 @@ return `${blobServiceConfig.url}${path}`; } -function getBlobFetchableURL(holder: string): string { +function getBlobFetchableURL(blobHash: string): string { return makeBlobServiceEndpointURL(blobServiceConfig.httpEndpoints.GET_BLOB, { - holder, + blobHash, }); } export { makeBlobServiceURI, isBlobServiceURI, - holderFromURI, - holderFromBlobServiceURI, + blobHashFromURI, + blobHashFromBlobServiceURI, getBlobFetchableURL, makeBlobServiceEndpointURL, };