mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-09 05:29:51 +08:00
fix: type error
This commit is contained in:
@@ -7,7 +7,6 @@ const { getSettingGroup } = useConfigStore();
|
||||
|
||||
const parser = getSettingGroup('rss_parser');
|
||||
|
||||
/** @ts-expect-error Incorrect order */
|
||||
const langs: RssParserLang = ['zh', 'en', 'jp'];
|
||||
|
||||
const items: SettingItem<RssParser>[] = [
|
||||
|
||||
@@ -1,62 +1,91 @@
|
||||
import type { UnionToTuple } from '#/utils';
|
||||
import type { TupleToUnion } from './utils';
|
||||
|
||||
/** 下载方式 */
|
||||
export type DownloaderType = ['qbittorrent'];
|
||||
/** rss parser 源 */
|
||||
export type RssParserType = ['mikan'];
|
||||
/** rss parser 方法 */
|
||||
export type RssParserMethodType = ['tmdb', 'mikan', 'parser'];
|
||||
/** rss parser 语言 */
|
||||
export type RssParserLang = ['zh', 'en', 'jp'];
|
||||
/** 重命名方式 */
|
||||
export type RenameMethod = ['normal', 'pn', 'advance', 'none'];
|
||||
/** 代理类型 */
|
||||
export type ProxyType = ['http', 'https', 'socks5'];
|
||||
/** 通知类型 */
|
||||
export type NotificationType = ['telegram', 'server-chan', 'bark', 'wecom'];
|
||||
/** OpenAI Model List */
|
||||
export type OpenAIModel = ['gpt-3.5-turbo'];
|
||||
/** OpenAI API Type */
|
||||
export type OpenAIType = ['openai', 'azure'];
|
||||
|
||||
export interface Program {
|
||||
rss_time: number;
|
||||
rename_time: number;
|
||||
webui_port: number;
|
||||
}
|
||||
|
||||
export interface Downloader {
|
||||
type: TupleToUnion<DownloaderType>;
|
||||
host: string;
|
||||
username: string;
|
||||
password: string;
|
||||
path: string;
|
||||
ssl: boolean;
|
||||
}
|
||||
export interface RssParser {
|
||||
enable: boolean;
|
||||
type: TupleToUnion<RssParserType>;
|
||||
token: string;
|
||||
custom_url: string;
|
||||
filter: Array<string>;
|
||||
language: TupleToUnion<RssParserLang>;
|
||||
parser_type: TupleToUnion<RssParserMethodType>;
|
||||
}
|
||||
export interface BangumiManage {
|
||||
enable: boolean;
|
||||
eps_complete: boolean;
|
||||
rename_method: TupleToUnion<RenameMethod>;
|
||||
group_tag: boolean;
|
||||
remove_bad_torrent: boolean;
|
||||
}
|
||||
export interface Log {
|
||||
debug_enable: boolean;
|
||||
}
|
||||
export interface Proxy {
|
||||
enable: boolean;
|
||||
type: TupleToUnion<ProxyType>;
|
||||
host: string;
|
||||
port: number;
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
export interface Notification {
|
||||
enable: boolean;
|
||||
type: 'telegram' | 'server-chan' | 'bark' | 'wecom';
|
||||
token: string;
|
||||
chat_id: string;
|
||||
}
|
||||
export interface ExperimentalOpenAI {
|
||||
enable: boolean;
|
||||
api_key: string;
|
||||
api_base: string;
|
||||
model: TupleToUnion<OpenAIModel>;
|
||||
// azure
|
||||
api_type: TupleToUnion<OpenAIType>;
|
||||
api_version?: string;
|
||||
deployment_id?: string;
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
program: {
|
||||
rss_time: number;
|
||||
rename_time: 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;
|
||||
filter: Array<string>;
|
||||
language: 'zh' | 'en' | 'jp';
|
||||
parser_type: 'tmdb' | 'mikan' | 'parser';
|
||||
};
|
||||
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' | 'bark' | 'wecom';
|
||||
token: string;
|
||||
chat_id: string;
|
||||
};
|
||||
experimental_openai: {
|
||||
enable: boolean;
|
||||
api_key: string;
|
||||
api_base: string;
|
||||
model: 'gpt-3.5-turbo';
|
||||
// azure
|
||||
api_type: 'openai' | 'azure';
|
||||
api_version?: string;
|
||||
deployment_id?: string;
|
||||
};
|
||||
program: Program;
|
||||
downloader: Downloader;
|
||||
rss_parser: RssParser;
|
||||
bangumi_manage: BangumiManage;
|
||||
log: Log;
|
||||
proxy: Proxy;
|
||||
notification: Notification;
|
||||
experimental_openai: ExperimentalOpenAI;
|
||||
}
|
||||
|
||||
export const initConfig: Config = {
|
||||
@@ -117,33 +146,3 @@ export const initConfig: Config = {
|
||||
deployment_id: '',
|
||||
},
|
||||
};
|
||||
|
||||
type getItem<T extends keyof Config> = Pick<Config, T>[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 ExperimentalOpenAI = getItem<'experimental_openai'>;
|
||||
|
||||
/** 下载方式 */
|
||||
export type DownloaderType = UnionToTuple<Downloader['type']>;
|
||||
/** rss parser 源 */
|
||||
export type RssParserType = UnionToTuple<RssParser['type']>;
|
||||
/** rss parser 方法 */
|
||||
export type RssParserMethodType = UnionToTuple<RssParser['parser_type']>;
|
||||
/** rss parser 语言 */
|
||||
export type RssParserLang = UnionToTuple<RssParser['language']>;
|
||||
/** 重命名方式 */
|
||||
export type RenameMethod = UnionToTuple<BangumiManage['rename_method']>;
|
||||
/** 代理类型 */
|
||||
export type ProxyType = UnionToTuple<Proxy['type']>;
|
||||
/** 通知类型 */
|
||||
export type NotificationType = UnionToTuple<Notification['type']>;
|
||||
/** OpenAI Model List */
|
||||
export type OpenAIModel = UnionToTuple<ExperimentalOpenAI['model']>;
|
||||
/** OpenAI API Type */
|
||||
export type OpenAIType = UnionToTuple<ExperimentalOpenAI['api_type']>;
|
||||
|
||||
@@ -1,39 +1 @@
|
||||
/**
|
||||
* 将联合类型转为对应的交叉函数类型
|
||||
* @template U 联合类型
|
||||
*/
|
||||
export type UnionToInterFunction<U> = (
|
||||
U extends any ? (k: () => U) => void : never
|
||||
) extends (k: infer I) => void
|
||||
? I
|
||||
: never;
|
||||
|
||||
/**
|
||||
* 获取联合类型中的最后一个类型
|
||||
* @template U 联合类型
|
||||
*/
|
||||
export type GetUnionLast<U> = UnionToInterFunction<U> extends { (): infer A }
|
||||
? A
|
||||
: never;
|
||||
|
||||
/**
|
||||
* 在元组类型中前置插入一个新的类型(元素);
|
||||
* @template Tuple 元组类型
|
||||
* @template E 新的类型
|
||||
*/
|
||||
export type Prepend<Tuple extends any[], E> = [E, ...Tuple];
|
||||
|
||||
/**
|
||||
* 联合类型转元组类型;
|
||||
* @template Union 联合类型
|
||||
* @template T 初始元组类型
|
||||
* @template Last 传入联合类型中的最后一个类型(元素),自动生成,内部使用
|
||||
*/
|
||||
export type UnionToTuple<
|
||||
Union,
|
||||
T extends any[] = [],
|
||||
Last = GetUnionLast<Union>
|
||||
> = {
|
||||
0: T;
|
||||
1: UnionToTuple<Exclude<Union, Last>, Prepend<T, Last>>;
|
||||
}[[Union] extends [never] ? 0 : 1];
|
||||
export type TupleToUnion<T extends any[]> = T[number];
|
||||
|
||||
Reference in New Issue
Block a user