添加下载失败信息状态

pull/1211/head
lyswhut 2023-02-10 08:58:24 +08:00
parent ef9427122e
commit 6048af99bc
6 changed files with 78 additions and 62 deletions

View File

@ -1,66 +1,69 @@
import { type Message } from '@/lang'
// interface DownloadList { // interface DownloadList {
// } // }
declare namespace LX { declare global {
namespace Download { namespace LX {
type DownloadTaskStatus = 'run' namespace Download {
| 'waiting' type DownloadTaskStatus = 'run'
| 'pause' | 'waiting'
| 'error' | 'pause'
| 'completed' | 'error'
| 'completed'
type FileExt = 'mp3' | 'flac' | 'wav' | 'ape' type FileExt = 'mp3' | 'flac' | 'wav' | 'ape'
interface ProgressInfo { interface ProgressInfo {
progress: number progress: number
speed: string speed: string
downloaded: number downloaded: number
total: number total: number
}
interface DownloadTaskActionBase <A> {
action: A
}
interface DownloadTaskActionData<A, D> extends DownloadTaskActionBase<A> {
data: D
}
type DownloadTaskAction<A, D = undefined> = D extends undefined ? DownloadTaskActionBase<A> : DownloadTaskActionData<A, D>
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 saveDownloadMusicInfo { interface DownloadTaskActionBase <A> {
list: ListItem[] action: A
addMusicLocationType: LX.AddMusicLocationType }
interface DownloadTaskActionData<A, D> extends DownloadTaskActionBase<A> {
data: D
}
type DownloadTaskAction<A, D = undefined> = D extends undefined ? DownloadTaskActionBase<A> : DownloadTaskActionData<A, D>
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
}
} }
} }
} }

View File

@ -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": "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_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_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_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_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", "download_status_start": "start download",

View File

@ -64,6 +64,7 @@
"download_status_error_check_path": "检查下载路径出错,请检查设置的下载目录是否正常", "download_status_error_check_path": "检查下载路径出错,请检查设置的下载目录是否正常",
"download_status_error_check_path_exist": "存在同名文件,跳过下载", "download_status_error_check_path_exist": "存在同名文件,跳过下载",
"download_status_error_refresh_url": "链接失效,正在刷新链接", "download_status_error_refresh_url": "链接失效,正在刷新链接",
"download_status_error_response": "下载失败:",
"download_status_error_url_failed": "获取音乐链接失败", "download_status_error_url_failed": "获取音乐链接失败",
"download_status_error_write": "歌曲保存位置被占用或没有写入权限,请尝试更改歌曲保存目录或重启软件或重启电脑,错误详情:", "download_status_error_write": "歌曲保存位置被占用或没有写入权限,请尝试更改歌曲保存目录或重启软件或重启电脑,错误详情:",
"download_status_start": "开始下载", "download_status_start": "开始下载",

View File

@ -64,6 +64,7 @@
"download_status_error_check_path": "檢查下載路徑出錯,請檢查設置的下載目錄是否正常", "download_status_error_check_path": "檢查下載路徑出錯,請檢查設置的下載目錄是否正常",
"download_status_error_check_path_exist": "存在同名文件,跳過下載", "download_status_error_check_path_exist": "存在同名文件,跳過下載",
"download_status_error_refresh_url": "鏈接失效,正在刷新鏈接", "download_status_error_refresh_url": "鏈接失效,正在刷新鏈接",
"download_status_error_response": "下載失敗:",
"download_status_error_url_failed": "獲取音樂鏈接失敗", "download_status_error_url_failed": "獲取音樂鏈接失敗",
"download_status_error_write": "歌曲保存位置被佔用或沒有寫入權限,請嘗試更改歌曲保存目錄或重啟軟件或重啟電腦,錯誤詳情:", "download_status_error_write": "歌曲保存位置被佔用或沒有寫入權限,請嘗試更改歌曲保存目錄或重啟軟件或重啟電腦,錯誤詳情:",
"download_status_start": "開始下載", "download_status_start": "開始下載",

View File

@ -260,10 +260,10 @@ const handleStartTask = async(downloadInfo: LX.Download.ListItem) => {
setProgress(downloadInfo, event.data) setProgress(downloadInfo, event.data)
break break
case 'error': case 'error':
handleError(downloadInfo, event.data.error == null handleError(downloadInfo, event.data.error
? event.data.message ?? undefined ? window.i18n.t(event.data.error) + (event.data.message ?? '')
// @ts-expect-error : event.data.message,
: window.i18n.t(event.data.error) + (event.data.message ?? '')) )
break break
default: default:
break break

View File

@ -165,10 +165,20 @@ const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string, s
let retryNum = tryNum.get(downloadInfo.id) ?? 0 let retryNum = tryNum.get(downloadInfo.id) ?? 0
tryNum.set(downloadInfo.id, ++retryNum) tryNum.set(downloadInfo.id, ++retryNum)
if (retryNum > 2) { if (retryNum > 2) {
sendAction(downloadInfo.id, { if (response.statusCode) {
action: 'error', sendAction(downloadInfo.id, {
data: {}, action: 'error',
}) data: {
error: 'download_status_error_response',
message: String(response.statusCode),
},
})
} else {
sendAction(downloadInfo.id, {
action: 'error',
data: {},
})
}
return return
} }
switch (response.statusCode) { switch (response.statusCode) {
@ -187,7 +197,7 @@ const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string, s
} }
}, },
onStart() { onStart() {
// sendAction(downloadInfo.id, { action: 'start' }) sendAction(downloadInfo.id, { action: 'start' })
console.log('on start') console.log('on start')
}, },
onProgress(status) { onProgress(status) {