This commit is contained in:
Patrick Alvin Alcala 2026-03-26 19:08:50 +08:00
parent 82a0fd6eea
commit 4fadb54891
24 changed files with 58 additions and 84 deletions

View file

@ -1,17 +0,0 @@
import { JSEncrypt } from "jsencrypt";
import * as fs from "node:fs";
import * as toml from "toml";
const config = toml.parse(
fs.readFileSync("configs/config.security.toml", "utf-8"),
);
const enc = new JSEncrypt();
const PUBLIC_KEY = config.rsa.public_key;
export default (message: string) => {
enc.setPublicKey(PUBLIC_KEY);
const encrypted = enc.encrypt(message).toString();
const fixedEncrypted = encrypted.replace(/\//g, "~");
return fixedEncrypted;
};

View file

@ -1,47 +1,39 @@
import { consola } from "consola";
import process from "node:process";
import sharp from "sharp";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { consola } from 'consola'
import process from 'node:process'
import sharp from 'sharp'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
;(async () => {
const argv = yargs(hideBin(process.argv))
.option('name', {
alias: 'n',
describe: 'Specify the name of the image',
type: 'string',
demandOption: true,
})
.option('size', {
alias: 's',
describe: 'Specify the size of the image',
type: 'number',
demandOption: true,
}).argv
(async () => {
const argv = yargs(hideBin(process.argv))
.option("name", {
alias: "n",
describe: "Specify the name of the image",
type: "string",
demandOption: true,
})
.option("size", {
alias: "s",
describe: "Specify the size of the image",
type: "number",
demandOption: true,
}).argv;
const name = argv.name
const size = argv.size
const name = argv.name;
const size = argv.size;
try {
const avifOutputPath = `./@dasig/images/${name.toString().split('.').slice(0, -1).join('.')}.avif`
const webpOutputPath = `./@dasig/images/${name.toString().split('.').slice(0, -1).join('.')}.webp`
try {
const avifOutputPath = `./@dasig/images/${name.toString().split(".").slice(0, -1).join(".")}.avif`;
const webpOutputPath = `./@dasig/images/${name.toString().split(".").slice(0, -1).join(".")}.webp`;
const avifBuffer = await sharp(`./src/images/${name}.png`).avif({ quality: 60 }).resize(size).toBuffer()
await sharp(avifBuffer).toFile(avifOutputPath)
consola.success(`${name} successfully optimized in Avif`)
const avifBuffer = await sharp(`./src/images/${name}`)
.avif({ quality: 60 })
.resize(size)
.toBuffer();
await sharp(avifBuffer).toFile(avifOutputPath);
consola.success(`${name} successfully optimized in Avif`);
const webpBuffer = await sharp(`./src/images/${name}`)
.webp({ quality: 75 })
.resize(size)
.toBuffer();
await sharp(webpBuffer).toFile(webpOutputPath);
consola.success(`${name} successfully optimized in Webp`);
} catch (error: any) {
consola.error("Error optimizing image:", error);
if (error.message.includes("missing"))
consola.error(`${name} could not be found on image folder`);
}
})();
const webpBuffer = await sharp(`./src/images/${name}.png`).webp({ quality: 75 }).resize(size).toBuffer()
await sharp(webpBuffer).toFile(webpOutputPath)
consola.success(`${name} successfully optimized in Webp`)
} catch (error: any) {
consola.error('Error optimizing image:', error)
if (error.message.includes('missing')) consola.error(`${name} could not be found on image folder`)
}
})()