diff --git a/src/common/types/download_list.d.ts b/src/common/types/download_list.d.ts index ed969835..5633972e 100644 --- a/src/common/types/download_list.d.ts +++ b/src/common/types/download_list.d.ts @@ -1,66 +1,69 @@ +import { type Message } from '@/lang' // interface DownloadList { // } -declare namespace LX { - namespace Download { - type DownloadTaskStatus = 'run' - | 'waiting' - | 'pause' - | 'error' - | 'completed' +declare global { + namespace LX { + namespace Download { + type DownloadTaskStatus = 'run' + | 'waiting' + | 'pause' + | 'error' + | 'completed' - type FileExt = 'mp3' | 'flac' | 'wav' | 'ape' + type FileExt = 'mp3' | 'flac' | 'wav' | 'ape' - interface ProgressInfo { - progress: number - speed: string - downloaded: number - total: number - } - - interface DownloadTaskActionBase { - action: A - } - interface DownloadTaskActionData extends DownloadTaskActionBase { - data: D - } - type DownloadTaskAction = D extends undefined ? DownloadTaskActionBase : DownloadTaskActionData - - type DownloadTaskActions = DownloadTaskAction<'start'> - | DownloadTaskAction<'complete'> - | DownloadTaskAction<'refreshUrl'> - | DownloadTaskAction<'statusText', string> - | DownloadTaskAction<'progress', ProgressInfo> - | DownloadTaskAction<'error', { - error?: string - message?: string - }> - - interface ListItem { - id: string - isComplate: boolean - status: DownloadTaskStatus - statusText: string - downloaded: number - total: number - progress: number - speed: string - metadata: { - musicInfo: LX.Music.MusicInfoOnline - url: string | null - quality: LX.Quality - ext: FileExt - fileName: string - filePath: string + interface ProgressInfo { + progress: number + speed: string + downloaded: number + total: number } - } - interface saveDownloadMusicInfo { - list: ListItem[] - addMusicLocationType: LX.AddMusicLocationType + interface DownloadTaskActionBase { + action: A + } + interface DownloadTaskActionData extends DownloadTaskActionBase { + data: D + } + type DownloadTaskAction = D extends undefined ? DownloadTaskActionBase : DownloadTaskActionData + + type DownloadTaskActions = DownloadTaskAction<'start'> + | DownloadTaskAction<'complete'> + | DownloadTaskAction<'refreshUrl'> + | DownloadTaskAction<'statusText', string> + | DownloadTaskAction<'progress', ProgressInfo> + | DownloadTaskAction<'error', { + error?: keyof Message + message?: string + }> + + interface ListItem { + id: string + isComplate: boolean + status: DownloadTaskStatus + statusText: string + downloaded: number + total: number + progress: number + speed: string + metadata: { + musicInfo: LX.Music.MusicInfoOnline + url: string | null + quality: LX.Quality + ext: FileExt + fileName: string + filePath: string + } + } + + interface saveDownloadMusicInfo { + list: ListItem[] + addMusicLocationType: LX.AddMusicLocationType + } } } } diff --git a/src/lang/en-us.json b/src/lang/en-us.json index e911d455..3c85bfb1 100644 --- a/src/lang/en-us.json +++ b/src/lang/en-us.json @@ -64,6 +64,7 @@ "download_status_error_check_path": "There is an error in checking the download path, please check whether the set download directory is normal", "download_status_error_check_path_exist": "A file with the same name exists, skip download", "download_status_error_refresh_url": "Link is dead, link is being refreshed", + "download_status_error_response": "download failed:", "download_status_error_url_failed": "Failed to get music link", "download_status_error_write": "The song save location is occupied or does not have write permission, please try to change the song save directory or restart the software or restart the computer, the error details:", "download_status_start": "start download", diff --git a/src/lang/zh-cn.json b/src/lang/zh-cn.json index 7f69236d..4e9236b1 100644 --- a/src/lang/zh-cn.json +++ b/src/lang/zh-cn.json @@ -64,6 +64,7 @@ "download_status_error_check_path": "检查下载路径出错,请检查设置的下载目录是否正常", "download_status_error_check_path_exist": "存在同名文件,跳过下载", "download_status_error_refresh_url": "链接失效,正在刷新链接", + "download_status_error_response": "下载失败:", "download_status_error_url_failed": "获取音乐链接失败", "download_status_error_write": "歌曲保存位置被占用或没有写入权限,请尝试更改歌曲保存目录或重启软件或重启电脑,错误详情:", "download_status_start": "开始下载", diff --git a/src/lang/zh-tw.json b/src/lang/zh-tw.json index bd649852..bcec5dcd 100644 --- a/src/lang/zh-tw.json +++ b/src/lang/zh-tw.json @@ -64,6 +64,7 @@ "download_status_error_check_path": "檢查下載路徑出錯,請檢查設置的下載目錄是否正常", "download_status_error_check_path_exist": "存在同名文件,跳過下載", "download_status_error_refresh_url": "鏈接失效,正在刷新鏈接", + "download_status_error_response": "下載失敗:", "download_status_error_url_failed": "獲取音樂鏈接失敗", "download_status_error_write": "歌曲保存位置被佔用或沒有寫入權限,請嘗試更改歌曲保存目錄或重啟軟件或重啟電腦,錯誤詳情:", "download_status_start": "開始下載", diff --git a/src/renderer/store/download/action.ts b/src/renderer/store/download/action.ts index eb5cbb8b..02b856e2 100644 --- a/src/renderer/store/download/action.ts +++ b/src/renderer/store/download/action.ts @@ -260,10 +260,10 @@ const handleStartTask = async(downloadInfo: LX.Download.ListItem) => { setProgress(downloadInfo, event.data) break case 'error': - handleError(downloadInfo, event.data.error == null - ? event.data.message ?? undefined - // @ts-expect-error - : window.i18n.t(event.data.error) + (event.data.message ?? '')) + handleError(downloadInfo, event.data.error + ? window.i18n.t(event.data.error) + (event.data.message ?? '') + : event.data.message, + ) break default: break diff --git a/src/renderer/worker/download/download.ts b/src/renderer/worker/download/download.ts index 8ac0f599..175df9bb 100644 --- a/src/renderer/worker/download/download.ts +++ b/src/renderer/worker/download/download.ts @@ -165,10 +165,20 @@ const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string, s let retryNum = tryNum.get(downloadInfo.id) ?? 0 tryNum.set(downloadInfo.id, ++retryNum) if (retryNum > 2) { - sendAction(downloadInfo.id, { - action: 'error', - data: {}, - }) + if (response.statusCode) { + sendAction(downloadInfo.id, { + action: 'error', + data: { + error: 'download_status_error_response', + message: String(response.statusCode), + }, + }) + } else { + sendAction(downloadInfo.id, { + action: 'error', + data: {}, + }) + } return } switch (response.statusCode) { @@ -187,7 +197,7 @@ const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string, s } }, onStart() { - // sendAction(downloadInfo.id, { action: 'start' }) + sendAction(downloadInfo.id, { action: 'start' }) console.log('on start') }, onProgress(status) {