Skip to content

Commit

Permalink
Merge pull request #57 from taronaeo/feat/file-upload-encryption
Browse files Browse the repository at this point in the history
Feat/file upload encryption
  • Loading branch information
deziiii authored Feb 11, 2024
2 parents 9bdc61e + 05994aa commit 751a867
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"firebase": "^10.7.0",
"mime-types": "^2.1.35",
"svelte-forms-lib": "^2.0.1",
"uuidv4": "^6.2.13",
"yup": "^1.3.2"
Expand All @@ -23,6 +24,7 @@
"@sveltejs/kit": "^1.27.4",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9",
"@types/mime-types": "^2.1.4",
"@types/node": "^20.10.6",
"@types/uuid": "^9.0.7",
"@types/yup": "^0.32.0",
Expand Down
8 changes: 6 additions & 2 deletions apps/backend/src/lib/components/FileUpload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import type { FSFile, FSFileClass } from '@armadillo/shared';
import * as yup from 'yup';
import * as mime from 'mime';
import { v4 } from 'uuid';
import { createForm } from 'svelte-forms-lib';
Expand Down Expand Up @@ -71,7 +73,7 @@
file_domain: $authStore?.email?.split('@').pop()!, // TODO: Please change later
file_classification: data.fileClass!,
file_name: formFile.name,
file_ext: formFile.name.split('.').pop() || '',
file_ext: formFileExt,
file_owner_id: $authStore!.uid,
file_encryption_hash: filePwdHash,
file_encryption_iv: '',
Expand All @@ -84,7 +86,9 @@
const storageRef = ref(fileStorage, `${$authStore.uid}/${formFileName}.${formFileExt}`);
const setDocPromise = setDoc(docRef, fileData);
const uploadDocPromise = uploadBytes(storageRef, formFileBuffer);
const uploadDocPromise = uploadBytes(storageRef, formFileBuffer, {
contentType: mime.getType(formFileExt) || 'application/octet-stream',
});
await Promise.all([setDocPromise, uploadDocPromise]).catch(console.error);
toggleModal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const https_onCall_file_getClassification = onCall<CFCallableGetClassific
.collection(FS_COLLECTION_AUDITS)
.doc(`FILE_CLASSIFICATION-${clientId}`);


const auditDoc: FSAudit = {
origin,
client_id: clientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import { onObjectFinalized } from 'firebase-functions/v2/storage';

import { bucketFiles, firestore } from '../../../firebase';

/**
* Handles the encryption of a file when it is uploaded to the storage.
*
* @param data The data object containing information about the uploaded file.
* @param data.name The name of the uploaded file.
* @param data.size The size of the uploaded file in bytes.
* @param data.contentType The content type of the uploaded file.
* @returns A promise that resolves when the encryption process is complete.
*/
export const storage_onObjectFinalized_file_onFileUploadEncrypt = onObjectFinalized(
{
bucket: BUCKET_FILES,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3773,6 +3773,11 @@
resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.5.tgz#3e0d2db570e9fb6ccb2dc8fde0be1d79ac810d39"
integrity sha512-6L6VymKTzYSrEf4Nev4Xa1LCHKrlTlYCBMTlQKFuddo1CvQcE52I0mwfOJayueUC7MJuXOeHTcIU683lzd0cUA==

"@types/mime-types@^2.1.4":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@types/mime-types/-/mime-types-2.1.4.tgz#93a1933e24fed4fb9e4adc5963a63efcbb3317a2"
integrity sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==

"@types/mime@*":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.4.tgz#2198ac274de6017b44d941e00261d5bc6a0e0a45"
Expand Down

0 comments on commit 751a867

Please sign in to comment.