feat: set raw url in get resp

This commit is contained in:
Noah Hsu 2022-06-29 16:23:31 +08:00
parent 40548926e6
commit bf950ee6e1
2 changed files with 32 additions and 8 deletions

View File

@ -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 {

View File

@ -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"
@ -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(),
@ -154,6 +179,6 @@ func FsGet(c *gin.Context) {
Modified: obj.ModTime(),
Sign: common.Sign(obj),
},
// TODO: set raw url
RawURL: rawURL,
})
}