π Upscayl - #1 Free and Open Source AI Image Upscaler for Linux, MacOS and Windows.
TypeScript aielectronesrgangigapixelgigapixel-imagesimageimage-upscalingtopazupscaleupscalerimageupscayl
Add removeFileExtension utility function
Nayam Amarshefb7728077e0f
diff --git a/electron/commands/batch-upscayl.ts b/electron/commands/batch-upscayl.tsindex 0b28321..f1aa5e4 100644--- a/electron/commands/batch-upscayl.ts+++ b/electron/commands/batch-upscayl.ts@@ -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 pngif (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);diff --git a/electron/commands/image-upscayl.ts b/electron/commands/image-upscayl.tsindex 667b5d1..c8cc7d2 100644--- a/electron/commands/image-upscayl.ts+++ b/electron/commands/image-upscayl.ts@@ -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,diff --git a/electron/utils/remove-file-extension.ts b/electron/utils/remove-file-extension.tsnew file mode 100644index 0000000..660450d--- /dev/null+++ b/electron/utils/remove-file-extension.ts@@ -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(/\.[^/.]+$/, "");+}diff --git a/renderer/components/settings-tab/index.tsx b/renderer/components/settings-tab/index.tsxindex 9fd0170..266489a 100644--- a/renderer/components/settings-tab/index.tsx+++ b/renderer/components/settings-tab/index.tsx@@ -175,6 +175,12 @@ function SettingsTab({target="_blank">Read Wiki Guide</a>+ <a+ className="btn-primary btn"+ href="mailto:[email protected]?subject=Upscayl%20Issue:%20&body=Describe%20your%20issue%20here."+ target="_blank">+ Email Developer+ </a>{!featureFlags.APP_STORE_BUILD && <DonateButton />}</div>diff --git a/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx b/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsxindex a060e30..2e700d5 100644--- a/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx+++ b/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx@@ -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">