This commit is contained in:
spiritysdx
2024-07-20 18:48:31 +08:00
parent f2e4ca6a0b
commit 34065b0161

View File

@@ -239,7 +239,8 @@ func PrintAndCapture(f func(), tempOutput, output string) string {
// UploadText 上传文本内容到指定URL // UploadText 上传文本内容到指定URL
func UploadText(absPath string) (string, error) { func UploadText(absPath string) (string, error) {
url := "https://paste.spiritlhl.net/api/upload" primaryURL := "http://hpaste.spiritlhl.net/api/upload"
backupURL := "https://paste.spiritlhl.net/api/upload"
token := network.SecurityUploadToken token := network.SecurityUploadToken
client := req.DefaultClient() client := req.DefaultClient()
client.SetTimeout(6 * time.Second) client.SetTimeout(6 * time.Second)
@@ -247,7 +248,12 @@ func UploadText(absPath string) (string, error) {
SetRetryCount(2). SetRetryCount(2).
SetRetryBackoffInterval(1*time.Second, 5*time.Second). SetRetryBackoffInterval(1*time.Second, 5*time.Second).
SetRetryFixedInterval(2 * time.Second) SetRetryFixedInterval(2 * time.Second)
file, _ := os.Open(absPath) file, err := os.Open(absPath)
if err != nil {
return "", err
}
defer file.Close()
upload := func(url string) (string, error) {
resp, err := client.R(). resp, err := client.R().
SetHeader("Authorization", token). SetHeader("Authorization", token).
SetHeader("Format", "RANDOM"). SetHeader("Format", "RANDOM").
@@ -266,6 +272,16 @@ func UploadText(absPath string) (string, error) {
return "", fmt.Errorf("upload failed with status code: %d", resp.StatusCode) return "", fmt.Errorf("upload failed with status code: %d", resp.StatusCode)
} }
} }
result, err := upload(primaryURL)
if err == nil {
return result, nil
}
result, err = upload(backupURL)
if err != nil {
return "", err
}
return result, nil
}
// ProcessAndUpload 创建结果文件并上传文件 // ProcessAndUpload 创建结果文件并上传文件
func ProcessAndUpload(output string, filePath string, enableUplaod bool) { func ProcessAndUpload(output string, filePath string, enableUplaod bool) {