Skip to content

Commit

Permalink
license add mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Nov 12, 2022
1 parent 4eb99e7 commit 12580b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/restore/upload/onedriveRecoverableRestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func (rs *RestoreService) recoverableUpload(userID string, bearerToken string, c
//3b. make a call to the upload url with the file part based on the offset. 使用基于偏移量的文件部分调用上载url。
var resp *http.Response
for errCount := 1; errCount < 10; errCount++ {
bearerToken = http2.GetBearer() //解决长时下载时,Bearer超时的问题,这里采用超时一次就重新获取一次token的方案
resp, err = rs.uploadFilePart(uploadURL, filePath, bearerToken, *filePartInBytes, sOffset, isLastChunk)
if err != nil {
bearerToken = http2.GetBearer() //解决长时上传时,Bearer超时的问题,这里采用超时一次就重新获取一次token的方案
sendMsg("close|" + fmt.Sprintf(locText("failToLink"), username, filePath, errCount))
// close 用作输出时定位,带有 close 在输出时不会被刷新走
// close= 表示文件传输结束,此时会同步删除tg发出的消息
Expand Down
7 changes: 5 additions & 2 deletions graph/net/http/OAuth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package http
import (
"encoding/json"
"fmt"
"github.com/buger/jsonparser"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strings"

"github.com/buger/jsonparser"
"sync"
)

type Certificate struct {
Expand All @@ -30,6 +30,7 @@ var GraphURL = "https://graph.microsoft.com/v1.0/me/"
var TokenURL = "https://login.microsoftonline.com/common/oauth2/v2.0/token"
var Host = "login.microsoftonline.com"
var isCN = false
var mutex sync.Mutex

func ChangeCNURL() {
GraphURL = "https://microsoftgraph.chinacloudapi.cn/v1.0/me/"
Expand Down Expand Up @@ -200,6 +201,7 @@ func getAccessToken(oauth2URL string, ms int, lang string) string {
}

func refreshAccessToken(path string, Thread int, BlockSize int, Language string, TimeOut int, BotKey string, UserID string) string {
mutex.Lock() //使用互斥锁防止线程数过高时信息被覆盖问题
filePtr, err := os.Open(path)
if err != nil {
log.Panicln(err)
Expand Down Expand Up @@ -260,6 +262,7 @@ func refreshAccessToken(path string, Thread int, BlockSize int, Language string,
// 创建Json编码器
encoder := json.NewEncoder(filePtr)
err = encoder.Encode(info)
defer mutex.Unlock()
if err != nil {
log.Panicln(err.Error())
}
Expand Down

0 comments on commit 12580b3

Please sign in to comment.