Skip to content

Commit

Permalink
feat: set raw url in get resp
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 29, 2022
1 parent 4054892 commit bf950ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
13 changes: 6 additions & 7 deletions internal/driver/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package driver

type Config struct {
Name string
LocalSort bool
OnlyLocal bool
OnlyProxy bool
NoNeedSetLink bool
NoCache bool
NoUpload bool
Name string
LocalSort bool
OnlyLocal bool
OnlyProxy bool
NoCache bool
NoUpload bool
}

func (c Config) MustProxy() bool {
Expand Down
27 changes: 26 additions & 1 deletion server/controllers/fsread.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package controllers

import (
"fmt"
"github.com/alist-org/alist/v3/internal/sign"
stdpath "path"
"strings"
"time"

"github.com/alist-org/alist/v3/internal/db"
Expand Down Expand Up @@ -146,6 +149,28 @@ func FsGet(c *gin.Context) {
common.ErrorResp(c, err, 500)
return
}
var rawURL string
// obj have raw url
if u, ok := obj.(model.URL); ok {
rawURL = u.URL()
} else {
account, _ := fs.GetAccount(req.Path)
if account.Config().MustProxy() || account.GetAccount().WebProxy {
if account.GetAccount().DownProxyUrl != "" {
rawURL = fmt.Sprintf("%s%s?sign=%s", strings.Split(account.GetAccount().DownProxyUrl, "\n")[0], req.Path, sign.Sign(obj.GetName()))
} else {
rawURL = fmt.Sprintf("%s/p%s?sign=%s", common.GetBaseUrl(c.Request), req.Path, sign.Sign(obj.GetName()))
}
} else {
// if account is not proxy, use raw url by fs.Link
link, _, err := fs.Link(c, req.Path, model.LinkArgs{})
if err != nil {
common.ErrorResp(c, err, 500)
return
}
rawURL = link.URL
}
}
common.SuccessResp(c, FsGetResp{
ObjResp: ObjResp{
Name: obj.GetName(),
Expand All @@ -154,6 +179,6 @@ func FsGet(c *gin.Context) {
Modified: obj.ModTime(),
Sign: common.Sign(obj),
},
// TODO: set raw url
RawURL: rawURL,
})
}

0 comments on commit bf950ee

Please sign in to comment.