task-7: buildDownloadUrl()/resolveDownloadUrl() 下载 URL 统一构造(user_id 追加与去重、fresh 优先)

This commit is contained in:
2026-08-31 19:20:56 +08:00
parent 1e1f533a24
commit 35de13f7f1
2 changed files with 72 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
export interface DownloadableItem {
freshDownloadUrl?: string | null
downloadUrl?: string | null
}
export function buildDownloadUrl(path: string, userId?: number): string {
if (userId === undefined || userId === null || Number.isNaN(userId)) {
return path
}
if (/[?&]user_id=/.test(path)) {
return path
}
const separator = path.includes('?') ? '&' : '?'
return `${path}${separator}user_id=${userId}`
}
export function resolveDownloadUrl(item: DownloadableItem | null | undefined): string {
if (!item) {
return ''
}
return item.freshDownloadUrl || item.downloadUrl || ''
}