remove delete api and add move api
This commit is contained in:
parent
36107a665c
commit
679894632c
|
@ -5,9 +5,4 @@ export async function getDirFiles(dirPath: string) {
|
||||||
const electronFiles = await Promise.all(files.map(getElectronFile));
|
const electronFiles = await Promise.all(files.map(getElectronFile));
|
||||||
return electronFiles;
|
return electronFiles;
|
||||||
}
|
}
|
||||||
export {
|
export { isFolder, moveFile, readTextFile } from '../services/fs';
|
||||||
isFolder,
|
|
||||||
removeFile,
|
|
||||||
removeFolder,
|
|
||||||
readTextFile,
|
|
||||||
} from '../services/fs';
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ import {
|
||||||
openDirectory,
|
openDirectory,
|
||||||
} from './api/common';
|
} from './api/common';
|
||||||
import { fixHotReloadNext12 } from './utils/preload';
|
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 { convertHEIC, generateImageThumbnail } from './api/imageProcessor';
|
||||||
import { setupLogging } from './utils/logging';
|
import { setupLogging } from './utils/logging';
|
||||||
import {
|
import {
|
||||||
|
@ -105,6 +105,5 @@ windowObject['ElectronAPIs'] = {
|
||||||
logRendererProcessMemoryUsage,
|
logRendererProcessMemoryUsage,
|
||||||
registerForegroundEventListener,
|
registerForegroundEventListener,
|
||||||
openDirectory,
|
openDirectory,
|
||||||
removeFile,
|
moveFile,
|
||||||
removeFolder,
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -242,16 +242,20 @@ export async function readTextFile(filePath: string) {
|
||||||
return await fs.readFile(filePath, 'utf-8');
|
return await fs.readFile(filePath, 'utf-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeFile(filePath: string) {
|
export async function moveFile(
|
||||||
if (!existsSync(filePath)) {
|
sourcePath: string,
|
||||||
return;
|
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;
|
|
||||||
}
|
}
|
||||||
fs.rmSync(folderPath, { recursive: true, force: true });
|
// check if destination folder exists
|
||||||
|
const destinationFolder = path.dirname(destinationPath);
|
||||||
|
if (!existsSync(destinationFolder)) {
|
||||||
|
throw new Error('Destination folder does not exist');
|
||||||
|
}
|
||||||
|
await fs.rename(sourcePath, destinationPath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue