mirror of
https://github.com/upscayl/upscayl.git
synced 2025-02-17 11:18:36 +01:00
Add removeFileExtension utility function
This commit is contained in:
parent
68d3395cbe
commit
fb7728077e
@ -22,6 +22,7 @@ import DEFAULT_MODELS from "../constants/models";
|
||||
import { BatchUpscaylPayload } from "../../common/types/types";
|
||||
import { ImageFormat } from "../utils/types";
|
||||
import getModelScale from "../../common/check-model-scale";
|
||||
import removeFileExtension from "../utils/remove-file-extension";
|
||||
|
||||
const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
||||
const mainWindow = getMainWindow();
|
||||
@ -129,11 +130,11 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
||||
const files = fs.readdirSync(inputDir);
|
||||
try {
|
||||
files.forEach(async (file) => {
|
||||
console.log("Filename: ", file.slice(0, -3));
|
||||
console.log("Filename: ", removeFileExtension(file));
|
||||
await convertAndScale(
|
||||
inputDir + slash + file,
|
||||
outputDir + slash + file.slice(0, -3) + "png",
|
||||
outputDir + slash + file.slice(0, -3) + saveImageAs,
|
||||
`${outputDir}${slash}${removeFileExtension(file)}.png`,
|
||||
`${outputDir}/${removeFileExtension(file)}.${saveImageAs}`,
|
||||
desiredScale,
|
||||
saveImageAs,
|
||||
onError
|
||||
@ -141,7 +142,9 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
||||
// Remove the png file (default) if the saveImageAs is not png
|
||||
if (saveImageAs !== "png") {
|
||||
logit("Removing output PNG");
|
||||
fs.unlinkSync(outputDir + slash + file.slice(0, -3) + "png");
|
||||
fs.unlinkSync(
|
||||
`${outputDir}${slash}${removeFileExtension(file)}.png`
|
||||
);
|
||||
}
|
||||
});
|
||||
mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);
|
||||
|
@ -25,6 +25,7 @@ import { getMainWindow } from "../main-window";
|
||||
import { ImageUpscaylPayload } from "../../common/types/types";
|
||||
import { ImageFormat } from "../utils/types";
|
||||
import getModelScale from "../../common/check-model-scale";
|
||||
import removeFileExtension from "../utils/remove-file-extension";
|
||||
|
||||
const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
||||
const mainWindow = getMainWindow();
|
||||
@ -104,7 +105,7 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
||||
getSingleImageArguments(
|
||||
inputDir,
|
||||
fullfileName,
|
||||
outFile.slice(0, -3) + "png",
|
||||
removeFileExtension(outFile) + ".png",
|
||||
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
||||
model,
|
||||
initialScale,
|
||||
@ -165,19 +166,23 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
||||
try {
|
||||
await convertAndScale(
|
||||
inputDir + slash + fullfileName,
|
||||
outFile.slice(0, -3) + "png",
|
||||
removeFileExtension(outFile) + ".png",
|
||||
outFile,
|
||||
desiredScale,
|
||||
saveImageAs,
|
||||
onError
|
||||
);
|
||||
// Remove the png file (default) if the saveImageAs is not png
|
||||
fs.access(outFile.slice(0, -3) + "png", fs.constants.F_OK, (err) => {
|
||||
if (!err && saveImageAs !== "png") {
|
||||
logit("🗑 Removing png file");
|
||||
fs.unlinkSync(outFile.slice(0, -3) + "png");
|
||||
fs.access(
|
||||
removeFileExtension(outFile) + ".png",
|
||||
fs.constants.F_OK,
|
||||
(err) => {
|
||||
if (!err && saveImageAs !== "png") {
|
||||
logit("🗑 Removing png file");
|
||||
fs.unlinkSync(removeFileExtension(outFile) + ".png");
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
mainWindow.setProgressBar(-1);
|
||||
mainWindow.webContents.send(
|
||||
COMMAND.UPSCAYL_DONE,
|
||||
|
8
electron/utils/remove-file-extension.ts
Normal file
8
electron/utils/remove-file-extension.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Returns the filename without the extension.
|
||||
* @param filename The filename to remove the extension from.
|
||||
* @returns The filename without the extension.
|
||||
*/
|
||||
export default function removeFileExtension(filename: string): string {
|
||||
return filename.replace(/\.[^/.]+$/, "");
|
||||
}
|
@ -175,6 +175,12 @@ function SettingsTab({
|
||||
target="_blank">
|
||||
Read Wiki Guide
|
||||
</a>
|
||||
<a
|
||||
className="btn-primary btn"
|
||||
href="mailto:nayam.emikx@aleeas.com?subject=Upscayl%20Issue:%20&body=Describe%20your%20issue%20here."
|
||||
target="_blank">
|
||||
Email Developer
|
||||
</a>
|
||||
{!featureFlags.APP_STORE_BUILD && <DonateButton />}
|
||||
</div>
|
||||
|
||||
|
@ -221,10 +221,10 @@ function LeftPaneImageSteps({
|
||||
Double Upscayl
|
||||
</p>
|
||||
<button
|
||||
className="badge-info badge cursor-help"
|
||||
className="badge badge-sm badge-neutral cursor-help"
|
||||
data-tooltip-id="tooltip"
|
||||
data-tooltip-content="Enable this option to get a 16x upscayl (we just run upscayl twice). Note that this may not always work properly with all images, for example, images with really large resolutions.">
|
||||
i
|
||||
?
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
@ -237,6 +237,17 @@ function LeftPaneImageSteps({
|
||||
data-tooltip-id="tooltip">
|
||||
<div className="step-heading flex items-center gap-2">
|
||||
<span>Step 3</span>
|
||||
{featureFlags.APP_STORE_BUILD && (
|
||||
<button
|
||||
className="badge badge-sm badge-outline cursor-pointer"
|
||||
onClick={() =>
|
||||
alert(
|
||||
"Due to MacOS App Store security restrictions, Upscayl requires you to select an output folder everytime you start it.\n\nTo avoid this, you can permanently save a default output folder in the Upscayl 'Settings' tab."
|
||||
)
|
||||
}>
|
||||
?
|
||||
</button>
|
||||
)}
|
||||
{!outputPath && featureFlags.APP_STORE_BUILD && (
|
||||
<div className="text-xs">
|
||||
<span className="bg-base-200 font-medium uppercase text-base-content/50 rounded-btn px-2">
|
||||
|
Loading…
x
Reference in New Issue
Block a user