chore: 换一个方式

This commit is contained in:
tangge233
2024-11-08 16:51:38 +08:00
parent 05acfc6b51
commit 5d16cf24bb
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ RetryStart:
'下载 '下载
ActualSource = LoadingSource '显示加载中图片 ActualSource = LoadingSource '显示加载中图片
TempDownloadingPath = TempPath & RandomInteger(0, 10000000) TempDownloadingPath = TempPath & RandomInteger(0, 10000000)
NetDownload(Url, TempDownloadingPath, True) NetDownload(Url, TempDownloadingPath, True, False)
If Url <> Source AndAlso Url <> FallbackSource Then If Url <> Source AndAlso Url <> FallbackSource Then
'已经更换了地址 '已经更换了地址
File.Delete(TempDownloadingPath) File.Delete(TempDownloadingPath)
@@ -252,7 +252,7 @@ RequestFinished:
''' </summary> ''' </summary>
''' <param name="Url">网络 Url。</param> ''' <param name="Url">网络 Url。</param>
''' <param name="LocalFile">下载的本地地址。</param> ''' <param name="LocalFile">下载的本地地址。</param>
Public Sub NetDownload(Url As String, LocalFile As String, Optional UseBrowserUserAgent As Boolean = False) Public Sub NetDownload(Url As String, LocalFile As String, Optional UseBrowserUserAgent As Boolean = False, Optional AddReferer As Boolean = True)
Log("[Net] 直接下载文件:" & Url) Log("[Net] 直接下载文件:" & Url)
'初始化 '初始化
@@ -268,7 +268,7 @@ RequestFinished:
'下载 '下载
Using Client As New WebClient Using Client As New WebClient
Try Try
SecretHeadersSign(Url, Client, UseBrowserUserAgent) SecretHeadersSign(Url, Client, UseBrowserUserAgent, AddReferer)
Client.DownloadFile(Url, LocalFile) Client.DownloadFile(Url, LocalFile)
Catch ex As Exception Catch ex As Exception
File.Delete(LocalFile) File.Delete(LocalFile)
+2 -2
View File
@@ -100,7 +100,7 @@ Friend Module ModSecret
''' <summary> ''' <summary>
''' 设置 Headers 的 UA、Referer。 ''' 设置 Headers 的 UA、Referer。
''' </summary> ''' </summary>
Friend Sub SecretHeadersSign(Url As String, ByRef Client As WebClient, Optional UseBrowserUserAgent As Boolean = False) Friend Sub SecretHeadersSign(Url As String, ByRef Client As WebClient, Optional UseBrowserUserAgent As Boolean = False, Optional AddReferer As Boolean = True)
If Url.Contains("baidupcs.com") OrElse Url.Contains("baidu.com") Then If Url.Contains("baidupcs.com") OrElse Url.Contains("baidu.com") Then
Client.Headers("User-Agent") = "LogStatistic" '#4951 Client.Headers("User-Agent") = "LogStatistic" '#4951
ElseIf UseBrowserUserAgent Then ElseIf UseBrowserUserAgent Then
@@ -108,7 +108,7 @@ Friend Module ModSecret
Else Else
Client.Headers("User-Agent") = "PCL2/" & VersionStandardCode Client.Headers("User-Agent") = "PCL2/" & VersionStandardCode
End If End If
If Not Url.Contains("hdslb.com") Then If AddReferer Then
Client.Headers("Referer") = "http://" & VersionCode & ".pcl2.open.server/" Client.Headers("Referer") = "http://" & VersionCode & ".pcl2.open.server/"
End If End If
Client.Headers("x-api-key") = CurseForgeAPIKey Client.Headers("x-api-key") = CurseForgeAPIKey