Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3520821
D13656.id45006.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13656.id45006.diff
View Options
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 AssignMultipleHoldersRequest,
+ type RemoveMultipleHoldersRequest,
+ assignMultipleHoldersResponseValidator,
+ removeMultipleHoldersResponseValidator,
+} 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: AssignMultipleHoldersRequest = {
+ 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,
+ assignMultipleHoldersResponseValidator,
+ );
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: RemoveMultipleHoldersRequest = {
+ 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,
+ removeMultipleHoldersResponseValidator,
+ );
+
if (failedRequests.length !== 0) {
return { result: 'failed_requests', failedRequests };
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 1:31 AM (20 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2697746
Default Alt Text
D13656.id45006.diff (3 KB)
Attached To
Mode
D13656: [lib] Use response validators in multiple-holder calls
Attached
Detach File
Event Timeline
Log In to Comment