remove delete api and add move api

This commit is contained in:
Abhinav 2023-04-25 15:31:27 +05:30
parent 36107a665c
commit 679894632c
3 changed files with 17 additions and 19 deletions

View file

@ -5,9 +5,4 @@ export async function getDirFiles(dirPath: string) {
const electronFiles = await Promise.all(files.map(getElectronFile));
return electronFiles;
}
export {
isFolder,
removeFile,
removeFolder,
readTextFile,
} from '../services/fs';
export { isFolder, moveFile, readTextFile } from '../services/fs';

View file

@ -45,7 +45,7 @@ import {
openDirectory,
} from './api/common';
import { fixHotReloadNext12 } from './utils/preload';
import { isFolder, getDirFiles, removeFile, removeFolder } from './api/fs';
import { isFolder, getDirFiles, moveFile } from './api/fs';
import { convertHEIC, generateImageThumbnail } from './api/imageProcessor';
import { setupLogging } from './utils/logging';
import {
@ -105,6 +105,5 @@ windowObject['ElectronAPIs'] = {
logRendererProcessMemoryUsage,
registerForegroundEventListener,
openDirectory,
removeFile,
removeFolder,
moveFile,
};

View file

@ -242,16 +242,20 @@ export async function readTextFile(filePath: string) {
return await fs.readFile(filePath, 'utf-8');
}
export async function removeFile(filePath: string) {
if (!existsSync(filePath)) {
return;
export async function moveFile(
sourcePath: string,
destinationPath: string
): Promise<void> {
if (!existsSync(sourcePath)) {
throw new Error('File does not exist');
}
await fs.unlink(filePath);
if (existsSync(destinationPath)) {
throw new Error('Destination file already exists');
}
export async function removeFolder(folderPath: string) {
if (!existsSync(folderPath)) {
return;
// check if destination folder exists
const destinationFolder = path.dirname(destinationPath);
if (!existsSync(destinationFolder)) {
throw new Error('Destination folder does not exist');
}
fs.rmSync(folderPath, { recursive: true, force: true });
await fs.rename(sourcePath, destinationPath);
}