Skip to content

Commit

Permalink
feat(onedrive): custom host for download link (close #5310)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Oct 2, 2023
1 parent e895801 commit 0fd5164
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion drivers/onedrive/driver.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"path"

"github.com/alist-org/alist/v3/drivers/base"
Expand Down Expand Up @@ -57,8 +58,17 @@ func (d *Onedrive) Link(ctx context.Context, file model.Obj, args model.LinkArgs
if f.File == nil {
return nil, errs.NotFile
}
u := f.Url
if d.CustomHost != "" {
_u, err := url.Parse(f.Url)
if err != nil {
return nil, err
}
_u.Host = d.CustomHost
u = _u.String()
}
return &model.Link{
URL: f.Url,
URL: u,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions drivers/onedrive/meta.go
Expand Up @@ -15,6 +15,7 @@ type Addition struct {
RefreshToken string `json:"refresh_token" required:"true"`
SiteId string `json:"site_id"`
ChunkSize int64 `json:"chunk_size" type:"number" default:"5"`
CustomHost string `json:"custom_host" help:"Custom host for onedrive download link"`
}

var config = driver.Config{
Expand Down
12 changes: 11 additions & 1 deletion drivers/onedrive_app/driver.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"path"

"github.com/alist-org/alist/v3/drivers/base"
Expand Down Expand Up @@ -57,8 +58,17 @@ func (d *OnedriveAPP) Link(ctx context.Context, file model.Obj, args model.LinkA
if f.File == nil {
return nil, errs.NotFile
}
u := f.Url
if d.CustomHost != "" {
_u, err := url.Parse(f.Url)
if err != nil {
return nil, err
}
_u.Host = d.CustomHost
u = _u.String()
}
return &model.Link{
URL: f.Url,
URL: u,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions drivers/onedrive_app/meta.go
Expand Up @@ -13,6 +13,7 @@ type Addition struct {
TenantID string `json:"tenant_id"`
Email string `json:"email"`
ChunkSize int64 `json:"chunk_size" type:"number" default:"5"`
CustomHost string `json:"custom_host" help:"Custom host for onedrive download link"`
}

var config = driver.Config{
Expand Down

1 comment on commit 0fd5164

@AlexEisie
Copy link

@AlexEisie AlexEisie commented on 0fd5164 Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

host proxy with nginx configuration for reference:

server {
listen 443 ssl http2;
server_name [your proxy host];
ssl_certificate [domain cer];
ssl_certificate_key [domain key];
resolver 8.8.8.8; #optional
location / {
proxy_pass https://[cumstomed onedrive domain].sharepoint.com;
}
}

Please sign in to comment.