File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -209,10 +209,10 @@ func (d *Onedrive) createLink(path string) (string, error) {
209209 if err != nil {
210210 return "" , err
211211 }
212- q := p . Query ()
213-
212+ // Do some transformations
213+ q := url. Values {}
214214 if p .Host == "1drv.ms" {
215- // For personal, do some transformations
215+ // For personal
216216 // https://1drv.ms/t/c/{user}/{share} ->
217217 // https://my.microsoftpersonalcontent.com/personal/{user}/_layouts/15/download.aspx?share={share}
218218 paths := strings .Split (p .Path , "/" )
@@ -221,13 +221,22 @@ func (d *Onedrive) createLink(path string) (string, error) {
221221 }
222222 user := paths [3 ]
223223 share := paths [4 ]
224- p .Scheme = "https"
225224 p .Host = "my.microsoftpersonalcontent.com"
226225 p .Path = fmt .Sprintf ("/personal/%s/_layouts/15/download.aspx" , user )
227- q = url.Values {}
226+ q .Set ("share" , share )
227+ } else if strings .Contains (p .Host , ".sharepoint.com" ) {
228+ // https://{tenant}-my.sharepoint.com/:u:/g/personal/{user_email}/{share}
229+ // https://{tenant}-my.sharepoint.com/personal/{user_email}/_layouts/15/download.aspx?share={share}
230+ paths := strings .Split (p .Path , "/" )
231+ if len (paths ) < 6 || paths [5 ] == "" {
232+ return "" , fmt .Errorf ("invalid onedrive sharepoint link" )
233+ }
234+ user := paths [4 ]
235+ share := paths [5 ]
236+ p .Path = fmt .Sprintf ("/personal/%s/_layouts/15/download.aspx" , user )
228237 q .Set ("share" , share )
229238 } else {
230- q . Set ( "download " , "1" )
239+ return " " , fmt . Errorf ( "unsupported onedrive link host: %s" , p . Host )
231240 }
232241 p .RawQuery = q .Encode ()
233242 return p .String (), nil
You can’t perform that action at this time.
0 commit comments