Skip to content

Commit

Permalink
fix: some eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ltaoo committed Aug 26, 2023
1 parent 69bbbeb commit 249d40e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
15 changes: 13 additions & 2 deletions src/domains/list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { OriginalResponse, FetchParams, Response, Search, ParamsProcessor, ListP
* @returns
*/
const RESPONSE_PROCESSOR = <T>(
originalResponse: OriginalResponse
originalResponse: OriginalResponse | null
): {
dataSource: T[];
page: number;
Expand All @@ -27,6 +27,17 @@ const RESPONSE_PROCESSOR = <T>(
noMore: boolean;
error: Error | null;
} => {
if (originalResponse === null) {
return {
dataSource: [],
page: 1,
pageSize: DEFAULT_PAGE_SIZE,
total: DEFAULT_TOTAL,
noMore: false,
empty: false,
error: new Error(`process response fail, because response is null`),
};
}
try {
const data = (() => {
if (originalResponse.data) {
Expand Down Expand Up @@ -125,7 +136,7 @@ export class ListCore<
return { ...prevParams, ...currentParams };
};
/** 响应处理器 */
private processor: (response: OriginalResponse) => Response<T>;
private processor: (response: OriginalResponse | null) => Response<T>;
/** 初始查询参数 */
private initialParams: FetchParams;
private extraResponse: Record<string, unknown>;
Expand Down
2 changes: 1 addition & 1 deletion src/domains/list/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export interface ListProps<T> {
* 响应处理器
* 建议在 service 函数中直接处理
*/
processor?: <T>(response: Response<T>, originalResponse: OriginalResponse) => Response<T>;
processor?: <T>(response: Response<T>, originalResponse: OriginalResponse | null) => Response<T>;
/**
* 默认已存在的数据
*/
Expand Down
46 changes: 22 additions & 24 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,28 @@ export async function fetch_partial_tv(params: { tv_id: string }) {
*/
export async function fetch_partial_season(params: { season_id: string }) {
const { season_id } = params;
const resp = await request.get<
ListResponse<{
id: string;
tv_id: string;
name: string;
original_name: string;
overview: string;
poster_path: string;
season_text: string;
first_air_date: string;
popularity: string;
episode_count: number;
season_count: number;
cur_episode_count: number;
cur_season_count: number;
episode_sources: number;
size_count: number;
size_count_text: string;
incomplete: boolean;
need_bind: boolean;
sync_task: { id: string } | null;
tips: string[];
}>
>(`/api/admin/season/${season_id}/partial`);
const resp = await request.get<{
id: string;
tv_id: string;
name: string;
original_name: string;
overview: string;
poster_path: string;
season_text: string;
first_air_date: string;
popularity: string;
episode_count: number;
season_count: number;
cur_episode_count: number;
cur_season_count: number;
episode_sources: number;
size_count: number;
size_count_text: string;
incomplete: boolean;
need_bind: boolean;
sync_task: { id: string } | null;
tips: string[];
}>(`/api/admin/season/${season_id}/partial`);
if (resp.error) {
return resp;
}
Expand Down
23 changes: 5 additions & 18 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,7 @@ import { cn as nzhcn } from "./nzh";
dayjs.extend(relative_time);
dayjs.locale("zh-cn");

export const VIDEO_KEYS_MAP = {
name: "",
original_name: "",
season: "",
episode: "",
episode_name: "",
resolution: "",
year: "",
source: "",
encode: "",
voice_encode: "",
episode_count: "",
type: "",
};
export type VideoKeys = keyof typeof VIDEO_KEYS_MAP;
export const VIDEO_ALL_KEYS = Object.keys(VIDEO_KEYS_MAP) as VideoKeys[];
export type ParsedVideoInfo = Record<VideoKeys, string>;
export const VIDEO_KEY_NAME_MAP: Record<VideoKeys, string> = {
export const VIDEO_KEY_NAME_MAP = {
name: "中文名称",
original_name: "译名or外文原名",
season: "季",
Expand All @@ -38,7 +21,11 @@ export const VIDEO_KEY_NAME_MAP: Record<VideoKeys, string> = {
voice_encode: "音频编码方式",
episode_count: "总集数",
type: "后缀",
subtitle_lang: "字幕语言",
};
export type VideoKeys = keyof typeof VIDEO_KEY_NAME_MAP;
export const VIDEO_ALL_KEYS = Object.keys(VIDEO_KEY_NAME_MAP) as VideoKeys[];
export type ParsedVideoInfo = Record<VideoKeys, string>;

export function cn(...inputs: any[]) {
return twMerge(inputs);
Expand Down

0 comments on commit 249d40e

Please sign in to comment.