1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-09-23 19:08:25 +02:00

Fix batch upscayl

This commit is contained in:
Nayam Amarshe 2023-12-03 12:06:00 +05:30
parent a6c9c5a20d
commit f08671c357
5 changed files with 1473 additions and 147 deletions

View File

@ -54,26 +54,18 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
}
const desiredScale = payload.scale as string;
const tempDirectory = outputDir + slash + "upscayl_temp";
outputDir +=
slash +
`upscayl_${model}_x${noImageProcessing ? initialScale : desiredScale}`;
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Create a folder in the output directory to store the original images
if (!fs.existsSync(tempDirectory)) {
fs.mkdirSync(tempDirectory, { recursive: true });
}
// Copy the files from the input directory to the output directory
// Delete .DS_Store files
fs.readdirSync(inputDir).forEach((file) => {
if (
file.toLocaleLowerCase().endsWith(".png") ||
file.toLocaleLowerCase().endsWith(".jpg") ||
file.toLocaleLowerCase().endsWith(".jpeg") ||
file.toLocaleLowerCase().endsWith(".webp")
) {
fs.copyFileSync(inputDir + slash + file, tempDirectory + slash + file);
if (file === ".DS_Store") {
logit("🗑️ Deleting .DS_Store file");
fs.unlinkSync(inputDir + slash + file);
}
});
@ -81,7 +73,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
const upscayl = spawnUpscayl(
"realesrgan",
getBatchArguments(
tempDirectory,
inputDir,
outputDir,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
model,
@ -137,51 +129,28 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
logit("🚫 Skipping scaling and converting");
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);
rmdir(
tempDirectory,
{
recursive: true,
},
(err) => {
if (err) {
logit("🚫 Error deleting temp folder", err);
}
}
);
return;
}
const files = fs.readdirSync(tempDirectory);
const files = fs.readdirSync(inputDir);
try {
files.forEach(async (file) => {
console.log("Filename: ", file.slice(0, -3));
await convertAndScale(
tempDirectory + slash + file,
inputDir + slash + file,
outputDir + slash + file.slice(0, -3) + "png",
outputDir + slash + file.slice(0, -3) + saveImageAs,
desiredScale,
saveImageAs,
onError
);
});
files.forEach(async (file) => {
// 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");
}
});
mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);
rmdir(
tempDirectory,
{
recursive: true,
},
(err) => {
if (err) {
logit("🚫 Error deleting temp folder", err);
}
}
);
} catch (error) {
logit("❌ Error processing (scaling and converting) the image.", error);
upscayl.kill();

View File

@ -2,9 +2,9 @@
"productName": "Upscayl",
"appId": "org.upscayl.Upscayl",
"afterSign": "./notarize.js",
"buildVersion": "23.11.5",
"buildVersion": "23.12.03",
"asar": true,
"asarUnpack": ["**/node_modules/sharp/**/*"],
"asarUnpack": ["**/node_modules/sharp/**/*", "**/node_modules/@img/**/*"],
"extraFiles": [
{
"from": "resources/${os}/bin",
@ -25,6 +25,8 @@
"entitlements": "resources/entitlements.mas.plist",
"entitlementsInherit": "resources/entitlements.mas.inherit.plist",
"provisioningProfile": "embedded.provisionprofile",
"icon": "build/icon.icns",
"x64ArchFiles": "*",
"target": [
{
"target": "mas",

1493
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "upscayl",
"private": true,
"version": "2.9.4",
"version": "2.9.5",
"productName": "Upscayl",
"author": {
"name": "Nayam Amarshe",
@ -232,6 +232,8 @@
"firebase": "^10.3.0",
"gray-matter": "^4.0.3",
"jotai": "^2.2.2",
"node-addon-api": "^7.0.0",
"node-gyp": "^10.0.1",
"react-compare-slider": "^2.2.0",
"react-markdown": "^9.0.1",
"react-select": "^5.7.4",
@ -242,6 +244,6 @@
"theme-change": "^2.5.0"
},
"volta": {
"node": "16.17.0"
"node": "18.17.0"
}
}

View File

@ -219,39 +219,43 @@ const Home = () => {
// FETCH NEWS
useEffect(() => {
fetch("https://raw.githubusercontent.com/upscayl/upscayl/main/news.md", {
cache: "no-cache",
})
.then((res) => {
return res.text();
// TODO: Disable on no internet
try {
return;
fetch("https://raw.githubusercontent.com/upscayl/upscayl/main/news.md", {
cache: "no-cache",
})
.then((result) => {
const newsData = result;
if (!newsData) {
console.log("📰 Could not fetch news data");
return;
}
const markdownData = matter(newsData);
if (!markdownData) return;
if (markdownData && markdownData.data.dontShow) {
return;
}
if (
markdownData &&
news &&
markdownData?.data?.version === news?.data?.version
) {
console.log("📰 News is up to date");
if (showNewsModal === false) {
setShowNewsModal(false);
.then((res) => {
return res.text();
})
.then((result) => {
const newsData = result;
if (!newsData) {
console.log("📰 Could not fetch news data");
return;
}
} else if (markdownData) {
setNews(matter(newsData));
setShowNewsModal(true);
}
});
const markdownData = matter(newsData);
if (!markdownData) return;
if (markdownData && markdownData.data.dontShow) {
return;
}
if (
markdownData &&
news &&
markdownData?.data?.version === news?.data?.version
) {
console.log("📰 News is up to date");
if (showNewsModal === false) {
setShowNewsModal(false);
}
} else if (markdownData) {
setNews(matter(newsData));
setShowNewsModal(true);
}
});
} catch (error) {
console.log("Could not fetch Upscayl News");
}
}, [news]);
// CONFIGURE SAVED OUTPUT PATH