Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3754356
D9170.id32483.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
D9170.id32483.diff
View Options
diff --git a/web/avatars/avatar-hooks.react.js b/web/avatars/avatar-hooks.react.js
--- a/web/avatars/avatar-hooks.react.js
+++ b/web/avatars/avatar-hooks.react.js
@@ -2,16 +2,25 @@
import * as React from 'react';
-import { uploadMultimedia } from 'lib/actions/upload-actions.js';
-import type { UploadMultimediaResult } from 'lib/types/media-types.js';
+import {
+ uploadMultimedia,
+ blobServiceUpload,
+} from 'lib/actions/upload-actions.js';
+import type { UpdateUserAvatarRequest } from 'lib/types/avatar-types.js';
import { useServerCall } from 'lib/utils/action-utils.js';
+import { encryptFile } from '../media/encryption-utils.js';
+import { generateThumbHash } from '../media/image-utils.js';
import { validateFile } from '../media/media-utils.js';
-function useUploadAvatarMedia(): File => Promise<UploadMultimediaResult> {
+// TODO: flip the switch
+const useBlobServiceUploads = true;
+
+function useUploadAvatarMedia(): File => Promise<UpdateUserAvatarRequest> {
const callUploadMultimedia = useServerCall(uploadMultimedia);
+ const callBlobServiceUpload = useServerCall(blobServiceUpload);
const uploadAvatarMedia = React.useCallback(
- async (file: File): Promise<UploadMultimediaResult> => {
+ async file => {
const validatedFile = await validateFile(file);
const { result } = validatedFile;
if (!result.success) {
@@ -22,9 +31,48 @@
...dimensions,
loop: false,
};
- return await callUploadMultimedia(fixedFile, uploadExtras);
+ if (!useBlobServiceUploads) {
+ const { id } = await callUploadMultimedia(fixedFile, uploadExtras);
+ return { type: 'image', uploadID: id };
+ }
+
+ const encryptionResponse = await encryptFile(fixedFile);
+ const { result: encryptionResult } = encryptionResponse;
+ if (!encryptionResult.success) {
+ throw new Error('Avatar media encryption failed.');
+ }
+ const {
+ file: encryptedFile,
+ sha256Hash: blobHash,
+ encryptionKey,
+ } = encryptionResult;
+
+ const { result: thumbHashResult } = await generateThumbHash(
+ fixedFile,
+ encryptionKey,
+ );
+ const thumbHash = thumbHashResult.success
+ ? thumbHashResult.thumbHash
+ : null;
+
+ const { id } = await callBlobServiceUpload({
+ input: {
+ blobInput: {
+ type: 'file',
+ file: encryptedFile,
+ },
+ blobHash,
+ encryptionKey,
+ dimensions,
+ loop: false,
+ thumbHash,
+ },
+ callbacks: {},
+ });
+
+ return { type: 'encrypted-image', uploadID: id };
},
- [callUploadMultimedia],
+ [callBlobServiceUpload, callUploadMultimedia],
);
return uploadAvatarMedia;
}
diff --git a/web/avatars/edit-thread-avatar-menu.react.js b/web/avatars/edit-thread-avatar-menu.react.js
--- a/web/avatars/edit-thread-avatar-menu.react.js
+++ b/web/avatars/edit-thread-avatar-menu.react.js
@@ -59,10 +59,7 @@
const onImageSelected = React.useCallback(
async event => {
const uploadResult = await uploadAvatarMedia(event.target.files[0]);
- baseSetThreadAvatar(threadInfo.id, {
- type: 'image',
- uploadID: uploadResult.id,
- });
+ baseSetThreadAvatar(threadInfo.id, uploadResult);
},
[baseSetThreadAvatar, threadInfo.id, uploadAvatarMedia],
);
diff --git a/web/avatars/edit-user-avatar-menu.react.js b/web/avatars/edit-user-avatar-menu.react.js
--- a/web/avatars/edit-user-avatar-menu.react.js
+++ b/web/avatars/edit-user-avatar-menu.react.js
@@ -71,7 +71,7 @@
const onImageSelected = React.useCallback(
async event => {
const uploadResult = await uploadAvatarMedia(event.target.files[0]);
- baseSetUserAvatar({ type: 'image', uploadID: uploadResult.id });
+ baseSetUserAvatar(uploadResult);
},
[baseSetUserAvatar, uploadAvatarMedia],
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 11, 3:00 AM (20 h, 28 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2859046
Default Alt Text
D9170.id32483.diff (3 KB)
Attached To
Mode
D9170: [web] Support avatar uploads to blob service
Attached
Detach File
Event Timeline
Log In to Comment