@@ -133,7 +133,7 @@ func (d *Onedrive) _refreshToken() error {
133133 return nil
134134}
135135
136- func (d * Onedrive ) Request (url string , method string , callback base.ReqCallback , resp interface {}) ([]byte , error ) {
136+ func (d * Onedrive ) Request (url string , method string , callback base.ReqCallback , resp interface {}, noRetry ... bool ) ([]byte , error ) {
137137 if d .ref != nil {
138138 return d .ref .Request (url , method , callback , resp )
139139 }
@@ -152,7 +152,7 @@ func (d *Onedrive) Request(url string, method string, callback base.ReqCallback,
152152 return nil , err
153153 }
154154 if e .Error .Code != "" {
155- if e .Error .Code == "InvalidAuthenticationToken" {
155+ if e .Error .Code == "InvalidAuthenticationToken" && ! utils . IsBool ( noRetry ... ) {
156156 err = d .refreshToken ()
157157 if err != nil {
158158 return nil , err
@@ -310,9 +310,36 @@ func (d *Onedrive) getDrive(ctx context.Context) (*DriveResp, error) {
310310 var resp DriveResp
311311 _ , err := d .Request (api , http .MethodGet , func (req * resty.Request ) {
312312 req .SetContext (ctx )
313- }, & resp )
313+ }, & resp , true )
314314 if err != nil {
315315 return nil , err
316316 }
317317 return & resp , nil
318318}
319+
320+ func (d * Onedrive ) getDirectUploadInfo (ctx context.Context , path string ) (* model.HttpDirectUploadInfo , error ) {
321+ // Create upload session
322+ url := d .GetMetaUrl (false , path ) + "/createUploadSession"
323+ metadata := map [string ]any {
324+ "item" : map [string ]any {
325+ "@microsoft.graph.conflictBehavior" : "rename" ,
326+ },
327+ }
328+
329+ res , err := d .Request (url , http .MethodPost , func (req * resty.Request ) {
330+ req .SetBody (metadata ).SetContext (ctx )
331+ }, nil )
332+ if err != nil {
333+ return nil , err
334+ }
335+
336+ uploadUrl := jsoniter .Get (res , "uploadUrl" ).ToString ()
337+ if uploadUrl == "" {
338+ return nil , fmt .Errorf ("failed to get upload URL from response" )
339+ }
340+ return & model.HttpDirectUploadInfo {
341+ UploadURL : uploadUrl ,
342+ ChunkSize : d .ChunkSize * 1024 * 1024 , // Convert MB to bytes
343+ Method : "PUT" ,
344+ }, nil
345+ }
0 commit comments