move non-exported function to util
This commit is contained in:
parent
b3f60bffcc
commit
c3b4872da7
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
},
|
||||
|
|
14
src/utils/upload.ts
Normal file
14
src/utils/upload.ts
Normal file
|
@ -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;
|
||||
};
|
Loading…
Reference in a new issue