mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-11-30 17:16:59 +00:00
Open Quark and UC browser downloads without a Referer.
The parse result, file list, dialog, and show-file download actions now use a link with referrerpolicy=no-referrer so a click does not send the site Referer that makes the public CDN return 403 HTML. Co-authored-by: qaiu <[email protected]>
This commit is contained in:
5 files changed
+28
-40
No files matched your search
@@ -455,6 +455,7 @@ import fileTypeUtils from '@/utils/fileTypeUtils'
|
|||||||
import DownloadDialog from '@/components/DownloadDialog.vue'
|
import DownloadDialog from '@/components/DownloadDialog.vue'
|
||||||
import { testConnection, autoDetect, addDownload, batchAddDownload, getConfig, saveConfig } from '@/utils/downloaderService'
|
import { testConnection, autoDetect, addDownload, batchAddDownload, getConfig, saveConfig } from '@/utils/downloaderService'
|
||||||
import batchTreeCollect from '@/utils/batchTreeCollect'
|
import batchTreeCollect from '@/utils/batchTreeCollect'
|
||||||
|
import { openNoReferrer } from '@/utils/openNoReferrer'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
DEFAULT_BATCH_MAX_DEPTH,
|
DEFAULT_BATCH_MAX_DEPTH,
|
||||||
@@ -758,13 +759,7 @@ export default {
|
|||||||
// 下载文件
|
// 下载文件
|
||||||
downloadFile(file) {
|
downloadFile(file) {
|
||||||
if (file?.parserUrl) {
|
if (file?.parserUrl) {
|
||||||
const a = document.createElement('a')
|
openNoReferrer(this.appendToken(file.parserUrl))
|
||||||
a.href = this.appendToken(file.parserUrl)
|
|
||||||
a.target = '_blank'
|
|
||||||
a.rel = 'noopener noreferrer'
|
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
document.body.removeChild(a)
|
|
||||||
this.$message.success('开始下载文件')
|
this.$message.success('开始下载文件')
|
||||||
} else {
|
} else {
|
||||||
this.$message.warning('该文件暂无下载链接')
|
this.$message.warning('该文件暂无下载链接')
|
||||||
@@ -805,14 +800,7 @@ export default {
|
|||||||
this.downloadInfo = info
|
this.downloadInfo = info
|
||||||
this.downloadDialogVisible = true
|
this.downloadDialogVisible = true
|
||||||
} else if (info.downloadUrl) {
|
} else if (info.downloadUrl) {
|
||||||
// 服务端判断不需要下载器,直接跳转
|
openNoReferrer(info.downloadUrl)
|
||||||
const a = document.createElement('a')
|
|
||||||
a.href = info.downloadUrl
|
|
||||||
a.target = '_blank'
|
|
||||||
a.rel = 'noopener noreferrer'
|
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
document.body.removeChild(a)
|
|
||||||
this.$message.success('开始下载文件')
|
this.$message.success('开始下载文件')
|
||||||
} else {
|
} else {
|
||||||
this.downloadFile(file)
|
this.downloadFile(file)
|
||||||
@@ -948,14 +936,7 @@ export default {
|
|||||||
},
|
},
|
||||||
openPreviewInNewTab() {
|
openPreviewInNewTab() {
|
||||||
if (this.previewUrl) {
|
if (this.previewUrl) {
|
||||||
// 使用动态 a 标签并设置 noopener noreferrer 以避免携带 Referer,绕过防盗链机制
|
openNoReferrer(this.previewUrl)
|
||||||
const a = document.createElement('a')
|
|
||||||
a.href = this.previewUrl
|
|
||||||
a.target = '_blank'
|
|
||||||
a.rel = 'noopener noreferrer'
|
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
document.body.removeChild(a)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hasValidTime(value) {
|
hasValidTime(value) {
|
||||||
@@ -1237,14 +1218,8 @@ export default {
|
|||||||
this.batchProgress = { current: 0, total: files.length, failed: 0 }
|
this.batchProgress = { current: 0, total: files.length, failed: 0 }
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
try {
|
try {
|
||||||
const a = document.createElement('a')
|
|
||||||
const rawUrl = file.parserUrl.startsWith('http') ? file.parserUrl : (window.location.origin + file.parserUrl)
|
const rawUrl = file.parserUrl.startsWith('http') ? file.parserUrl : (window.location.origin + file.parserUrl)
|
||||||
a.href = this.appendToken(rawUrl)
|
openNoReferrer(this.appendToken(rawUrl))
|
||||||
a.target = '_blank'
|
|
||||||
a.rel = 'noopener noreferrer'
|
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
document.body.removeChild(a)
|
|
||||||
await new Promise(r => setTimeout(r, 500))
|
await new Promise(r => setTimeout(r, 500))
|
||||||
} catch {
|
} catch {
|
||||||
this.batchProgress.failed++
|
this.batchProgress.failed++
|
||||||
|
|||||||
@@ -105,6 +105,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { testConnection, addDownload, getConfig, hasCookieHeader, hasCustomUaHeader } from '@/utils/downloaderService'
|
import { testConnection, addDownload, getConfig, hasCookieHeader, hasCustomUaHeader } from '@/utils/downloaderService'
|
||||||
|
import { openNoReferrer } from '@/utils/openNoReferrer'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DownloadDialog',
|
name: 'DownloadDialog',
|
||||||
@@ -193,13 +194,7 @@ export default {
|
|||||||
/** 直接打开下载链接(可能因缺请求头而失败) */
|
/** 直接打开下载链接(可能因缺请求头而失败) */
|
||||||
doDirectDownload() {
|
doDirectDownload() {
|
||||||
if (this.info && this.info.downloadUrl) {
|
if (this.info && this.info.downloadUrl) {
|
||||||
const a = document.createElement('a')
|
openNoReferrer(this.info.downloadUrl)
|
||||||
a.href = this.info.downloadUrl
|
|
||||||
a.target = '_blank'
|
|
||||||
a.rel = 'noopener noreferrer'
|
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
document.body.removeChild(a)
|
|
||||||
this.dialogVisible = false
|
this.dialogVisible = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* 在用户点击里打开地址,并且不带 Referer。
|
||||||
|
* 夸克 / UC 的公开文件 CDN 遇到站点 Referer 会返回 403 HTML。
|
||||||
|
* 使用 referrerpolicy="no-referrer" 的链接,而不是只依赖 window.open 的特征字符串。
|
||||||
|
*/
|
||||||
|
export function openNoReferrer(url) {
|
||||||
|
if (!url) return
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = url
|
||||||
|
a.target = '_blank'
|
||||||
|
a.rel = 'noreferrer noopener'
|
||||||
|
a.referrerPolicy = 'no-referrer'
|
||||||
|
a.style.display = 'none'
|
||||||
|
document.body.appendChild(a)
|
||||||
|
a.click()
|
||||||
|
a.remove()
|
||||||
|
}
|
||||||
@@ -619,6 +619,7 @@ import DirectoryTree from '@/components/DirectoryTree'
|
|||||||
import ViewModeSwitch from '@/components/ViewModeSwitch'
|
import ViewModeSwitch from '@/components/ViewModeSwitch'
|
||||||
import DownloadDialog from '@/components/DownloadDialog'
|
import DownloadDialog from '@/components/DownloadDialog'
|
||||||
import parserUrl from '../parserUrl1'
|
import parserUrl from '../parserUrl1'
|
||||||
|
import { openNoReferrer } from '../utils/openNoReferrer'
|
||||||
import fileTypeUtils from '@/utils/fileTypeUtils'
|
import fileTypeUtils from '@/utils/fileTypeUtils'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { playgroundApi } from '@/utils/playgroundApi'
|
import { playgroundApi } from '@/utils/playgroundApi'
|
||||||
@@ -1430,7 +1431,7 @@ export default {
|
|||||||
// 文件点击处理
|
// 文件点击处理
|
||||||
handleFileClick(file) {
|
handleFileClick(file) {
|
||||||
if (file.parserUrl) {
|
if (file.parserUrl) {
|
||||||
window.open(file.parserUrl, '_blank', 'noopener,noreferrer')
|
openNoReferrer(file.parserUrl)
|
||||||
} else {
|
} else {
|
||||||
this.$message.warning('该文件暂无下载链接')
|
this.$message.warning('该文件暂无下载链接')
|
||||||
}
|
}
|
||||||
@@ -1867,7 +1868,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
openUrl(url) {
|
openUrl(url) {
|
||||||
if (url) window.open(url, '_blank', 'noopener,noreferrer')
|
openNoReferrer(url)
|
||||||
},
|
},
|
||||||
async loadDirectoryParseSupportedPans() {
|
async loadDirectoryParseSupportedPans() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<div class="file-meta-info-card">
|
<div class="file-meta-info-card">
|
||||||
<div class="file-meta-row">
|
<div class="file-meta-row">
|
||||||
<span class="file-meta-label">下载链接:</span>
|
<span class="file-meta-label">下载链接:</span>
|
||||||
<a :href="downloadUrl" target="_blank" class="file-meta-link">点击下载</a>
|
<a :href="downloadUrl" target="_blank" rel="noreferrer noopener" referrerpolicy="no-referrer" class="file-meta-link">点击下载</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="file-meta-row">
|
<div class="file-meta-row">
|
||||||
<span class="file-meta-label">文件名:</span>{{ fileTypeUtils.extractFileNameAndExt(downloadUrl).name }}
|
<span class="file-meta-label">文件名:</span>{{ fileTypeUtils.extractFileNameAndExt(downloadUrl).name }}
|
||||||
|
|||||||
Reference in new issue
Block a user