delete notes & sync to firebase

This commit is contained in:
2023-05-25 22:29:40 +02:00
parent 2b7ba1faf7
commit e384495e73
10 changed files with 64 additions and 66 deletions

View File

@@ -1,6 +1,6 @@
import { doc, getDoc } from 'firebase/firestore'
import { user, db } from '@/composables/useFirebase'
import { decrypt, calculateClientKey } from '@/utils/crypto'
import { decrypt, encrypt, calculateClientKey } from '@/utils/crypto'
function getClientKeysFromLocalStorage(): { [uid: string]: string } {
try {
@@ -76,3 +76,18 @@ export const decryptNotes = (notes: BaseNotes, encryptionKey: EncryptionKey) =>
)
return decryptedNotes
}
const encryptNote = (note: BaseNote, key: EncryptionKey) => {
return {
...note,
title: encrypt(note.title, key),
content: encrypt(note.content, key)
}
}
export const encryptNotes = (notes: BaseNotes, encryptionKey: EncryptionKey) => {
const encryptedNotes = Object.fromEntries(
Object.entries(notes).map(([noteId, note]) => [noteId, { ...encryptNote(note, encryptionKey) }])
)
return encryptedNotes
}