From c3b4872da76d0c1e5ff7b15c11e8fd13d976e66b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 27 Aug 2022 10:37:32 +0530 Subject: [PATCH] move non-exported function to util --- src/api/upload.ts | 17 ++++------------- src/services/fs.ts | 3 --- src/utils/upload.ts | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 src/utils/upload.ts diff --git a/src/api/upload.ts b/src/api/upload.ts index 90d70ae31..e380fa048 100644 --- a/src/api/upload.ts +++ b/src/api/upload.ts @@ -1,10 +1,11 @@ import { getZipFileStream } from './../services/fs'; -import { getElectronFile, getValidPaths } from './../services/fs'; +import { getElectronFile } from './../services/fs'; import path from 'path'; import StreamZip from 'node-stream-zip'; import { uploadStatusStore } from '../stores/upload.store'; import { ElectronFile, FILE_PATH_KEYS, FILE_PATH_TYPE } from '../types'; import { ipcRenderer } from 'electron'; +import { getSavedFilePaths } from '../utils/upload'; async function getZipEntryAsElectronFile( zip: StreamZip.StreamZipAsync, @@ -47,8 +48,8 @@ export const setToUploadCollection = (collectionName: string) => { }; export const getPendingUploads = async () => { - const filePaths = getSavedPaths(FILE_PATH_TYPE.FILES); - const zipPaths = getSavedPaths(FILE_PATH_TYPE.ZIPS); + const filePaths = getSavedFilePaths(FILE_PATH_TYPE.FILES); + const zipPaths = getSavedFilePaths(FILE_PATH_TYPE.ZIPS); const collectionName = uploadStatusStore.get('collectionName'); let files: ElectronFile[] = []; @@ -120,13 +121,3 @@ export const showUploadZipDialog = async () => { files, }; }; - -const getSavedPaths = (type: FILE_PATH_TYPE) => { - const paths = - getValidPaths( - uploadStatusStore.get(FILE_PATH_KEYS[type]) as string[] - ) ?? []; - - setToUploadFiles(type, paths); - return paths; -}; diff --git a/src/services/fs.ts b/src/services/fs.ts index ace660ee1..0a6585664 100644 --- a/src/services/fs.ts +++ b/src/services/fs.ts @@ -2,7 +2,6 @@ import { FILE_STREAM_CHUNK_SIZE } from '../config'; import path from 'path'; import * as fs from 'promise-fs'; import { ElectronFile } from '../types'; -import { logError } from '../utils/logging'; import StreamZip from 'node-stream-zip'; import { Readable } from 'stream'; @@ -46,7 +45,6 @@ export const getFileStream = async (filePath: string) => { controller.enqueue(buff); } } catch (e) { - logError(e, 'stream pull failed'); await fs.close(file); } }, @@ -143,7 +141,6 @@ export const getZipFileStream = async ( controller.close(); } } catch (e) { - logError(e, 'stream reading failed'); controller.close(); } }, diff --git a/src/utils/upload.ts b/src/utils/upload.ts new file mode 100644 index 000000000..037d64370 --- /dev/null +++ b/src/utils/upload.ts @@ -0,0 +1,14 @@ +import { setToUploadFiles } from '../api/upload'; +import { getValidPaths } from '../services/fs'; +import { uploadStatusStore } from '../stores/upload.store'; +import { FILE_PATH_TYPE, FILE_PATH_KEYS } from '../types'; + +export const getSavedFilePaths = (type: FILE_PATH_TYPE) => { + const paths = + getValidPaths( + uploadStatusStore.get(FILE_PATH_KEYS[type]) as string[] + ) ?? []; + + setToUploadFiles(type, paths); + return paths; +};