@@ -5,10 +5,10 @@ import (
55 "fmt"
66 "io/ioutil"
77 "log"
8- "net/http"
9- "net/url"
108 "main/fileutil"
119 httpLocal "main/graph/net/http"
10+ "net/http"
11+ "net/url"
1212)
1313
1414const (
@@ -35,21 +35,20 @@ type RestoreService struct {
3535//@bearerToken will be extracted as sent from the restore input xml
3636//@filePath will be extracted from the file hierarchy the needs to be restored
3737//@fileInfo it is the file info struct that contains the actual file reference and the size_type
38- func (rs * RestoreService ) SimpleUploadToOriginalLoc (userId string , bearerToken string , conflictOption string , filePath string , fileInfo fileutil.FileInfo , sendMsg func (text string ), locText func (text string ) string , username string ) ( interface {}, error ) {
38+ func (rs * RestoreService ) SimpleUploadToOriginalLoc (userId string , bearerToken string , conflictOption string , filePath string , fileInfo fileutil.FileInfo , sendMsg func (text string ), locText func (text string ) string , username string ) interface {} {
3939 if fileInfo .SizeType == fileutil .SizeTypeLarge {
4040 //For Large file type use resemble onedrive upload API
4141 //log.Printf("Processing Large File: %s", filePath)
4242 sendMsg (fmt .Sprintf ("文件: `%s` 开始上传至OneDrive\n 账户:`%s`\n 文件超过4MB,进入大文件通道" , filePath , username ))
4343 return rs .recoverableUpload (userId , bearerToken , conflictOption , filePath , fileInfo , sendMsg , locText , username )
4444 } else {
4545 //log.Printf("Processing Small File: %s", filePath)
46- sendMsg (fmt .Sprintf ("文件: `%s` 开始上传至OneDrive\n 账户:`%s`\n 文件小于4MB,进入小文件通道,上传中...... " , filePath , username ))
46+ sendMsg (fmt .Sprintf ("文件: `%s` 开始上传至OneDrive\n 账户:`%s`\n 文件小于4MB,进入小文件通道,上传中" , filePath , username ))
4747 uploadPath := fmt .Sprintf (simpleUploadPath , userId , filePath )
4848 req , err := rs .NewRequest ("PUT" , uploadPath , getSimpleUploadHeader (bearerToken ), fileInfo .FileData )
4949 if err != nil {
50- return nil , err
50+ log . Panicf ( "Failed to Restore :%v" , err )
5151 }
52-
5352 //Handle query parameter for conflict resolution
5453 //The different values for @microsoft.graph.conflictBehavior= rename|replace|fail
5554 q := url.Values {}
@@ -59,8 +58,7 @@ func (rs *RestoreService) SimpleUploadToOriginalLoc(userId string, bearerToken s
5958 //Execute the request
6059 resp , err := rs .Do (req )
6160 if err != nil {
62- //Need to return a generic object from onedrive upload instead of response directly
63- return nil , err
61+ log .Panicf ("Failed to Restore :%v" , err )
6462 }
6563 if resp .Body != nil {
6664 defer resp .Body .Close ()
@@ -69,10 +67,10 @@ func (rs *RestoreService) SimpleUploadToOriginalLoc(userId string, bearerToken s
6967 respMap := make (map [string ]interface {})
7068 err = json .NewDecoder (resp .Body ).Decode (& respMap )
7169 if err != nil {
72- return nil , err
70+ log . Panicf ( "Failed to Restore :%v" , err )
7371 }
7472 sendMsg ("close" )
75- return respMap , nil
73+ return respMap
7674 }
7775
7876}
@@ -83,7 +81,7 @@ func (rs *RestoreService) SimpleUploadToOriginalLoc(userId string, bearerToken s
8381//@userId will be extracted as sent from the restore input xml
8482//@filePath will be extracted from the file hierarchy the needs to be restored
8583//@fileInfo it is the file info struct that contains the actual file reference and the size_type
86- func (rs * RestoreService ) SimpleUploadToAlternateLoc (altUserId string , bearerToken string , conflictOption string , filePath string , fileInfo fileutil.FileInfo , sendMsg func (text string ), locText func (text string ) string , username string ) ( interface {}, error ) {
84+ func (rs * RestoreService ) SimpleUploadToAlternateLoc (altUserId string , bearerToken string , conflictOption string , filePath string , fileInfo fileutil.FileInfo , sendMsg func (text string ), locText func (text string ) string , username string ) interface {} {
8785 if fileInfo .SizeType == fileutil .SizeTypeLarge {
8886 //For Large file type use resemble onedrive upload API
8987 return rs .recoverableUpload (altUserId , bearerToken , conflictOption , filePath , fileInfo , sendMsg , locText , username )
@@ -92,9 +90,8 @@ func (rs *RestoreService) SimpleUploadToAlternateLoc(altUserId string, bearerTok
9290 uploadPath := fmt .Sprintf (simpleUploadPath , altUserId , filePath )
9391 req , err := rs .NewRequest ("PUT" , uploadPath , getSimpleUploadHeader (bearerToken ), fileInfo .FileData )
9492 if err != nil {
95- return nil , err
93+ log . Panicf ( "Failed to Restore :%v" , err )
9694 }
97-
9895 //Handle query parameter for conflict resolution
9996 //The different values for @microsoft.graph.conflictBehavior= rename|replace|fail
10097 q := url.Values {}
@@ -104,8 +101,7 @@ func (rs *RestoreService) SimpleUploadToAlternateLoc(altUserId string, bearerTok
104101 //Execute the request
105102 resp , err := rs .Do (req )
106103 if err != nil {
107- //Need to return a generic object from onedrive upload instead of response directly
108- return nil , err
104+ log .Panicf ("Failed to Restore :%v" , err )
109105 }
110106 if resp .Body != nil {
111107 defer resp .Body .Close ()
@@ -114,9 +110,9 @@ func (rs *RestoreService) SimpleUploadToAlternateLoc(altUserId string, bearerTok
114110 respMap := make (map [string ]interface {})
115111 err = json .NewDecoder (resp .Body ).Decode (& respMap )
116112 if err != nil {
117- return nil , err
113+ log . Panicf ( "Failed to Restore :%v" , err )
118114 }
119- return respMap , nil
115+ return respMap
120116 }
121117}
122118
0 commit comments