End to end encrypted attachment upload and streaming
This commit is contained in:
parent
575e9e2010
commit
64ad8498f5
74 changed files with 2368 additions and 151 deletions
|
|
@ -4,6 +4,7 @@ import {
|
|||
updateMessageApi,
|
||||
removeMessageApi,
|
||||
} from "../../api/message";
|
||||
import { deleteAttachment } from "../../store/file";
|
||||
import { deleteMessage, setMessage } from "../../store/message";
|
||||
import { state } from "../../store/state";
|
||||
import {
|
||||
|
|
@ -13,6 +14,7 @@ import {
|
|||
generateIv,
|
||||
hexToBytes,
|
||||
} from "../crypto";
|
||||
import { fetchMedia } from "../file";
|
||||
|
||||
const fetchMessage = async (id: string, communityId: string) => {
|
||||
const data = await fetchMessageApi({
|
||||
|
|
@ -34,12 +36,18 @@ const fetchMessage = async (id: string, communityId: string) => {
|
|||
text: decrypted,
|
||||
});
|
||||
} catch {}
|
||||
|
||||
data.attachments.forEach((attachmentId) => {
|
||||
fetchMedia(communityId, attachmentId);
|
||||
});
|
||||
};
|
||||
|
||||
const createMessage = async (
|
||||
communityId: string,
|
||||
channelId: string,
|
||||
text: string,
|
||||
attachments: string[],
|
||||
replyToId?: string,
|
||||
) => {
|
||||
const encrypted = await encryptMessage(communityId, text);
|
||||
if (!encrypted) {
|
||||
|
|
@ -48,9 +56,11 @@ const createMessage = async (
|
|||
const [encryptedMessage, iv] = encrypted;
|
||||
|
||||
const data = await createMessageApi({
|
||||
channelId: channelId,
|
||||
iv: iv,
|
||||
text: encryptedMessage,
|
||||
iv: iv,
|
||||
channelId: channelId,
|
||||
replyToId: replyToId,
|
||||
attachments: attachments,
|
||||
});
|
||||
|
||||
if (typeof data.error === "string") {
|
||||
|
|
@ -61,6 +71,10 @@ const createMessage = async (
|
|||
...data,
|
||||
text: text,
|
||||
});
|
||||
|
||||
attachments.forEach((attachmentId) => {
|
||||
deleteAttachment(attachmentId);
|
||||
});
|
||||
};
|
||||
|
||||
const updateMessage = async (id: string, text: string) => {
|
||||
|
|
@ -98,6 +112,11 @@ const encryptMessage = async (
|
|||
}
|
||||
|
||||
const iv = generateIv();
|
||||
|
||||
if (text.length === 0) {
|
||||
return ["", bytesToHex(iv.buffer)];
|
||||
}
|
||||
|
||||
const encrypted = await encryptData<string>({
|
||||
key: key,
|
||||
iv: iv,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue