From d6437a337f378b68fa8730dc526dd3b5b5583a07 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Mon, 8 Aug 2022 00:58:32 +0800 Subject: [PATCH] feat: add provider to obj get api --- server/common/base.go | 2 +- server/handles/fsread.go | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/server/common/base.go b/server/common/base.go index 333e42e9fc7..6172a1d3be4 100644 --- a/server/common/base.go +++ b/server/common/base.go @@ -16,7 +16,7 @@ func GetBaseUrl(r *http.Request) string { protocol = "https" } if baseUrl == "" { - baseUrl = fmt.Sprintf("%s//%s", protocol, r.Host) + baseUrl = fmt.Sprintf("%s://%s", protocol, r.Host) } strings.TrimSuffix(baseUrl, "/") return baseUrl diff --git a/server/handles/fsread.go b/server/handles/fsread.go index b483ce8b72a..5def2f018d1 100644 --- a/server/handles/fsread.go +++ b/server/handles/fsread.go @@ -197,9 +197,10 @@ type FsGetOrLinkReq struct { type FsGetResp struct { ObjResp - RawURL string `json:"raw_url"` - Readme string `json:"readme"` - Related []string `json:"related"` + RawURL string `json:"raw_url"` + Readme string `json:"readme"` + Provider string `json:"provider"` + Related []string `json:"related"` } func FsGet(c *gin.Context) { @@ -228,12 +229,21 @@ func FsGet(c *gin.Context) { return } var rawURL string + + storage, err := fs.GetStorage(req.Path) + provider := "unknown" + if err == nil { + provider = storage.Config().Name + } // file have raw url if !obj.IsDir() { if u, ok := obj.(model.URL); ok { rawURL = u.URL() } else { - storage, _ := fs.GetStorage(req.Path) + if err != nil { + common.ErrorResp(c, err, 500) + return + } if storage.Config().MustProxy() || storage.GetStorage().WebProxy { if storage.GetStorage().DownProxyUrl != "" { rawURL = fmt.Sprintf("%s%s?sign=%s", strings.Split(storage.GetStorage().DownProxyUrl, "\n")[0], req.Path, sign.Sign(obj.GetName())) @@ -265,9 +275,10 @@ func FsGet(c *gin.Context) { Sign: common.Sign(obj), Type: utils.GetFileType(obj.GetName()), }, - RawURL: rawURL, - Readme: getReadme(meta, req.Path), - Related: related, + RawURL: rawURL, + Readme: getReadme(meta, req.Path), + Provider: provider, + Related: related, }) }