-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add copy button as alt to move
- Loading branch information
1 parent
fe6da9d
commit 192a887
Showing
7 changed files
with
128 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
import { DataStorage } from "../bars/model/persisted/DataStorage"; | ||
|
||
export enum MoveOrCopy { | ||
Copy, | ||
Move | ||
} | ||
|
||
export namespace ImageMover { | ||
export async function moveStarredImagesTo( | ||
currentImageInputDir: string, | ||
directoryPath: string, | ||
mode: MoveOrCopy | ||
): Promise<void> { | ||
const imagePaths = DataStorage.getPathsOfStarredImages(currentImageInputDir); | ||
|
||
let hasErrors = false; | ||
|
||
return new Promise<void>((resolve, reject) => { | ||
const done = () => { | ||
if (hasErrors) { | ||
reject("Some errors occurred when moving the files"); | ||
} else { | ||
resolve(); | ||
} | ||
}; | ||
|
||
imagePaths.forEach((imagePath, index) => { | ||
const fileName = path.basename(imagePath); | ||
const newPath = path.resolve(path.join(directoryPath, fileName)); | ||
|
||
switch (mode) { | ||
case MoveOrCopy.Copy: | ||
fs.copyFile(imagePath, newPath, error => { | ||
if (error) { | ||
console.error(error); | ||
hasErrors = true; | ||
} | ||
|
||
if (index === imagePaths.length - 1) { | ||
done(); | ||
} | ||
}); | ||
break; | ||
case MoveOrCopy.Move: | ||
fs.rename(imagePath, newPath, error => { | ||
if (error) { | ||
console.error(error); | ||
hasErrors = true; | ||
} else { | ||
DataStorage.setImageAsNoStar(imagePath); | ||
} | ||
|
||
if (index === imagePaths.length - 1) { | ||
done(); | ||
} | ||
}); | ||
break; | ||
default: | ||
throw new Error(`unhandled mode '${mode}'`); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes