Skip to content

Commit

Permalink
Refine onedrive profile
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Apr 13, 2021
1 parent 34a58b4 commit f74eb02
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/onedrive/graph/net/http/OAuth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/buger/jsonparser"
)

type token struct {
type Token struct {
RefreshToken string `json:"refresh_token"`
ThreadNum int `json:"threadNum"`
BlockSize int `json:"blockSize"`
Expand Down Expand Up @@ -123,7 +123,7 @@ func getAccessToken(oauth2URL string) string {
}
//log.Println(refreshToken)

info := token{
info := Token{
RefreshToken: refreshToken,
ThreadNum: 3,
BlockSize: 10,
Expand Down Expand Up @@ -152,7 +152,7 @@ func refreshAccessToken(path string) string {
return ""
}
defer filePtr.Close()
var info token
var info Token
// 创建json解码器
decoder := json.NewDecoder(filePtr)
err = decoder.Decode(&info)
Expand Down Expand Up @@ -182,7 +182,7 @@ func refreshAccessToken(path string) string {
}
// log.Println(refreshToken)

info = token{
info = Token{
RefreshToken: refreshToken,
ThreadNum: info.ThreadNum,
BlockSize: info.BlockSize,
Expand Down
21 changes: 19 additions & 2 deletions src/onedrive/onedrive.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package onedrive

import (
"encoding/json"
"fmt"
"log"
"net/http"
Expand All @@ -12,6 +13,7 @@ import (
"path/filepath"
"strings"
"sync"
"time"
)

func ApplyForNewPass(url string) string {
Expand All @@ -25,6 +27,21 @@ func refreshToken(infoPath string) (string, string, string) {
}

func Upload(infoPath string, filePath string, threads int, sendMsg func() func(text string), locText func(text string) string) {

filePtr, err := os.Open(infoPath)
if err != nil {
log.Panicln(err)
}
defer filePtr.Close()
var info httpLocal.Token

// 创建json解码器
decoder := json.NewDecoder(filePtr)
err = decoder.Decode(&info)
if err != nil {
log.Panicln(err.Error())
}
fileutil.SetDefaultChunkSize(info.BlockSize)
programPath, err := filepath.Abs(filepath.Dir(infoPath))
if err != nil {
log.Panic(err)
Expand All @@ -43,7 +60,7 @@ func Upload(infoPath string, filePath string, threads int, sendMsg func() func(t
}
filePath = path.Base(filePath)
//Initialize the upload restore service
restoreSrvc := upload.GetRestoreService(http.DefaultClient)
restoreSrvc := upload.GetRestoreService(&http.Client{Timeout: time.Duration(info.TimeOut) * time.Second})

//Get the list of files that needs to be restore with the actual backed up path. 获取需要使用实际备份路径还原的文件列表。
fileInfoToUpload, err := fileutil.GetAllUploadItemsFrmSource(filePath)
Expand All @@ -57,7 +74,7 @@ func Upload(infoPath string, filePath string, threads int, sendMsg func() func(t
} else {
restore(restoreSrvc, fileInfoToUpload, threads)
}*/
restore(restoreSrvc, fileInfoToUpload, threads, sendMsg, locText, infoPath)
restore(restoreSrvc, fileInfoToUpload, info.ThreadNum, sendMsg, locText, infoPath)
err = os.Chdir(oldDir)
if err != nil {
log.Panic(err)
Expand Down
8 changes: 4 additions & 4 deletions vendor/onedrive/graph/net/http/OAuth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/buger/jsonparser"
)

type token struct {
type Token struct {
RefreshToken string `json:"refresh_token"`
ThreadNum int `json:"threadNum"`
BlockSize int `json:"blockSize"`
Expand Down Expand Up @@ -123,7 +123,7 @@ func getAccessToken(oauth2URL string) string {
}
//log.Println(refreshToken)

info := token{
info :=Token{
RefreshToken: refreshToken,
ThreadNum: 3,
BlockSize: 10,
Expand Down Expand Up @@ -152,7 +152,7 @@ func refreshAccessToken(path string) string {
return ""
}
defer filePtr.Close()
var info token
var info Token
// 创建json解码器
decoder := json.NewDecoder(filePtr)
err = decoder.Decode(&info)
Expand Down Expand Up @@ -182,7 +182,7 @@ func refreshAccessToken(path string) string {
}
// log.Println(refreshToken)

info = token{
info = Token{
RefreshToken: refreshToken,
ThreadNum: info.ThreadNum,
BlockSize: info.BlockSize,
Expand Down
21 changes: 19 additions & 2 deletions vendor/onedrive/onedrive.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package onedrive

import (
"encoding/json"
"fmt"
"log"
"net/http"
Expand All @@ -12,6 +13,7 @@ import (
"path/filepath"
"strings"
"sync"
"time"
)

func ApplyForNewPass(url string) string {
Expand All @@ -25,6 +27,21 @@ func refreshToken(infoPath string) (string, string, string) {
}

func Upload(infoPath string, filePath string, threads int, sendMsg func() func(text string), locText func(text string) string) {

filePtr, err := os.Open(infoPath)
if err != nil {
log.Panicln(err)
}
defer filePtr.Close()
var info httpLocal.Token

// 创建json解码器
decoder := json.NewDecoder(filePtr)
err = decoder.Decode(&info)
if err != nil {
log.Panicln(err.Error())
}
fileutil.SetDefaultChunkSize(info.BlockSize)
programPath, err := filepath.Abs(filepath.Dir(infoPath))
if err != nil {
log.Panic(err)
Expand All @@ -43,7 +60,7 @@ func Upload(infoPath string, filePath string, threads int, sendMsg func() func(t
}
filePath = path.Base(filePath)
//Initialize the upload restore service
restoreSrvc := upload.GetRestoreService(http.DefaultClient)
restoreSrvc := upload.GetRestoreService(&http.Client{Timeout: time.Duration(info.TimeOut) * time.Second})

//Get the list of files that needs to be restore with the actual backed up path. 获取需要使用实际备份路径还原的文件列表。
fileInfoToUpload, err := fileutil.GetAllUploadItemsFrmSource(filePath)
Expand All @@ -57,7 +74,7 @@ func Upload(infoPath string, filePath string, threads int, sendMsg func() func(t
} else {
restore(restoreSrvc, fileInfoToUpload, threads)
}*/
restore(restoreSrvc, fileInfoToUpload, threads, sendMsg, locText, infoPath)
restore(restoreSrvc, fileInfoToUpload, info.ThreadNum, sendMsg, locText, infoPath)
err = os.Chdir(oldDir)
if err != nil {
log.Panic(err)
Expand Down

0 comments on commit f74eb02

Please sign in to comment.