Page MenuHomePhabricator

D13656.diff
No OneTemporary

D13656.diff

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
@@ -5,9 +5,16 @@
import { toBase64URL } from './base64.js';
import { replacePathParams, type URLPathParams } from './url-utils.js';
+import { assertWithValidator } from './validation-utils.js';
import type { BlobServiceHTTPEndpoint } from '../facts/blob-service.js';
import blobServiceConfig from '../facts/blob-service.js';
-import type { BlobHashAndHolder } from '../types/holder-types.js';
+import {
+ type BlobInfo,
+ type AssignHoldersRequest,
+ type RemoveHoldersRequest,
+ assignHoldersResponseValidator,
+ removeHoldersResponseValidator,
+} from '../types/blob-service-types.js';
const BLOB_SERVICE_URI_PREFIX = 'comm-blob-service://';
@@ -113,19 +120,19 @@
}
async function assignMultipleHolders(
- holders: $ReadOnlyArray<{ +blobHash: string, +holder: string }>,
+ holders: $ReadOnlyArray<BlobInfo>,
headers: { [string]: string },
): Promise<
| { +result: 'success' }
| { +result: 'error', +status: number, +statusText: string }
| {
- +failedRequests: $ReadOnlyArray<{
- +blobHash: string,
- +holder: string,
- }>,
+ +failedRequests: $ReadOnlyArray<BlobInfo>,
+result: 'failed_requests',
},
> {
+ const requestBody: AssignHoldersRequest = {
+ requests: holders,
+ };
const assignMultipleHoldersResponse = await fetch(
makeBlobServiceEndpointURL(
blobServiceConfig.httpEndpoints.ASSIGN_MULTIPLE_HOLDERS,
@@ -133,9 +140,7 @@
{
method: blobServiceConfig.httpEndpoints.ASSIGN_MULTIPLE_HOLDERS.method,
headers: { ...headers, 'Content-Type': 'application/json' },
- body: JSON.stringify({
- requests: holders,
- }),
+ body: JSON.stringify(requestBody),
},
);
@@ -144,7 +149,11 @@
return { result: 'error', status, statusText };
}
- const { results } = await assignMultipleHoldersResponse.json();
+ const responseJson = await assignMultipleHoldersResponse.json();
+ const { results } = assertWithValidator(
+ responseJson,
+ assignHoldersResponseValidator,
+ );
const failedRequests = results
.filter(result => !result.success)
.map(({ blobHash, holder }) => ({ blobHash, holder }));
@@ -157,7 +166,7 @@
}
async function removeMultipleHolders(
- holders: $ReadOnlyArray<BlobHashAndHolder>,
+ holders: $ReadOnlyArray<BlobInfo>,
headers: { [string]: string },
instantDelete?: boolean,
): Promise<
@@ -165,9 +174,13 @@
| { +result: 'error', +status: number, +statusText: string }
| {
+result: 'failed_requests',
- +failedRequests: $ReadOnlyArray<BlobHashAndHolder>,
+ +failedRequests: $ReadOnlyArray<BlobInfo>,
},
> {
+ const requestBody: RemoveHoldersRequest = {
+ requests: holders,
+ instantDelete: !!instantDelete,
+ };
const response = await fetch(
makeBlobServiceEndpointURL(
blobServiceConfig.httpEndpoints.REMOVE_MULTIPLE_HOLDERS,
@@ -175,10 +188,7 @@
{
method: blobServiceConfig.httpEndpoints.REMOVE_MULTIPLE_HOLDERS.method,
headers: { ...headers, 'Content-Type': 'application/json' },
- body: JSON.stringify({
- requests: holders,
- instantDelete: !!instantDelete,
- }),
+ body: JSON.stringify(requestBody),
},
);
@@ -187,7 +197,12 @@
return { result: 'error', status, statusText };
}
- const { failedRequests } = await response.json();
+ const responseJson = await response.json();
+ const { failedRequests } = assertWithValidator(
+ responseJson,
+ removeHoldersResponseValidator,
+ );
+
if (failedRequests.length !== 0) {
return { result: 'failed_requests', failedRequests };
}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 8:32 PM (18 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2696378
Default Alt Text
D13656.diff (3 KB)

Event Timeline