Add port setting

This commit is contained in:
2023-05-30 10:44:38 +08:00
parent 1c07fe9dc1
commit 935cf97d57
7 changed files with 21 additions and 4 deletions

View File

@@ -13,5 +13,6 @@
"db_path": "./downloads", "db_path": "./downloads",
"max_retry_count": 3, "max_retry_count": 3,
"max_download_img_count": 3, "max_download_img_count": 3,
"download_original_img": true "download_original_img": true,
"port": 8000
} }

View File

@@ -12,6 +12,7 @@ export type ConfigType = {
max_retry_count: number; max_retry_count: number;
max_download_img_count: number; max_download_img_count: number;
download_original_img: boolean; download_original_img: boolean;
port: number;
}; };
export class Config { export class Config {
@@ -85,6 +86,9 @@ export class Config {
get download_original_img() { get download_original_img() {
return this._return_bool("download_original_img") || false; return this._return_bool("download_original_img") || false;
} }
get port() {
return this._return_number("port") || 8000;
}
to_json(): ConfigType { to_json(): ConfigType {
return { return {
cookies: typeof this.cookies === "string", cookies: typeof this.cookies === "string",
@@ -97,6 +101,7 @@ export class Config {
max_retry_count: this.max_retry_count, max_retry_count: this.max_retry_count,
max_download_img_count: this.max_download_img_count, max_download_img_count: this.max_download_img_count,
download_original_img: this.download_original_img, download_original_img: this.download_original_img,
port: this.port,
}; };
} }
} }

View File

@@ -178,6 +178,14 @@ export default class Settings extends Component<SettingsProps> {
description={t("settings.db_path")} description={t("settings.db_path")}
helpertext={t("settings.db_path_help")} helpertext={t("settings.db_path_help")}
/> />
<SettingsText
name="port"
value={settings.port}
description={t("settings.port")}
type="number"
min={0}
max={65535}
/>
</SettingsContext> </SettingsContext>
<Button onClick={loadData}>{t("common.reload")}</Button> <Button onClick={loadData}>{t("common.reload")}</Button>
<Button onClick={showDlg} disabled={disabled}> <Button onClick={showDlg} disabled={disabled}>

View File

@@ -2,7 +2,7 @@ import { Handlers } from "$fresh/server.ts";
import { ConfigType, load_settings, save_settings } from "../../config.ts"; import { ConfigType, load_settings, save_settings } from "../../config.ts";
import { get_cfg_path, get_task_manager } from "../../server.ts"; import { get_cfg_path, get_task_manager } from "../../server.ts";
const UNSAFE_TYPE: (keyof ConfigType)[] = ["base", "db_path"]; const UNSAFE_TYPE: (keyof ConfigType)[] = ["base", "db_path", "port"];
const UNSAFE_TYPE2 = UNSAFE_TYPE as string[]; const UNSAFE_TYPE2 = UNSAFE_TYPE as string[];
export const handler: Handlers = { export const handler: Handlers = {

View File

@@ -35,5 +35,6 @@ export async function startServer(path: string) {
signal: task_manager.aborts, signal: task_manager.aborts,
plugins: [twindPlugin(twindConfig)], plugins: [twindPlugin(twindConfig)],
render: renderFn, render: renderFn,
port: cfg.port,
}); });
} }

View File

@@ -17,5 +17,6 @@
"max_download_img_count": "Maximum number of parallel downloads of images: ", "max_download_img_count": "Maximum number of parallel downloads of images: ",
"save_dlg": "Do you want to save settings?", "save_dlg": "Do you want to save settings?",
"db_path": "The folder where the database is stored: ", "db_path": "The folder where the database is stored: ",
"db_path_help": "If not set, the download location is used." "db_path_help": "If not set, the download location is used.",
"port": "Listening port: "
} }

View File

@@ -17,5 +17,6 @@
"max_download_img_count": "最大图片并行下载数:", "max_download_img_count": "最大图片并行下载数:",
"save_dlg": "是否保存设置?", "save_dlg": "是否保存设置?",
"db_path": "存放数据库的文件夹位置:", "db_path": "存放数据库的文件夹位置:",
"db_path_help": "如果未设置,将使用下载位置。" "db_path_help": "如果未设置,将使用下载位置。",
"port": "监听端口:"
} }