Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3400119
D9941.id33457.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9941.id33457.diff
View Options
diff --git a/keyserver/src/services/blob.js b/keyserver/src/services/blob.js
--- a/keyserver/src/services/blob.js
+++ b/keyserver/src/services/blob.js
@@ -4,12 +4,27 @@
import { makeBlobServiceEndpointURL } from 'lib/utils/blob-service.js';
import { getMessageForException } from 'lib/utils/errors.js';
-async function upload(blob: Blob, hash: string, holder: string): Promise<void> {
+async function uploadBlob(blob: Blob, hash: string): Promise<void> {
const formData = new FormData();
formData.append('blob_hash', hash);
formData.append('blob_data', blob);
- const assignHolderPromise = fetch(
+ const uploadBlobResponse = await fetch(
+ makeBlobServiceEndpointURL(blobService.httpEndpoints.UPLOAD_BLOB),
+ {
+ method: blobService.httpEndpoints.UPLOAD_BLOB.method,
+ body: formData,
+ },
+ );
+
+ if (!uploadBlobResponse.ok) {
+ const { status, statusText } = uploadBlobResponse;
+ throw new Error(`Payload upload failed with HTTP ${status}: ${statusText}`);
+ }
+}
+
+async function assignHolder(holder: string, hash: string): Promise<void> {
+ const assignHolderResponse = await fetch(
makeBlobServiceEndpointURL(blobService.httpEndpoints.ASSIGN_HOLDER),
{
method: blobService.httpEndpoints.ASSIGN_HOLDER.method,
@@ -23,20 +38,17 @@
},
);
- const uploadHolderPromise = fetch(
- makeBlobServiceEndpointURL(blobService.httpEndpoints.UPLOAD_BLOB),
- {
- method: blobService.httpEndpoints.UPLOAD_BLOB.method,
- body: formData,
- },
- );
+ if (!assignHolderResponse.ok) {
+ const { status, statusText } = assignHolderResponse;
+ throw new Error(
+ `Holder assignment failed with HTTP ${status}: ${statusText}`,
+ );
+ }
+}
- let assignHolderResponse, uploadBlobResponse;
+async function upload(blob: Blob, hash: string, holder: string): Promise<void> {
try {
- [assignHolderResponse, uploadBlobResponse] = await Promise.all([
- assignHolderPromise,
- uploadHolderPromise,
- ]);
+ await Promise.all([assignHolder(holder, hash), uploadBlob(blob, hash)]);
} catch (e) {
throw new Error(
`Payload upload failed with: ${
@@ -44,18 +56,6 @@
}`,
);
}
-
- if (!assignHolderResponse.ok) {
- const { status, statusText } = assignHolderResponse;
- throw new Error(
- `Holder assignment failed with HTTP ${status}: ${statusText}`,
- );
- }
-
- if (!uploadBlobResponse.ok) {
- const { status, statusText } = uploadBlobResponse;
- throw new Error(`Payload upload failed with HTTP ${status}: ${statusText}`);
- }
}
-export { upload };
+export { upload, uploadBlob, assignHolder };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 6:15 AM (1 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2610546
Default Alt Text
D9941.id33457.diff (2 KB)
Attached To
Mode
D9941: [keyserver] Split uploading blob and assigning holders
Attached
Detach File
Event Timeline
Log In to Comment