diff --git a/src/api/types.ts b/src/api/types.ts index e4782402..57cc4990 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -268,6 +268,64 @@ export interface TransferHistory { src_fileitem?: FileItem } +// 下载历史记录 +export interface DownloadHistory { + // ID + id: number + // 保存路径 + path?: string + // 类型:电影、电视剧 + type?: string + // 标题 + title?: string + // 年份 + year?: string + // TMDB ID + tmdbid?: number + // IMDB ID + imdbid?: string + // TVDB ID + tvdbid?: number + // 豆瓣 ID + doubanid?: string + // Bangumi ID + bangumiid?: number + // AniList ID + anilistid?: number + // 媒体数据源 + media_source?: MediaDataSource + // 数据源原生 ID + media_id?: string + // 季 Sxx + seasons?: string + // 集 Exx + episodes?: string + // 海报或背景图 + image?: string + // 下载器 Hash + download_hash?: string + // 种子名称 + torrent_name?: string + // 种子描述 + torrent_description?: string + // 站点 + torrent_site?: string + // 下载用户 ID + userid?: string + // 下载用户名或插件名 + username?: string + // 下载渠道 + channel?: string + // 创建时间 + date?: string + // 附加信息 + note?: unknown + // 自定义媒体类别 + media_category?: string + // 自定义剧集组 + episode_group?: string +} + // 媒体信息 export interface MediaInfo { // 来源:themoviedb、douban、bangumi、anilist diff --git a/src/components/dialog/DownloadHistoryDialog.vue b/src/components/dialog/DownloadHistoryDialog.vue new file mode 100644 index 00000000..7c75bb29 --- /dev/null +++ b/src/components/dialog/DownloadHistoryDialog.vue @@ -0,0 +1,271 @@ + + + diff --git a/tests/support/msw/handlers/download.ts b/tests/support/msw/handlers/download.ts index ac0d0286..332b8f5c 100644 --- a/tests/support/msw/handlers/download.ts +++ b/tests/support/msw/handlers/download.ts @@ -1,4 +1,4 @@ -import type { DownloadingInfo } from '@/api/types' +import type { DownloadHistory, DownloadingInfo } from '@/api/types' import { HttpResponse, http, type JsonBodyType } from 'msw' const API_BASE_URL = 'http://localhost/api/v1/' @@ -12,6 +12,7 @@ export const downloadApiUrls = { action: (operation: 'start' | 'stop', hash: string) => new URL(`download/${operation}/${hash}`, API_BASE_URL).href, delete: (hash: string) => new URL(`download/${hash}`, API_BASE_URL).href, list: new URL('download/', API_BASE_URL).href, + history: new URL('history/download', API_BASE_URL).href, } function jsonResponse(body: JsonBodyType, status: number) { @@ -60,3 +61,29 @@ export function deleteDownloadHandler( return jsonResponse(response, status) }) } + +/** 拦截下载历史分页查询,并保留分页参数供断言。 */ +export function downloadHistoryHandler( + response: DownloadHistory[] | ((url: URL) => DownloadHistory[] | Promise) = [], + status = 200, + onRequest: (url: URL) => void | Promise = () => {}, +) { + return http.get(downloadApiUrls.history, async ({ request }) => { + const url = new URL(request.url) + await onRequest(url) + const body = typeof response === 'function' ? await response(url) : response + return jsonResponse(body as unknown as JsonBodyType, status) + }) +} + +/** 拦截下载历史删除请求,并保留请求体供断言。 */ +export function deleteDownloadHistoryHandler( + response: DownloadMutationResponse = { success: true }, + status = 200, + onRequest: (body: DownloadHistory) => void | Promise = () => {}, +) { + return http.delete(downloadApiUrls.history, async ({ request }) => { + await onRequest((await request.json()) as DownloadHistory) + return jsonResponse(response, status) + }) +}