From 858e2892c417ba9f2bf661c8d52ceb501a8cb7d5 Mon Sep 17 00:00:00 2001 From: doubleface Date: Fri, 4 Aug 2023 15:02:46 +0200 Subject: [PATCH] fix: Let cozy-clisk convert dataUri to arrayBuffer itself --- src/libs/Launcher.js | 16 +++++----------- src/libs/utils.js | 24 ------------------------ 2 files changed, 5 insertions(+), 35 deletions(-) delete mode 100644 src/libs/utils.js diff --git a/src/libs/Launcher.js b/src/libs/Launcher.js index 6d0e95d91..e4a2064ef 100644 --- a/src/libs/Launcher.js +++ b/src/libs/Launcher.js @@ -1,6 +1,7 @@ // @ts-check /* eslint-disable no-unused-vars */ import Minilog from 'cozy-minilog' + import { getBuildId, getVersion } from 'react-native-device-info' // @ts-ignore @@ -17,7 +18,6 @@ import { removeCredential, getSlugAccountIds } from './keychain' -import { dataURItoArrayBuffer } from './utils' import { constants } from '/screens/konnectors/constants/konnectors-constants' @@ -458,16 +458,10 @@ export default class Launcher { sourceAccount: job.message.account, sourceAccountIdentifier, // @ts-ignore - downloadAndFormatFile: async entry => { - // @ts-ignore - const dataUri = await this.worker.call('downloadFileInWorker', entry) - const test = dataURItoArrayBuffer(dataUri) - const filestream = test.arrayBuffer - return { - ...entry, - filestream - } - }, + downloadAndFormatFile: async entry => ({ + ...entry, + dataUri: await this.worker.call('downloadFileInWorker', entry) + }), existingFilesIndex }) log.debug(result, 'saveFiles result') diff --git a/src/libs/utils.js b/src/libs/utils.js deleted file mode 100644 index e4c4fecec..000000000 --- a/src/libs/utils.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @typedef ArrayBufferWithContentType - * @property {String} contentType - dataUri included content type - * @property {ArrayBuffer} arrayBuffer - resulting decoded data - */ - -/** - * Converts a data URI string to an Array Buffer with its content Type - * - * @param {String} dataURI - data URI string containing content type and base64 encoded data - * @returns {ArrayBufferWithContentType} - */ -export const dataURItoArrayBuffer = dataURI => { - const [contentType, base64String] = dataURI - .match(/^data:(.*);base64,(.*)$/) - .slice(1) - const byteString = global.atob(base64String) - const arrayBuffer = new ArrayBuffer(byteString.length) - const ia = new Uint8Array(arrayBuffer) - for (let i = 0; i < byteString.length; i++) { - ia[i] = byteString.charCodeAt(i) - } - return { contentType, arrayBuffer } -}