import { readFileSync, writeFileSync } from "fs"; import { resolve } from "path"; import input from "@inquirer/input"; import select from "@inquirer/select"; import logger from "../utils/logger"; export interface SettingConfig { download_router: | "https://i1.nhentai.net/galleries/" | "https://i2.nhentai.net/galleries/" | "https://i3.nhentai.net/galleries/"; download_path: string; couldflare_bypass: boolean; retryLimit: number; concurrency: number; } export const getSettingConfig = () => { const data = JSON.parse(readFileSync(resolve("settings.config.json"), "utf-8")) as SettingConfig; if ( data.download_router != "https://i1.nhentai.net/galleries/" && data.download_router != "https://i2.nhentai.net/galleries/" && data.download_router != "https://i3.nhentai.net/galleries/" ) { throw new Error(`you setting config download router wrong, ${data.download_router} is not exit in nhentai api!`); } return data; }; export const changeSettingConfig = async () => { const data = JSON.parse(readFileSync(resolve("settings.config.json"), "utf-8")) as SettingConfig; data.download_router = await select({ message: "choice nhentai download router:", choices: [ { name: "i1.nhentai", value: "https://i1.nhentai.net/galleries/", }, { name: "i2.nhentai", value: "https://i2.nhentai.net/galleries/", }, { name: "i3.nhentai", value: "https://i3.nhentai.net/galleries/", }, ], default: data.download_router, }); data.download_path = await input({ message: "the path of download comic you want to save:", required: true, default: data.download_path, }); writeFileSync(resolve("settings.config.json"), JSON.stringify(data, null, 2), "utf-8"); logger.info("update settings config success!!"); };