From 88aff92a40ed443aaf7dac1881febecfe7d851f1 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Wed, 20 Sep 2023 13:09:29 +0100 Subject: [PATCH 1/5] ref: moved local file download to TS --- .../{index.android.js => index.android.ts} | 27 ++++++--------- .../{index.ios.js => index.ios.ts} | 33 +++++++------------ src/libs/fileDownload/{index.js => index.ts} | 9 ++--- 3 files changed, 24 insertions(+), 45 deletions(-) rename src/libs/fileDownload/{index.android.js => index.android.ts} (83%) rename src/libs/fileDownload/{index.ios.js => index.ios.ts} (78%) rename src/libs/fileDownload/{index.js => index.ts} (85%) diff --git a/src/libs/fileDownload/index.android.js b/src/libs/fileDownload/index.android.ts similarity index 83% rename from src/libs/fileDownload/index.android.js rename to src/libs/fileDownload/index.android.ts index c19301cbde49..a57a4bed71fd 100644 --- a/src/libs/fileDownload/index.android.js +++ b/src/libs/fileDownload/index.android.ts @@ -1,15 +1,14 @@ import {PermissionsAndroid, Platform} from 'react-native'; -import RNFetchBlob from 'react-native-blob-util'; +import RNFetchBlob, {FetchBlobResponse} from 'react-native-blob-util'; import * as FileUtils from './FileUtils'; /** * Android permission check to store images - * @returns {Promise} */ function hasAndroidPermission() { // On Android API Level 33 and above, these permissions do nothing and always return 'never_ask_again' // More info here: https://stackoverflow.com/a/74296799 - if (Platform.Version >= 33) { + if (Number(Platform.Version) >= 33) { return Promise.resolve(true); } @@ -31,12 +30,9 @@ function hasAndroidPermission() { /** * Handling the download - * @param {String} url - * @param {String} fileName - * @returns {Promise} */ -function handleDownload(url, fileName) { - return new Promise((resolve) => { +function handleDownload(url: string, fileName: string) { + return new Promise((resolve) => { const dirs = RNFetchBlob.fs.dirs; // Android files will download to Download directory @@ -46,7 +42,7 @@ function handleDownload(url, fileName) { const isLocalFile = url.startsWith('file://'); let attachmentPath = isLocalFile ? url : undefined; - let fetchedAttachment = Promise.resolve(); + let fetchedAttachment: Promise = Promise.resolve(); if (!isLocalFile) { // Fetching the attachment @@ -68,7 +64,7 @@ function handleDownload(url, fileName) { return Promise.reject(); } - if (!isLocalFile) attachmentPath = attachment.path(); + if (!isLocalFile) attachmentPath = attachment?.path() ?? ''; return RNFetchBlob.MediaCollection.copyToMediaStore( { @@ -77,11 +73,11 @@ function handleDownload(url, fileName) { mimeType: null, }, 'Download', - attachmentPath, + String(attachmentPath), ); }) .then(() => { - RNFetchBlob.fs.unlink(attachmentPath); + RNFetchBlob.fs.unlink(String(attachmentPath)); FileUtils.showSuccessAlert(); }) .catch(() => { @@ -93,12 +89,9 @@ function handleDownload(url, fileName) { /** * Checks permission and downloads the file for Android - * @param {String} url - * @param {String} fileName - * @returns {Promise} */ -export default function fileDownload(url, fileName) { - return new Promise((resolve) => { +export default function fileDownload(url: string, fileName: string) { + return new Promise((resolve) => { hasAndroidPermission() .then((hasPermission) => { if (hasPermission) { diff --git a/src/libs/fileDownload/index.ios.js b/src/libs/fileDownload/index.ios.ts similarity index 78% rename from src/libs/fileDownload/index.ios.js rename to src/libs/fileDownload/index.ios.ts index 95d92f1e3103..b0540da95a33 100644 --- a/src/libs/fileDownload/index.ios.js +++ b/src/libs/fileDownload/index.ios.ts @@ -1,16 +1,12 @@ import RNFetchBlob from 'react-native-blob-util'; import {CameraRoll} from '@react-native-camera-roll/camera-roll'; -import lodashGet from 'lodash/get'; import * as FileUtils from './FileUtils'; import CONST from '../../CONST'; /** * Downloads the file to Documents section in iOS - * @param {String} fileUrl - * @param {String} fileName - * @returns {Promise} */ -function downloadFile(fileUrl, fileName) { +function downloadFile(fileUrl: string, fileName: string) { const dirs = RNFetchBlob.fs.dirs; // The iOS files will download to documents directory @@ -31,29 +27,25 @@ function downloadFile(fileUrl, fileName) { /** * Download the image to photo lib in iOS - * @param {String} fileUrl - * @param {String} fileName - * @returns {String} URI + * @returns URI */ -function downloadImage(fileUrl) { +function downloadImage(fileUrl: string) { return CameraRoll.save(fileUrl); } /** * Download the video to photo lib in iOS - * @param {String} fileUrl - * @param {String} fileName - * @returns {String} URI + * @returns URI */ -function downloadVideo(fileUrl, fileName) { +function downloadVideo(fileUrl: string, fileName: string): Promise { return new Promise((resolve, reject) => { - let documentPathUri = null; - let cameraRollUri = null; + let documentPathUri: string; + let cameraRollUri: string; // Because CameraRoll doesn't allow direct downloads of video with remote URIs, we first download as documents, then copy to photo lib and unlink the original file. downloadFile(fileUrl, fileName) .then((attachment) => { - documentPathUri = lodashGet(attachment, 'data'); + documentPathUri = attachment?.data; return CameraRoll.save(documentPathUri); }) .then((attachment) => { @@ -67,19 +59,16 @@ function downloadVideo(fileUrl, fileName) { /** * Download the file based on type(image, video, other file types)for iOS - * @param {String} fileUrl - * @param {String} fileName - * @returns {Promise} */ -export default function fileDownload(fileUrl, fileName) { - return new Promise((resolve) => { +export default function fileDownload(fileUrl: string, fileName: string) { + return new Promise((resolve) => { let fileDownloadPromise = null; const fileType = FileUtils.getFileType(fileUrl); const attachmentName = FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(fileUrl); switch (fileType) { case CONST.ATTACHMENT_FILE_TYPE.IMAGE: - fileDownloadPromise = downloadImage(fileUrl, attachmentName); + fileDownloadPromise = downloadImage(fileUrl); break; case CONST.ATTACHMENT_FILE_TYPE.VIDEO: fileDownloadPromise = downloadVideo(fileUrl, attachmentName); diff --git a/src/libs/fileDownload/index.js b/src/libs/fileDownload/index.ts similarity index 85% rename from src/libs/fileDownload/index.js rename to src/libs/fileDownload/index.ts index a775576eb365..81e78f6baa9a 100644 --- a/src/libs/fileDownload/index.js +++ b/src/libs/fileDownload/index.ts @@ -3,12 +3,9 @@ import * as Link from '../actions/Link'; /** * Downloading attachment in web, desktop - * @param {String} url - * @param {String} fileName - * @returns {Promise} */ -export default function fileDownload(url, fileName) { - return new Promise((resolve) => { +export default function fileDownload(url: string, fileName: string) { + return new Promise((resolve) => { fetch(url) .then((response) => response.blob()) .then((blob) => { @@ -34,7 +31,7 @@ export default function fileDownload(url, fileName) { // Clean up and remove the link URL.revokeObjectURL(link.href); - link.parentNode.removeChild(link); + link.parentNode?.removeChild(link); return resolve(); }) .catch(() => { From 61b1e6ef63a84c91c9e208f2d58ac856c7953680 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Wed, 20 Sep 2023 13:47:15 +0100 Subject: [PATCH 2/5] fix: undo wrongly migrated file download file to TS --- .../{index.android.ts => index.android.js} | 27 +++++++++------ .../{index.ios.ts => index.ios.js} | 33 ++++++++++++------- src/libs/fileDownload/{index.ts => index.js} | 9 +++-- 3 files changed, 45 insertions(+), 24 deletions(-) rename src/libs/fileDownload/{index.android.ts => index.android.js} (83%) rename src/libs/fileDownload/{index.ios.ts => index.ios.js} (78%) rename src/libs/fileDownload/{index.ts => index.js} (85%) diff --git a/src/libs/fileDownload/index.android.ts b/src/libs/fileDownload/index.android.js similarity index 83% rename from src/libs/fileDownload/index.android.ts rename to src/libs/fileDownload/index.android.js index a57a4bed71fd..c19301cbde49 100644 --- a/src/libs/fileDownload/index.android.ts +++ b/src/libs/fileDownload/index.android.js @@ -1,14 +1,15 @@ import {PermissionsAndroid, Platform} from 'react-native'; -import RNFetchBlob, {FetchBlobResponse} from 'react-native-blob-util'; +import RNFetchBlob from 'react-native-blob-util'; import * as FileUtils from './FileUtils'; /** * Android permission check to store images + * @returns {Promise} */ function hasAndroidPermission() { // On Android API Level 33 and above, these permissions do nothing and always return 'never_ask_again' // More info here: https://stackoverflow.com/a/74296799 - if (Number(Platform.Version) >= 33) { + if (Platform.Version >= 33) { return Promise.resolve(true); } @@ -30,9 +31,12 @@ function hasAndroidPermission() { /** * Handling the download + * @param {String} url + * @param {String} fileName + * @returns {Promise} */ -function handleDownload(url: string, fileName: string) { - return new Promise((resolve) => { +function handleDownload(url, fileName) { + return new Promise((resolve) => { const dirs = RNFetchBlob.fs.dirs; // Android files will download to Download directory @@ -42,7 +46,7 @@ function handleDownload(url: string, fileName: string) { const isLocalFile = url.startsWith('file://'); let attachmentPath = isLocalFile ? url : undefined; - let fetchedAttachment: Promise = Promise.resolve(); + let fetchedAttachment = Promise.resolve(); if (!isLocalFile) { // Fetching the attachment @@ -64,7 +68,7 @@ function handleDownload(url: string, fileName: string) { return Promise.reject(); } - if (!isLocalFile) attachmentPath = attachment?.path() ?? ''; + if (!isLocalFile) attachmentPath = attachment.path(); return RNFetchBlob.MediaCollection.copyToMediaStore( { @@ -73,11 +77,11 @@ function handleDownload(url: string, fileName: string) { mimeType: null, }, 'Download', - String(attachmentPath), + attachmentPath, ); }) .then(() => { - RNFetchBlob.fs.unlink(String(attachmentPath)); + RNFetchBlob.fs.unlink(attachmentPath); FileUtils.showSuccessAlert(); }) .catch(() => { @@ -89,9 +93,12 @@ function handleDownload(url: string, fileName: string) { /** * Checks permission and downloads the file for Android + * @param {String} url + * @param {String} fileName + * @returns {Promise} */ -export default function fileDownload(url: string, fileName: string) { - return new Promise((resolve) => { +export default function fileDownload(url, fileName) { + return new Promise((resolve) => { hasAndroidPermission() .then((hasPermission) => { if (hasPermission) { diff --git a/src/libs/fileDownload/index.ios.ts b/src/libs/fileDownload/index.ios.js similarity index 78% rename from src/libs/fileDownload/index.ios.ts rename to src/libs/fileDownload/index.ios.js index b0540da95a33..95d92f1e3103 100644 --- a/src/libs/fileDownload/index.ios.ts +++ b/src/libs/fileDownload/index.ios.js @@ -1,12 +1,16 @@ import RNFetchBlob from 'react-native-blob-util'; import {CameraRoll} from '@react-native-camera-roll/camera-roll'; +import lodashGet from 'lodash/get'; import * as FileUtils from './FileUtils'; import CONST from '../../CONST'; /** * Downloads the file to Documents section in iOS + * @param {String} fileUrl + * @param {String} fileName + * @returns {Promise} */ -function downloadFile(fileUrl: string, fileName: string) { +function downloadFile(fileUrl, fileName) { const dirs = RNFetchBlob.fs.dirs; // The iOS files will download to documents directory @@ -27,25 +31,29 @@ function downloadFile(fileUrl: string, fileName: string) { /** * Download the image to photo lib in iOS - * @returns URI + * @param {String} fileUrl + * @param {String} fileName + * @returns {String} URI */ -function downloadImage(fileUrl: string) { +function downloadImage(fileUrl) { return CameraRoll.save(fileUrl); } /** * Download the video to photo lib in iOS - * @returns URI + * @param {String} fileUrl + * @param {String} fileName + * @returns {String} URI */ -function downloadVideo(fileUrl: string, fileName: string): Promise { +function downloadVideo(fileUrl, fileName) { return new Promise((resolve, reject) => { - let documentPathUri: string; - let cameraRollUri: string; + let documentPathUri = null; + let cameraRollUri = null; // Because CameraRoll doesn't allow direct downloads of video with remote URIs, we first download as documents, then copy to photo lib and unlink the original file. downloadFile(fileUrl, fileName) .then((attachment) => { - documentPathUri = attachment?.data; + documentPathUri = lodashGet(attachment, 'data'); return CameraRoll.save(documentPathUri); }) .then((attachment) => { @@ -59,16 +67,19 @@ function downloadVideo(fileUrl: string, fileName: string): Promise} */ -export default function fileDownload(fileUrl: string, fileName: string) { - return new Promise((resolve) => { +export default function fileDownload(fileUrl, fileName) { + return new Promise((resolve) => { let fileDownloadPromise = null; const fileType = FileUtils.getFileType(fileUrl); const attachmentName = FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(fileUrl); switch (fileType) { case CONST.ATTACHMENT_FILE_TYPE.IMAGE: - fileDownloadPromise = downloadImage(fileUrl); + fileDownloadPromise = downloadImage(fileUrl, attachmentName); break; case CONST.ATTACHMENT_FILE_TYPE.VIDEO: fileDownloadPromise = downloadVideo(fileUrl, attachmentName); diff --git a/src/libs/fileDownload/index.ts b/src/libs/fileDownload/index.js similarity index 85% rename from src/libs/fileDownload/index.ts rename to src/libs/fileDownload/index.js index 81e78f6baa9a..a775576eb365 100644 --- a/src/libs/fileDownload/index.ts +++ b/src/libs/fileDownload/index.js @@ -3,9 +3,12 @@ import * as Link from '../actions/Link'; /** * Downloading attachment in web, desktop + * @param {String} url + * @param {String} fileName + * @returns {Promise} */ -export default function fileDownload(url: string, fileName: string) { - return new Promise((resolve) => { +export default function fileDownload(url, fileName) { + return new Promise((resolve) => { fetch(url) .then((response) => response.blob()) .then((blob) => { @@ -31,7 +34,7 @@ export default function fileDownload(url: string, fileName: string) { // Clean up and remove the link URL.revokeObjectURL(link.href); - link.parentNode?.removeChild(link); + link.parentNode.removeChild(link); return resolve(); }) .catch(() => { From 7bd5be7df8da7107dabcab98f6043ac572a8626f Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Wed, 20 Sep 2023 13:47:58 +0100 Subject: [PATCH 3/5] ref: move local file download to TS --- .../localFileDownload/{index.android.js => index.android.ts} | 5 +---- src/libs/localFileDownload/{index.ios.js => index.ios.ts} | 5 +---- src/libs/localFileDownload/{index.js => index.ts} | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) rename src/libs/localFileDownload/{index.android.js => index.android.ts} (89%) rename src/libs/localFileDownload/{index.ios.js => index.ios.ts} (84%) rename src/libs/localFileDownload/{index.js => index.ts} (80%) diff --git a/src/libs/localFileDownload/index.android.js b/src/libs/localFileDownload/index.android.ts similarity index 89% rename from src/libs/localFileDownload/index.android.js rename to src/libs/localFileDownload/index.android.ts index b3e39e7a7a53..10cb8c2e35dc 100644 --- a/src/libs/localFileDownload/index.android.js +++ b/src/libs/localFileDownload/index.android.ts @@ -5,11 +5,8 @@ import * as FileUtils from '../fileDownload/FileUtils'; * Writes a local file to the app's internal directory with the given fileName * and textContent, so we're able to copy it to the Android public download dir. * After the file is copied, it is removed from the internal dir. - * - * @param {String} fileName - * @param {String} textContent */ -export default function localFileDownload(fileName, textContent) { +export default function localFileDownload(fileName: string, textContent: string) { const newFileName = FileUtils.appendTimeToFileName(fileName); const dir = RNFetchBlob.fs.dirs.DocumentDir; const path = `${dir}/${newFileName}.txt`; diff --git a/src/libs/localFileDownload/index.ios.js b/src/libs/localFileDownload/index.ios.ts similarity index 84% rename from src/libs/localFileDownload/index.ios.js rename to src/libs/localFileDownload/index.ios.ts index 1241f5a535db..2d0d54b411ae 100644 --- a/src/libs/localFileDownload/index.ios.js +++ b/src/libs/localFileDownload/index.ios.ts @@ -6,11 +6,8 @@ import * as FileUtils from '../fileDownload/FileUtils'; * Writes a local file to the app's internal directory with the given fileName * and textContent, so we're able to share it using iOS' share API. * After the file is shared, it is removed from the internal dir. - * - * @param {String} fileName - * @param {String} textContent */ -export default function localFileDownload(fileName, textContent) { +export default function localFileDownload(fileName: string, textContent: string) { const newFileName = FileUtils.appendTimeToFileName(fileName); const dir = RNFetchBlob.fs.dirs.DocumentDir; const path = `${dir}/${newFileName}.txt`; diff --git a/src/libs/localFileDownload/index.js b/src/libs/localFileDownload/index.ts similarity index 80% rename from src/libs/localFileDownload/index.js rename to src/libs/localFileDownload/index.ts index 427928834c9c..42074cc9146f 100644 --- a/src/libs/localFileDownload/index.js +++ b/src/libs/localFileDownload/index.ts @@ -4,11 +4,8 @@ import * as FileUtils from '../fileDownload/FileUtils'; * Creates a Blob with the given fileName and textContent, then dynamically * creates a temporary anchor, just to programmatically click it, so the file * is downloaded by the browser. - * - * @param {String} fileName - * @param {String} textContent */ -export default function localFileDownload(fileName, textContent) { +export default function localFileDownload(fileName: string, textContent: string) { const blob = new Blob([textContent], {type: 'text/plain'}); const url = URL.createObjectURL(blob); const link = document.createElement('a'); From 1eed015711e5e810cf6f5a6abbe7655e70972857 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Wed, 20 Sep 2023 15:01:20 +0100 Subject: [PATCH 4/5] group platform-specific types --- src/libs/localFileDownload/index.android.ts | 3 ++- src/libs/localFileDownload/index.ios.ts | 3 ++- src/libs/localFileDownload/index.ts | 3 ++- src/libs/localFileDownload/types.ts | 5 +++++ 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/libs/localFileDownload/types.ts diff --git a/src/libs/localFileDownload/index.android.ts b/src/libs/localFileDownload/index.android.ts index 10cb8c2e35dc..0b91b3a10d0d 100644 --- a/src/libs/localFileDownload/index.android.ts +++ b/src/libs/localFileDownload/index.android.ts @@ -1,12 +1,13 @@ import RNFetchBlob from 'react-native-blob-util'; import * as FileUtils from '../fileDownload/FileUtils'; +import LocalFileDownload from './types'; /** * Writes a local file to the app's internal directory with the given fileName * and textContent, so we're able to copy it to the Android public download dir. * After the file is copied, it is removed from the internal dir. */ -export default function localFileDownload(fileName: string, textContent: string) { +export default function localFileDownload({fileName, textContent}: LocalFileDownload) { const newFileName = FileUtils.appendTimeToFileName(fileName); const dir = RNFetchBlob.fs.dirs.DocumentDir; const path = `${dir}/${newFileName}.txt`; diff --git a/src/libs/localFileDownload/index.ios.ts b/src/libs/localFileDownload/index.ios.ts index 2d0d54b411ae..427f6c3463ed 100644 --- a/src/libs/localFileDownload/index.ios.ts +++ b/src/libs/localFileDownload/index.ios.ts @@ -1,13 +1,14 @@ import {Share} from 'react-native'; import RNFetchBlob from 'react-native-blob-util'; import * as FileUtils from '../fileDownload/FileUtils'; +import LocalFileDownload from './types'; /** * Writes a local file to the app's internal directory with the given fileName * and textContent, so we're able to share it using iOS' share API. * After the file is shared, it is removed from the internal dir. */ -export default function localFileDownload(fileName: string, textContent: string) { +export default function localFileDownload({fileName, textContent}: LocalFileDownload) { const newFileName = FileUtils.appendTimeToFileName(fileName); const dir = RNFetchBlob.fs.dirs.DocumentDir; const path = `${dir}/${newFileName}.txt`; diff --git a/src/libs/localFileDownload/index.ts b/src/libs/localFileDownload/index.ts index 42074cc9146f..8c2e4e4baf38 100644 --- a/src/libs/localFileDownload/index.ts +++ b/src/libs/localFileDownload/index.ts @@ -1,11 +1,12 @@ import * as FileUtils from '../fileDownload/FileUtils'; +import LocalFileDownload from './types'; /** * Creates a Blob with the given fileName and textContent, then dynamically * creates a temporary anchor, just to programmatically click it, so the file * is downloaded by the browser. */ -export default function localFileDownload(fileName: string, textContent: string) { +export default function localFileDownload({fileName, textContent}: LocalFileDownload) { const blob = new Blob([textContent], {type: 'text/plain'}); const url = URL.createObjectURL(blob); const link = document.createElement('a'); diff --git a/src/libs/localFileDownload/types.ts b/src/libs/localFileDownload/types.ts new file mode 100644 index 000000000000..ddc9f8a40246 --- /dev/null +++ b/src/libs/localFileDownload/types.ts @@ -0,0 +1,5 @@ +type LocalFileDownload = { + fileName: string; + textContent: string; +}; +export default LocalFileDownload; From 801dddcb8d2a416148419a526e1a8f90b490f2c6 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Tue, 26 Sep 2023 09:14:25 +0100 Subject: [PATCH 5/5] resolve review comments --- src/libs/localFileDownload/index.android.ts | 6 ++++-- src/libs/localFileDownload/index.ios.ts | 6 ++++-- src/libs/localFileDownload/index.ts | 6 ++++-- src/libs/localFileDownload/types.ts | 6 ++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libs/localFileDownload/index.android.ts b/src/libs/localFileDownload/index.android.ts index 0b91b3a10d0d..ad13b5c5cfa7 100644 --- a/src/libs/localFileDownload/index.android.ts +++ b/src/libs/localFileDownload/index.android.ts @@ -7,7 +7,7 @@ import LocalFileDownload from './types'; * and textContent, so we're able to copy it to the Android public download dir. * After the file is copied, it is removed from the internal dir. */ -export default function localFileDownload({fileName, textContent}: LocalFileDownload) { +const localFileDownload: LocalFileDownload = (fileName, textContent) => { const newFileName = FileUtils.appendTimeToFileName(fileName); const dir = RNFetchBlob.fs.dirs.DocumentDir; const path = `${dir}/${newFileName}.txt`; @@ -32,4 +32,6 @@ export default function localFileDownload({fileName, textContent}: LocalFileDown RNFetchBlob.fs.unlink(path); }); }); -} +}; + +export default localFileDownload; diff --git a/src/libs/localFileDownload/index.ios.ts b/src/libs/localFileDownload/index.ios.ts index 427f6c3463ed..3597ea5f6d3c 100644 --- a/src/libs/localFileDownload/index.ios.ts +++ b/src/libs/localFileDownload/index.ios.ts @@ -8,7 +8,7 @@ import LocalFileDownload from './types'; * and textContent, so we're able to share it using iOS' share API. * After the file is shared, it is removed from the internal dir. */ -export default function localFileDownload({fileName, textContent}: LocalFileDownload) { +const localFileDownload: LocalFileDownload = (fileName, textContent) => { const newFileName = FileUtils.appendTimeToFileName(fileName); const dir = RNFetchBlob.fs.dirs.DocumentDir; const path = `${dir}/${newFileName}.txt`; @@ -18,4 +18,6 @@ export default function localFileDownload({fileName, textContent}: LocalFileDown RNFetchBlob.fs.unlink(path); }); }); -} +}; + +export default localFileDownload; diff --git a/src/libs/localFileDownload/index.ts b/src/libs/localFileDownload/index.ts index 8c2e4e4baf38..7b9b4973d5c1 100644 --- a/src/libs/localFileDownload/index.ts +++ b/src/libs/localFileDownload/index.ts @@ -6,11 +6,13 @@ import LocalFileDownload from './types'; * creates a temporary anchor, just to programmatically click it, so the file * is downloaded by the browser. */ -export default function localFileDownload({fileName, textContent}: LocalFileDownload) { +const localFileDownload: LocalFileDownload = (fileName, textContent) => { const blob = new Blob([textContent], {type: 'text/plain'}); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.download = FileUtils.appendTimeToFileName(`${fileName}.txt`); link.href = url; link.click(); -} +}; + +export default localFileDownload; diff --git a/src/libs/localFileDownload/types.ts b/src/libs/localFileDownload/types.ts index ddc9f8a40246..2086e2334d39 100644 --- a/src/libs/localFileDownload/types.ts +++ b/src/libs/localFileDownload/types.ts @@ -1,5 +1,3 @@ -type LocalFileDownload = { - fileName: string; - textContent: string; -}; +type LocalFileDownload = (fileName: string, textContent: string) => void; + export default LocalFileDownload;