From 30f0af8e361b5123b61a0e0db2bfcefcc1d8933c Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 9 May 2023 17:14:45 +0530 Subject: [PATCH] export simpler APIs --- src/api/export.ts | 21 ++------------------- src/api/fs.ts | 8 +++++++- src/preload.ts | 6 ++---- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/api/export.ts b/src/api/export.ts index 118a6c1a5..50a9a88d7 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -1,5 +1,4 @@ -import { readTextFile, writeStream } from './../services/fs'; -import { logError } from '../services/logging'; +import { writeStream } from './../services/fs'; import * as fs from 'promise-fs'; export const exists = (path: string) => { @@ -19,22 +18,6 @@ export const saveStreamToDisk = async ( await writeStream(filePath, fileStream); }; -export const saveFileToDisk = async (path: string, fileData: any) => { +export const saveFileToDisk = async (path: string, fileData: string) => { await fs.writeFile(path, fileData); }; - -export const getExportRecord = async (filePath: string) => { - try { - if (!fs.existsSync(filePath)) { - return null; - } - const recordFile = await readTextFile(filePath); - return recordFile; - } catch (e) { - logError(e, 'error while selecting files'); - } -}; - -export const setExportRecord = async (filePath: string, data: string) => { - await fs.writeFile(filePath, data); -}; diff --git a/src/api/fs.ts b/src/api/fs.ts index a5cbfc510..762e6df22 100644 --- a/src/api/fs.ts +++ b/src/api/fs.ts @@ -5,4 +5,10 @@ export async function getDirFiles(dirPath: string) { const electronFiles = await Promise.all(files.map(getElectronFile)); return electronFiles; } -export { isFolder, moveFile, deleteFolder, rename } from '../services/fs'; +export { + isFolder, + moveFile, + deleteFolder, + rename, + readTextFile, +} from '../services/fs'; diff --git a/src/preload.ts b/src/preload.ts index e94534f9e..d5e10750d 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -31,8 +31,6 @@ import { checkExistsAndCreateDir, saveStreamToDisk, saveFileToDisk, - getExportRecord, - setExportRecord, exists, } from './api/export'; import { @@ -50,6 +48,7 @@ import { moveFile, deleteFolder, rename, + readTextFile, } from './api/fs'; import { convertHEIC, generateImageThumbnail } from './api/imageProcessor'; import { setupLogging } from './utils/logging'; @@ -74,8 +73,7 @@ windowObject['ElectronAPIs'] = { clearElectronStore, sendNotification, reloadWindow, - getExportRecord, - setExportRecord, + readTextFile, showUploadFilesDialog, showUploadDirsDialog, getPendingUploads,