+
-
-
\ No newline at end of file
+
diff --git a/src/pages/YMenu.vue b/src/pages/YMenu.vue
index f7c21107..5c7e7b32 100644
--- a/src/pages/YMenu.vue
+++ b/src/pages/YMenu.vue
@@ -1,13 +1,9 @@
-
-
-
\ No newline at end of file
diff --git a/src/pages/bangumi/components/AddBangumi.vue b/src/pages/bangumi/components/AddBangumi.vue
index 4c8cae35..dc65fef6 100644
--- a/src/pages/bangumi/components/AddBangumi.vue
+++ b/src/pages/bangumi/components/AddBangumi.vue
@@ -1,34 +1,28 @@
-
+
@@ -39,19 +33,13 @@ const add = async () => {
-
+
- 订阅
+ 订阅
-
-
\ No newline at end of file
+
diff --git a/src/pages/bangumi/components/BangumiData.vue b/src/pages/bangumi/components/BangumiData.vue
index 74c97d81..2c118588 100644
--- a/src/pages/bangumi/components/BangumiData.vue
+++ b/src/pages/bangumi/components/BangumiData.vue
@@ -1,76 +1,50 @@
-
+
-
-
-
- 注: 目前只能管理mikan源, 如通过api添加其他来源的新番将不过出现在此处
+
+
+ 注: 目前只能管理 mikan 源, 如通过 api 添加其他来源的新番将
+ 不会 出现在此处
-
-
-
-
-
+
+
+
+
+
-
-
\ No newline at end of file
+
diff --git a/src/pages/bangumi/index.vue b/src/pages/bangumi/index.vue
index b219e1c5..7d0f9974 100644
--- a/src/pages/bangumi/index.vue
+++ b/src/pages/bangumi/index.vue
@@ -1,6 +1,6 @@
-
@@ -14,7 +14,6 @@ import AddBangumi from './components/AddBangumi.vue'
-
@@ -26,15 +25,14 @@ import AddBangumi from './components/AddBangumi.vue'
-
-
\ No newline at end of file
+
diff --git a/src/pages/config/__test__/useConfigCheck.test.ts b/src/pages/config/__test__/useConfigCheck.test.ts
new file mode 100644
index 00000000..91bae0c3
--- /dev/null
+++ b/src/pages/config/__test__/useConfigCheck.test.ts
@@ -0,0 +1,26 @@
+import { checkHost, checkIp, checkPort } from '../useConfigCheck';
+
+describe('check methods', () => {
+ it('check ip', () => {
+ expect(checkIp('127.0.0.1')).toBe(true);
+ expect(checkIp('127.0.1')).toBe(false);
+ expect(checkIp('')).toBe(false);
+ });
+
+ it('check port', () => {
+ expect(checkPort(80)).toBe(true);
+ expect(checkPort(-1)).toBe(false);
+ expect(checkPort(70000)).toBe(false);
+ expect(checkPort()).toBe(false);
+ });
+
+ it('check host', () => {
+ expect(checkHost('127.0.0.1:2523')).toContainEqual(true);
+ expect(checkHost('127.0.0.1')).toContainEqual(false);
+ expect(checkHost('127.0.1:')).toContainEqual(false);
+ expect(checkHost(':2523')).toContainEqual(false);
+ expect(checkHost('127.0.0.1:70000')).toContainEqual(false);
+ expect(checkHost('dfajlskdfa0')).toContainEqual(false);
+ expect(checkHost('')).toContainEqual(false);
+ });
+});
diff --git a/src/pages/config/components/BangumiManageItem.vue b/src/pages/config/components/BangumiManageItem.vue
new file mode 100644
index 00000000..83530775
--- /dev/null
+++ b/src/pages/config/components/BangumiManageItem.vue
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/config/components/DownloaderItem.vue b/src/pages/config/components/DownloaderItem.vue
new file mode 100644
index 00000000..46bfbbe8
--- /dev/null
+++ b/src/pages/config/components/DownloaderItem.vue
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/config/components/LogItem.vue b/src/pages/config/components/LogItem.vue
new file mode 100644
index 00000000..d54f1fa8
--- /dev/null
+++ b/src/pages/config/components/LogItem.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/config/components/NotificationItem.vue b/src/pages/config/components/NotificationItem.vue
new file mode 100644
index 00000000..d8efd745
--- /dev/null
+++ b/src/pages/config/components/NotificationItem.vue
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/config/components/ProgramItem.vue b/src/pages/config/components/ProgramItem.vue
new file mode 100644
index 00000000..26761621
--- /dev/null
+++ b/src/pages/config/components/ProgramItem.vue
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/config/components/ProxyItem.vue b/src/pages/config/components/ProxyItem.vue
new file mode 100644
index 00000000..907825a1
--- /dev/null
+++ b/src/pages/config/components/ProxyItem.vue
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/config/components/RssParserItem.vue b/src/pages/config/components/RssParserItem.vue
new file mode 100644
index 00000000..21aa1872
--- /dev/null
+++ b/src/pages/config/components/RssParserItem.vue
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/config/form-data.ts b/src/pages/config/form-data.ts
new file mode 100644
index 00000000..ef5ec465
--- /dev/null
+++ b/src/pages/config/form-data.ts
@@ -0,0 +1,70 @@
+import type {
+ Config,
+ DownloaderType,
+ NotificationType,
+ ProxyType,
+ RenameMethod,
+ RssParserLang,
+ RssParserType,
+} from '#/config';
+
+export const form = reactive
({
+ data_version: 4,
+ program: {
+ sleep_time: 0,
+ rename_times: 0,
+ webui_port: 0,
+ },
+ downloader: {
+ type: 'qbittorrent',
+ host: '',
+ username: '',
+ password: '',
+ path: '',
+ ssl: false,
+ },
+ rss_parser: {
+ enable: true,
+ type: 'mikan',
+ token: '',
+ custom_url: '',
+ enable_tmdb: false,
+ filter: [],
+ language: 'zh',
+ },
+ bangumi_manage: {
+ enable: true,
+ eps_complete: true,
+ rename_method: 'normal',
+ group_tag: true,
+ remove_bad_torrent: true,
+ },
+ log: {
+ debug_enable: false,
+ },
+ proxy: {
+ enable: false,
+ type: 'http',
+ host: '',
+ port: 0,
+ username: '',
+ password: '',
+ },
+ notification: {
+ enable: false,
+ type: 'telegram',
+ token: '',
+ chat_id: '',
+ },
+});
+
+export const downloaderType: DownloaderType = ['qbittorrent'];
+export const rssParserType: RssParserType = ['mikan'];
+export const rssParserLang: RssParserLang = ['zh', 'en', 'jp'];
+export const renameMethod: RenameMethod = ['normal', 'pn', 'advance', 'none'];
+export const proxyType: ProxyType = ['http', 'https', 'socks5'];
+export const notificationType: NotificationType = ['telegram', 'server-chan'];
+export const tfOptions = [
+ { label: '是', value: true },
+ { label: '否', value: false },
+];
diff --git a/src/pages/config/index.vue b/src/pages/config/index.vue
new file mode 100644
index 00000000..1f49ab60
--- /dev/null
+++ b/src/pages/config/index.vue
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 保存
+ 还原
+
+
+
+
+
diff --git a/src/pages/config/useConfigCheck.ts b/src/pages/config/useConfigCheck.ts
new file mode 100644
index 00000000..8635f4d9
--- /dev/null
+++ b/src/pages/config/useConfigCheck.ts
@@ -0,0 +1,77 @@
+import { form } from './form-data';
+
+export function checkIp(ip: string) {
+ const check =
+ /^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/;
+
+ return check.test(ip);
+}
+
+/** 有效端口检测 */
+export function checkPort(port?: number) {
+ if (!port) return false;
+ if (port >= 0 && port <= 65535) return true;
+ else return false;
+}
+
+/** host 格式检测 */
+export function checkHost(host: string): [boolean, string] {
+ if (host === '') return [false, '请输入host'];
+ if (!/:/.test(host)) {
+ return [false, "缺少 ':'"];
+ } else {
+ const [ip, port] = host.split(':');
+
+ if (!checkIp(ip)) {
+ return [false, '请输入有效ip!'];
+ }
+
+ if (!checkPort(Number(port))) {
+ return [false, '请输入有效端口!'];
+ }
+ }
+
+ return [true, ''];
+}
+
+export function useConfigCheck() {
+ /** 端口验证 */
+ function validtePort(rule: any, value: any, callback: any) {
+ if (value === '') return callback(new Error('请输入端口号'));
+
+ if (!checkPort(value)) {
+ callback(new Error('无效端口 (端口范围 0 - 65535)'));
+ } else {
+ callback();
+ }
+ }
+
+ /** host 验证 */
+ function validteHost(rule: any, value: any, callback: any) {
+ const [c, m] = checkHost(value);
+ if (!c) return callback(new Error(m));
+ callback();
+ }
+
+ /** proxy 启用时检测 ip 和 端口 */
+ const validteFormProxy = {
+ ip(rule: any, value: any, callback: any) {
+ if (form.proxy.enable) {
+ if (!checkIp(value)) return callback(new Error('请输入有效ip!'));
+ }
+ callback();
+ },
+ port(rule: any, value: any, callback: any) {
+ if (form.proxy.enable) {
+ if (!checkPort(value)) return callback(new Error('请输入有效端口!'));
+ }
+ callback();
+ },
+ };
+
+ return {
+ validtePort,
+ validteHost,
+ validteFormProxy,
+ };
+}
diff --git a/src/pages/debug/index.vue b/src/pages/debug/index.vue
index 2f71dad1..9904595d 100644
--- a/src/pages/debug/index.vue
+++ b/src/pages/debug/index.vue
@@ -1,29 +1,55 @@
-
@@ -34,20 +60,31 @@ const reset = async () => {
- 重置
+ 重置
-
+
+
+
+
+
+
+
+
+ 重启
+
+
+
+
-
-
\ No newline at end of file
diff --git a/src/pages/journal/index.vue b/src/pages/journal/index.vue
index 5aaa368e..21694ace 100644
--- a/src/pages/journal/index.vue
+++ b/src/pages/journal/index.vue
@@ -1,41 +1,18 @@
-
-
{{ log }}
+
-
-
\ No newline at end of file
diff --git a/src/router/index.ts b/src/router/index.ts
index f817facc..327d9930 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -4,6 +4,7 @@ const YLayout = () => import('../pages/YLayout.vue');
const YBangumi = () => import('../pages/bangumi/index.vue');
const YDebug = () => import('../pages/debug/index.vue');
const YLog = () => import('../pages/journal/index.vue');
+const YConfig = () => import('../pages/config/index.vue');
const routes = [
{
@@ -13,23 +14,27 @@ const routes = [
children: [
{
path: 'bangumi',
- component: YBangumi
+ component: YBangumi,
},
{
path: 'debug',
- component: YDebug
+ component: YDebug,
},
{
path: 'log',
- component: YLog
- }
- ]
+ component: YLog,
+ },
+ {
+ path: 'config',
+ component: YConfig,
+ },
+ ],
},
-]
+];
const router = createRouter({
history: createWebHashHistory(),
routes,
-})
+});
-export default router;
\ No newline at end of file
+export default router;
diff --git a/src/store/bangumi.ts b/src/store/bangumi.ts
new file mode 100644
index 00000000..8771b21d
--- /dev/null
+++ b/src/store/bangumi.ts
@@ -0,0 +1,12 @@
+import { getABData } from '../api/bangumi';
+
+export const bangumiStore = defineStore('bangumi', () => {
+ const data = ref({ rss_link: '', data_version: 4, bangumi_info: [] });
+
+ const get = async () => {
+ const res = await getABData();
+ data.value = res.data;
+ };
+
+ return { data, get };
+});
diff --git a/src/store/config.ts b/src/store/config.ts
new file mode 100644
index 00000000..236ee851
--- /dev/null
+++ b/src/store/config.ts
@@ -0,0 +1,39 @@
+import { ElMessage } from 'element-plus';
+import { getConfig, setConfig } from '@/api/config';
+import type { Config } from '#/config';
+
+export const configStore = defineStore('config', () => {
+ const config = ref
();
+
+ const get = async () => {
+ config.value = await getConfig();
+ };
+
+ const set = async (newConfig: Omit) => {
+ let finalConfig: Config;
+ if (config.value !== undefined) {
+ finalConfig = Object.assign(config.value, newConfig);
+ const { message } = await setConfig(finalConfig);
+
+ if (message === 'Success') {
+ ElMessage({
+ message: '保存成功, 请重启容器以应用新的配置!',
+ type: 'success',
+ });
+ } else {
+ ElMessage({
+ message: '保存失败, 请重试!',
+ type: 'error',
+ });
+ }
+ }
+
+ return false;
+ };
+
+ return {
+ get,
+ set,
+ config,
+ };
+});
diff --git a/src/store/log.ts b/src/store/log.ts
new file mode 100644
index 00000000..96244b77
--- /dev/null
+++ b/src/store/log.ts
@@ -0,0 +1,25 @@
+import { getABLog } from '../api/debug';
+
+export const logStore = defineStore('log', () => {
+ const log = ref('');
+ const timer = ref(null);
+
+ const get = async () => {
+ log.value = await getABLog();
+ };
+
+ const onUpdate = () => {
+ timer.value = setInterval(() => get(), 3000);
+ };
+
+ const removeUpdate = () => {
+ clearInterval(Number(timer.value));
+ };
+
+ return {
+ log,
+ get,
+ onUpdate,
+ removeUpdate,
+ };
+});
diff --git a/src/store/program.ts b/src/store/program.ts
new file mode 100644
index 00000000..8282910a
--- /dev/null
+++ b/src/store/program.ts
@@ -0,0 +1,20 @@
+import { appStatus } from '../api/program';
+
+export const programStore = defineStore('program', () => {
+ const status = ref(false);
+ const timer = ref(null);
+
+ const getStatus = async () => {
+ status.value = await appStatus();
+ };
+
+ const onUpdate = () => {
+ timer.value = setInterval(() => getStatus(), 3000);
+ };
+
+ return {
+ status,
+ getStatus,
+ onUpdate,
+ };
+});
diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts
index 323c78a6..af36df34 100644
--- a/src/vite-env.d.ts
+++ b/src/vite-env.d.ts
@@ -1,7 +1,7 @@
///
declare module '*.vue' {
- import type { DefineComponent } from 'vue'
- const component: DefineComponent<{}, {}, any>
- export default component
+ import type { DefineComponent } from 'vue';
+ const component: DefineComponent<{}, {}, any>;
+ export default component;
}
diff --git a/tsconfig.json b/tsconfig.json
index 16888103..b26e902a 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -12,15 +12,20 @@
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
+ "noImplicitAny": false,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
- "#/*": ["src/types/*"]
+ "#/*": ["types/*"]
},
- "types": [
- "element-plus/global"
- ]
+ "types": ["element-plus/global"]
},
- "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
+ "include": [
+ "src/**/*.ts",
+ "src/**/*.d.ts",
+ "src/**/*.tsx",
+ "src/**/*.vue",
+ "types/config.ts"
+ ],
"references": [{ "path": "./tsconfig.node.json" }]
}
diff --git a/types/config.ts b/types/config.ts
new file mode 100644
index 00000000..44649ab6
--- /dev/null
+++ b/types/config.ts
@@ -0,0 +1,74 @@
+import type { UnionToTuple } from '#/utils';
+
+export interface Config {
+ data_version: 4;
+ program: {
+ sleep_time: number;
+ rename_times: number;
+ webui_port: number;
+ };
+ downloader: {
+ type: 'qbittorrent';
+ host: string;
+ username: string;
+ password: string;
+ path: string;
+ ssl: boolean;
+ };
+ rss_parser: {
+ enable: boolean;
+ type: 'mikan';
+ token: string;
+ custom_url: string;
+ enable_tmdb: boolean;
+ filter: Array;
+ language: 'zh' | 'en' | 'jp';
+ };
+ bangumi_manage: {
+ enable: boolean;
+ eps_complete: boolean;
+ rename_method: 'normal' | 'pn' | 'advance' | 'none';
+ group_tag: boolean;
+ remove_bad_torrent: boolean;
+ };
+ log: {
+ debug_enable: boolean;
+ };
+ proxy: {
+ enable: boolean;
+ type: 'http' | 'https' | 'socks5';
+ host: string;
+ port: number;
+ username: string;
+ password: string;
+ };
+ notification: {
+ enable: boolean;
+ type: 'telegram' | 'server-chan';
+ token: string;
+ chat_id: string;
+ };
+}
+
+type getItem = Pick[T];
+
+export type Program = getItem<'program'>;
+export type Downloader = getItem<'downloader'>;
+export type RssParser = getItem<'rss_parser'>;
+export type BangumiManage = getItem<'bangumi_manage'>;
+export type Log = getItem<'log'>;
+export type Proxy = getItem<'proxy'>;
+export type Notification = getItem<'notification'>;
+
+/** 下载方式 */
+export type DownloaderType = UnionToTuple;
+/** rss parser 源 */
+export type RssParserType = UnionToTuple;
+/** rss parser 语言 */
+export type RssParserLang = UnionToTuple;
+/** 重命名方式 */
+export type RenameMethod = UnionToTuple;
+/** 代理类型 */
+export type ProxyType = UnionToTuple;
+/** 通知类型 */
+export type NotificationType = UnionToTuple;
diff --git a/types/utils.ts b/types/utils.ts
new file mode 100644
index 00000000..c9c2ab8a
--- /dev/null
+++ b/types/utils.ts
@@ -0,0 +1,39 @@
+/**
+ * 将联合类型转为对应的交叉函数类型
+ * @template U 联合类型
+ */
+export type UnionToInterFunction = (
+ U extends any ? (k: () => U) => void : never
+) extends (k: infer I) => void
+ ? I
+ : never;
+
+/**
+ * 获取联合类型中的最后一个类型
+ * @template U 联合类型
+ */
+export type GetUnionLast = UnionToInterFunction extends { (): infer A }
+ ? A
+ : never;
+
+/**
+ * 在元组类型中前置插入一个新的类型(元素);
+ * @template Tuple 元组类型
+ * @template E 新的类型
+ */
+export type Prepend = [E, ...Tuple];
+
+/**
+ * 联合类型转元组类型;
+ * @template Union 联合类型
+ * @template T 初始元组类型
+ * @template Last 传入联合类型中的最后一个类型(元素),自动生成,内部使用
+ */
+export type UnionToTuple<
+ Union,
+ T extends any[] = [],
+ Last = GetUnionLast
+> = {
+ 0: T;
+ 1: UnionToTuple, Prepend>;
+}[[Union] extends [never] ? 0 : 1];
diff --git a/unocss.config.ts b/unocss.config.ts
new file mode 100644
index 00000000..58c77b7a
--- /dev/null
+++ b/unocss.config.ts
@@ -0,0 +1,17 @@
+import {
+ defineConfig,
+ presetAttributify,
+ presetIcons,
+ presetUno,
+} from 'unocss';
+import presetRemToPx from '@unocss/preset-rem-to-px';
+
+export default defineConfig({
+ presets: [
+ presetUno(),
+ presetRemToPx(),
+ presetAttributify(),
+ presetIcons({ cdn: 'https://esm.sh/' }),
+ ],
+ shortcuts: [[/^wh-(.*)$/, ([, t]) => `w-${t} h-${t}`]],
+});
diff --git a/vite.config.ts b/vite.config.ts
index cba72217..66bf709d 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,32 +1,41 @@
-import { defineConfig } from 'vite'
-import vue from '@vitejs/plugin-vue'
-import { resolve } from 'path';
-import AutoImport from 'unplugin-auto-import/vite'
-import Components from 'unplugin-vue-components/vite'
-import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
+import { resolve } from 'node:path';
+import UnoCSS from 'unocss/vite';
+import { defineConfig } from 'vite';
+import vue from '@vitejs/plugin-vue';
+import AutoImport from 'unplugin-auto-import/vite';
+import Components from 'unplugin-vue-components/vite';
+import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [
vue(),
+ UnoCSS(),
AutoImport({
+ imports: ['vue', 'vue-router', 'vitest', 'pinia'],
+ dts: 'src/auto-imports.d.ts',
resolvers: [ElementPlusResolver()],
+ dirs: ['src/store', 'src/hooks'],
}),
Components({
+ dts: 'src/components.d.ts',
resolvers: [ElementPlusResolver()],
}),
],
+ build: {
+ cssCodeSplit: false,
+ },
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
- '#': resolve(__dirname, 'types')
- }
+ '#': resolve(__dirname, 'types'),
+ },
},
server: {
host: '0.0.0.0',
proxy: {
- '/api': 'http://192.168.0.2:7892'
- }
- }
-})
+ '^/api/.*': 'http://127.0.0.1:7892',
+ },
+ },
+});