Skip to content

Commit

Permalink
Store file drop as array instead of object
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Aug 31, 2023
1 parent 6c118a5 commit b714fde
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions js/end_to_end_encryption-filedrop.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/end_to_end_encryption-filedrop.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/Controller/MetaDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function addMetadataFileDrop(int $id, string $fileDrop, ?string $shareTok
try {
$metaData = $this->metaDataStorage->getMetaData($ownerId, $id);
$decodedMetadata = json_decode($metaData, true);
$decodedFileDrop = json_decode($fileDrop, true);
$decodedFileDrop = json_decode($fileDrop);
$decodedMetadata['filedrop'] = array_merge($decodedMetadata['filedrop'] ?? [], $decodedFileDrop);
$encodedMetadata = json_encode($decodedMetadata);

Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/V1/MetaDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ public function addMetadataFileDrop(int $id, string $fileDrop, ?string $shareTok

try {
$metaData = $this->metaDataStorage->getMetaData($ownerId, $id);
$decodedMetadata = json_decode($metaData, true);
$decodedFileDrop = json_decode($fileDrop, true);
$decodedMetadata = json_decode($metaData);
$decodedFileDrop = json_decode($fileDrop);
$decodedMetadata['filedrop'] = array_merge($decodedMetadata['filedrop'] ?? [], $decodedFileDrop);
$encodedMetadata = json_encode($decodedMetadata);

Expand Down
19 changes: 10 additions & 9 deletions src/services/filedrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { EncryptedFile, encryptStringAsymmetric, encryptWithAES, getRandomAESKey
* @property {string} encryptedTag - Encryption tag used to decrypt the 'encrypted' property.
*/

/**
*
*/
async function getRandomEncryptionParams() {
return {
key: await getRandomAESKey(),
Expand All @@ -39,7 +42,7 @@ function bufferToBase64(buffer) {
* @param {EncryptedFile} file
* @param {Uint8Array} tag
* @param {string} publicKey
* @return {Promise<Object<string, EncryptedFileMetadata>>}
* @return {Promise<EncryptedFileMetadata>}
*/
export async function getFileDropEntry(file, tag, publicKey) {
const rawFileEncryptionKey = await window.crypto.subtle.exportKey('raw', await file.getEncryptionKey())
Expand Down Expand Up @@ -70,14 +73,12 @@ export async function getFileDropEntry(file, tag, publicKey) {
)

return {
[file.encryptedFileName]: {
encrypted: bufferToBase64(encrypted.content),
initializationVector: bufferToBase64(file.initializationVector),
authenticationTag: bufferToBase64(tag),
encryptedKey: bufferToBase64(encryptedKey),
encryptedTag: bufferToBase64(encrypted.tag),
encryptedInitializationVector: bufferToBase64(encryptedEncryptionParams.initializationVector),
},
encrypted: bufferToBase64(encrypted.content),
initializationVector: bufferToBase64(file.initializationVector),
authenticationTag: bufferToBase64(tag),
encryptedKey: bufferToBase64(encryptedKey),
encryptedTag: bufferToBase64(encrypted.tag),
encryptedInitializationVector: bufferToBase64(encryptedEncryptionParams.initializationVector),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/FileDrop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default {
const fileDrops = progresses
.filter(({ error }) => !error)
.reduce((fileDropEntries, { fileDrop }) => ({ ...fileDropEntries, ...fileDrop }), {})
.map(({ fileDrop }) => fileDrop)
await uploadFileDrop(this.encryptionVersion, this.folderId, fileDrops, lockToken, this.shareToken)
} catch (exception) {
Expand Down

0 comments on commit b714fde

Please sign in to comment.