Cleanup
This commit is contained in:
parent
b8db541231
commit
fb4ba5f4b4
|
@ -76,8 +76,4 @@ export interface IShareAttachment {
|
|||
canUpload: boolean;
|
||||
error?: any;
|
||||
uri: string;
|
||||
encryption?: {
|
||||
key: any;
|
||||
iv: string;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -32,10 +32,6 @@ export interface IUploadFile {
|
|||
tmid?: string;
|
||||
description?: string;
|
||||
size: number;
|
||||
type: string;
|
||||
// store?: string;
|
||||
// progress?: number;
|
||||
type?: string;
|
||||
msg?: string;
|
||||
// t?: MessageType;
|
||||
// e2e?: E2EType;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import parse from 'url-parse';
|
|||
import { sha256 } from 'js-sha256';
|
||||
|
||||
import getSingleMessage from '../methods/getSingleMessage';
|
||||
import { IAttachment, IMessage, IShareAttachment, IUpload, IUploadFile, IUser } from '../../definitions';
|
||||
import { IAttachment, IMessage, IUpload, IUploadFile, IUser } from '../../definitions';
|
||||
import Deferred from './helpers/deferred';
|
||||
import { debounce } from '../methods/helpers';
|
||||
import database from '../database';
|
||||
|
@ -32,7 +32,7 @@ import { mapMessageFromAPI } from './helpers/mapMessageFromApi';
|
|||
import { mapMessageFromDB } from './helpers/mapMessageFromDB';
|
||||
import { createQuoteAttachment } from './helpers/createQuoteAttachment';
|
||||
import { getMessageById } from '../database/services/Message';
|
||||
import { TEncryptFile, TEncryptFileResult, TGetContent } from './definitions';
|
||||
import { TEncryptFileResult, TGetContent } from './definitions';
|
||||
|
||||
export default class EncryptionRoom {
|
||||
ready: boolean;
|
||||
|
@ -293,21 +293,21 @@ export default class EncryptionRoom {
|
|||
iv: bufferToB64(vector)
|
||||
}
|
||||
};
|
||||
if (/^image\/.+/.test(file.type)) {
|
||||
if (file.type && /^image\/.+/.test(file.type)) {
|
||||
att = {
|
||||
...att,
|
||||
image_url: fileUrl,
|
||||
image_type: file.type,
|
||||
image_size: file.size
|
||||
};
|
||||
} else if (/^audio\/.+/.test(file.type)) {
|
||||
} else if (file.type && /^audio\/.+/.test(file.type)) {
|
||||
att = {
|
||||
...att,
|
||||
audio_url: fileUrl,
|
||||
audio_type: file.type,
|
||||
audio_size: file.size
|
||||
};
|
||||
} else if (/^video\/.+/.test(file.type)) {
|
||||
} else if (file.type && /^video\/.+/.test(file.type)) {
|
||||
att = {
|
||||
...att,
|
||||
video_url: fileUrl,
|
||||
|
@ -392,16 +392,10 @@ export default class EncryptionRoom {
|
|||
tmsg = await this.decryptText(tmsg);
|
||||
}
|
||||
|
||||
// if (message.attachments?.length) {
|
||||
// message.attachments[0].description = await this.decryptText(message.attachments[0].description as string);
|
||||
// }
|
||||
|
||||
if (message.content?.ciphertext) {
|
||||
try {
|
||||
const content = await this.decryptContent(message.content?.ciphertext as string);
|
||||
console.log('🚀 ~ EncryptionRoom ~ decrypt= ~ content:', content);
|
||||
message.attachments = content.attachments;
|
||||
console.log('🚀 ~ EncryptionRoom ~ decrypt= ~ message.attachments:', message.attachments);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
|
|
@ -6,12 +6,6 @@ import { fromByteArray, toByteArray } from './helpers/base64-js';
|
|||
|
||||
const BASE64URI = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
||||
|
||||
// Use a lookup table to find the index.
|
||||
const lookup = new Uint8Array(256);
|
||||
for (let i = 0; i < BASE64URI.length; i++) {
|
||||
lookup[BASE64URI.charCodeAt(i)] = i;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
export const b64ToBuffer = (base64: string): ArrayBuffer => toByteArray(base64).buffer;
|
||||
export const utf8ToBuffer = SimpleCrypto.utils.convertUtf8ToArrayBuffer;
|
||||
|
@ -38,32 +32,6 @@ export const bufferToB64URI = (buffer: ArrayBuffer): string => {
|
|||
|
||||
return base64;
|
||||
};
|
||||
export const b64URIToBuffer = (base64: string): ArrayBuffer => {
|
||||
const bufferLength = base64.length * 0.75;
|
||||
const len = base64.length;
|
||||
let i;
|
||||
let p = 0;
|
||||
let encoded1;
|
||||
let encoded2;
|
||||
let encoded3;
|
||||
let encoded4;
|
||||
|
||||
const arraybuffer = new ArrayBuffer(bufferLength);
|
||||
const bytes = new Uint8Array(arraybuffer);
|
||||
|
||||
for (i = 0; i < len; i += 4) {
|
||||
encoded1 = lookup[base64.charCodeAt(i)];
|
||||
encoded2 = lookup[base64.charCodeAt(i + 1)];
|
||||
encoded3 = lookup[base64.charCodeAt(i + 2)];
|
||||
encoded4 = lookup[base64.charCodeAt(i + 3)];
|
||||
|
||||
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
||||
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
||||
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
||||
}
|
||||
|
||||
return arraybuffer;
|
||||
};
|
||||
// SimpleCrypto.utils.convertArrayBufferToUtf8 is not working with unicode emoji
|
||||
export const bufferToUtf8 = (buffer: ArrayBuffer): string => {
|
||||
const uintArray = new Uint8Array(buffer) as number[] & Uint8Array;
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import * as FileSystem from 'expo-file-system';
|
||||
import * as mime from 'react-native-mime-types';
|
||||
import { isEmpty } from 'lodash';
|
||||
// import { Base64 } from 'js-base64';
|
||||
|
||||
import { sanitizeLikeString } from '../database/utils';
|
||||
import { store } from '../store/auxStore';
|
||||
import log from './helpers/log';
|
||||
import { Base64, b64ToBuffer, b64URIToBuffer, base64Decode, decryptAESCTR } from '../encryption/utils';
|
||||
import { decryptAESCTR } from '../encryption/utils';
|
||||
|
||||
export type MediaTypes = 'audio' | 'image' | 'video';
|
||||
|
||||
|
@ -224,7 +223,6 @@ export function downloadMediaFile({
|
|||
|
||||
if (encryption) {
|
||||
const decryptedFile = await decryptAESCTR(result.uri, encryption.key.k, encryption.iv);
|
||||
console.log('🚀 ~ returnnewPromise ~ decryptedFile:', decryptedFile);
|
||||
if (decryptedFile) {
|
||||
return resolve(decryptedFile);
|
||||
}
|
||||
|
|
|
@ -266,7 +266,6 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
|||
size,
|
||||
type,
|
||||
path,
|
||||
store: 'Uploads',
|
||||
msg
|
||||
},
|
||||
thread?.id,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue