Skip to content

Commit

Permalink
feat: add provider to obj get api
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 7, 2022
1 parent 61fa6f3 commit d6437a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/common/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions server/handles/fsread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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,
})
}

Expand Down

0 comments on commit d6437a3

Please sign in to comment.