Changeset View
Changeset View
Standalone View
Standalone View
native/media/encryption-utils.js
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | const { steps: encryptionSteps, result: encryptionResult } = | ||||
await encryptFile(uploadURI); | await encryptFile(uploadURI); | ||||
steps.push(...encryptionSteps); | steps.push(...encryptionSteps); | ||||
if (!encryptionResult.success) { | if (!encryptionResult.success) { | ||||
return { steps, result: encryptionResult }; | return { steps, result: encryptionResult }; | ||||
} | } | ||||
if (preprocessedMedia.mediaType === 'photo') { | if (preprocessedMedia.mediaType === 'photo') { | ||||
const thumbHashResult = preprocessedMedia.thumbHash | |||||
? encryptBase64( | |||||
preprocessedMedia.thumbHash, | |||||
hexToUintArray(encryptionResult.encryptionKey), | |||||
) | |||||
: null; | |||||
return { | return { | ||||
steps, | steps, | ||||
result: { | result: { | ||||
...preprocessedMedia, | ...preprocessedMedia, | ||||
mediaType: 'encrypted_photo', | mediaType: 'encrypted_photo', | ||||
uploadURI: encryptionResult.uri, | uploadURI: encryptionResult.uri, | ||||
blobHash: encryptionResult.sha256Hash, | blobHash: encryptionResult.sha256Hash, | ||||
thumbHash: thumbHashResult?.base64, | |||||
encryptionKey: encryptionResult.encryptionKey, | encryptionKey: encryptionResult.encryptionKey, | ||||
shouldDisposePath: pathFromURI(encryptionResult.uri), | shouldDisposePath: pathFromURI(encryptionResult.uri), | ||||
}, | }, | ||||
}; | }; | ||||
} | } | ||||
// For videos, we also need to encrypt the thumbnail | // For videos, we also need to encrypt the thumbnail | ||||
const { steps: thumbnailEncryptionSteps, result: thumbnailEncryptionResult } = | const { steps: thumbnailEncryptionSteps, result: thumbnailEncryptionResult } = | ||||
await encryptFile(preprocessedMedia.uploadThumbnailURI); | await encryptFile(preprocessedMedia.uploadThumbnailURI); | ||||
steps.push(...thumbnailEncryptionSteps); | steps.push(...thumbnailEncryptionSteps); | ||||
if (!thumbnailEncryptionResult.success) { | if (!thumbnailEncryptionResult.success) { | ||||
return { steps, result: thumbnailEncryptionResult }; | return { steps, result: thumbnailEncryptionResult }; | ||||
} | } | ||||
const thumbHashResult = preprocessedMedia.thumbHash | |||||
? encryptBase64( | |||||
preprocessedMedia.thumbHash, | |||||
hexToUintArray(thumbnailEncryptionResult.encryptionKey), | |||||
) | |||||
: null; | |||||
return { | return { | ||||
steps, | steps, | ||||
result: { | result: { | ||||
...preprocessedMedia, | ...preprocessedMedia, | ||||
mediaType: 'encrypted_video', | mediaType: 'encrypted_video', | ||||
uploadURI: encryptionResult.uri, | uploadURI: encryptionResult.uri, | ||||
blobHash: encryptionResult.sha256Hash, | blobHash: encryptionResult.sha256Hash, | ||||
thumbHash: thumbHashResult?.base64, | |||||
encryptionKey: encryptionResult.encryptionKey, | encryptionKey: encryptionResult.encryptionKey, | ||||
uploadThumbnailURI: thumbnailEncryptionResult.uri, | uploadThumbnailURI: thumbnailEncryptionResult.uri, | ||||
thumbnailBlobHash: thumbnailEncryptionResult.sha256Hash, | thumbnailBlobHash: thumbnailEncryptionResult.sha256Hash, | ||||
thumbnailEncryptionKey: thumbnailEncryptionResult.encryptionKey, | thumbnailEncryptionKey: thumbnailEncryptionResult.encryptionKey, | ||||
shouldDisposePath: pathFromURI(encryptionResult.uri), | shouldDisposePath: pathFromURI(encryptionResult.uri), | ||||
}, | }, | ||||
}; | }; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |