icon_reloading script update (#927)

- skip list as string list
 - better root dir, ts-node compatibility
 - parsing plugins.json instead of parsing folders
 - check if google returns notavailable icon
 - better log
This commit is contained in:
Justin COLLON
2024-05-11 05:49:43 +02:00
committed by GitHub
parent c50eccf867
commit f3b0c676d9
11 changed files with 92 additions and 57 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 414 B

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 590 B

After

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

+2 -1
View File
@@ -13,7 +13,8 @@
"host-linux": "chmod +x ./host.sh && ./host.sh", "host-linux": "chmod +x ./host.sh && ./host.sh",
"host-windows": "powershell ./host.ps1", "host-windows": "powershell ./host.ps1",
"prettier": "prettier --write \"./**/*.{js,ts}\"", "prettier": "prettier --write \"./**/*.{js,ts}\"",
"prepare": "husky install" "prepare": "husky install",
"icons": "npm run clearMultisrc && npm run generate && npm run json && ts-node ./scripts/icon_reloading.ts"
}, },
"author": "LNReader", "author": "LNReader",
"license": "MIT", "license": "MIT",
+90 -56
View File
@@ -4,78 +4,112 @@ import { Plugin } from '@typings/plugin';
import { languages } from '@libs/languages'; import { languages } from '@libs/languages';
import * as path from 'path'; import * as path from 'path';
const delay = (ms: number) => new Promise(res => setTimeout(res, ms)); const root = path.join(__dirname, '..');
const root = path.dirname(__dirname);
const size = 96; const size = 96;
const skip: { [key: string]: boolean } = { const skip: string[] = [
//custom icons //custom icons
'ReN': true, 'ReN',
'sektenovel': true, 'sektenovel',
'FWK.US': true, 'FWK.US',
'daonovel',
'dragontea',
'foxaholic',
'kiniga',
'sonicmtl',
'translatinotaku',
'wuxiaworld.site',
'moonlightnovel',
'mtl-novel',
'mysticalmerries',
'lightnovelpubvip',
'novelTL',
//low quality //low quality
'BLN': true, 'BLN',
'novelhall': true, 'novelhall',
'NO.net': true, 'NO.net',
'novelbookid',
'olaoe',
//broken icons //broken icons
'guavaread': true, 'guavaread',
'LightNovelUpdates': true, 'LightNovelUpdates',
'turkcelightnovels': true, 'turkcelightnovels',
'novelki.pl': true, 'novelki.pl',
'lunarletters': true, 'lunarletters',
'novelsparadise',
//dead plugins? 'earlynovel',
'freenovel.me': true, 'wbnovel',
'daonovel': true, 'novhell',
'mtl-novel': true, 'RLIB',
'novelroom': true, ];
'zinnovel': true,
'novelr18': true,
'novelstic': true,
'readwebnovels': true,
};
const used = new Set(); const used = new Set();
used.add(path.join(root, '..', 'icons', 'coverNotAvailable.webp')); used.add(path.join(root, 'icons', 'coverNotAvailable.webp'));
(async () => { (async () => {
console.log('Loading plugins.json ⌛');
const plugin_path = path.join(root, '.dist', 'plugins.json');
if (!fs.existsSync(plugin_path)) {
console.log('❌', plugin_path, 'not found (run "json_plugins.ts" first)');
return;
}
const plugins = JSON.parse(fs.readFileSync(plugin_path, 'utf-8'));
console.log('\nDownloading icons ⌛'); console.log('\nDownloading icons ⌛');
for (let language in languages) { let language;
const langPath = path.join(root, 'plugins', language.toLowerCase()); for (let plugin in plugins) {
if (!fs.existsSync(langPath)) continue; const { id, name, site, iconUrl, lang } = plugins[plugin];
const plugins = fs.readdirSync(langPath); if (language !== lang) {
for (let i = 0; i < plugins.length; i++) { language = lang;
const instance: Plugin.PluginBase = require( console.log(
`../plugins/${language.toLowerCase()}/${plugins[i].split('.')[0]}`, ` ${language} `
).default; .padStart(Math.floor((language.length + 32) / 2), '=')
.padEnd(30, '='),
);
}
let icon;
if (iconUrl) icon = 'icons/' + iconUrl.split('icons/')[1];
try {
if (icon) used.add(path.join(root, icon));
const { id, name, site, icon } = instance; if (!skip.includes(id) && icon && site) {
try { const image = await fetch(
if (icon) used.add(path.join(root, '..', 'icons', icon)); `https://www.google.com/s2/favicons?domain=${site}&sz=${size}&type=png`,
)
.then(res => res.arrayBuffer())
.then(res => Buffer.from(res));
if (!skip[id] && icon && site) { const notAvailableImage = fs.readFileSync(
const image = await fetch( path.join(root, 'scripts', 'notavailable.png'),
`https://www.google.com/s2/favicons?domain=${site}&sz=${size}&type=png`, );
)
.then(res => res.arrayBuffer())
.then(res => Buffer.from(res));
const fullPath = path.join(root, '..', 'icons', icon); if (Buffer.compare(image, notAvailableImage) === 0) {
const dir = fullPath.match(/^.*[\\\/]/)?.[0] || fullPath; console.log(
if (!fs.existsSync(dir)) { ' ',
fs.mkdirSync(dir, { recursive: true }); name.padEnd(26),
} `(${id})`.padEnd(20),
fs.writeFileSync(fullPath, image); 'Is site down?',
console.log(name, '✅'); '\r❌',
} else { );
console.log(name, '❌'); continue;
} }
} catch (err) {
console.log(name, '❌', err); fs.writeFileSync(icon, image);
console.log(' ', name.padEnd(26), `(${id})`, '\r✅');
} else {
console.log(' ', `Skipping ${name}`.padEnd(26), `(${id})`, '\r🔄');
} }
await delay(2500); } catch (err) {
console.log(
' ',
name.padEnd(26),
`(${id})`.padEnd(20),
err instanceof Error ? err.constructor.name : typeof err,
'\r❌',
);
console.log(err);
await new Promise(resolve => setTimeout(resolve, 2500));
} }
} }
console.log('\nDeleting unused icons ⌛'); console.log('\nDeleting unused icons ⌛');
@@ -88,7 +122,7 @@ used.add(path.join(root, '..', 'icons', 'coverNotAvailable.webp'));
}, []); }, []);
} }
fileList(path.join(root, '..', 'icons')).forEach(path => { fileList(path.join(root, 'icons')).forEach(path => {
if (!used.has(path)) { if (!used.has(path)) {
console.log('🗑️', path); console.log('🗑️', path);
fs.rmSync(path, { force: true }); fs.rmSync(path, { force: true });
Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B