MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / buildFSGetRawURL

Function buildFSGetRawURL

server/mcp/fs_get.go:116–154  ·  view source on GitHub ↗
(ctx context.Context, c *gin.Context, reqPath string, obj model.Obj, meta *model.Meta)

Source from the content-addressed store, hash-verified

114}
115
116func buildFSGetRawURL(ctx context.Context, c *gin.Context, reqPath string, obj model.Obj, meta *model.Meta) (string, string, error) {
117 storage, storageErr := fs.GetStorage(reqPath, &fs.GetStoragesArgs{})
118 provider, ok := model.GetProvider(obj)
119 if !ok && storageErr == nil {
120 provider = storage.Config().Name
121 }
122 if obj.IsDir() {
123 return "", provider, nil
124 }
125 if storageErr != nil {
126 return "", provider, storageErr
127 }
128
129 if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
130 rawURL := common.GenerateDownProxyURL(storage.GetStorage(), reqPath)
131 if rawURL != "" {
132 return rawURL, provider, nil
133 }
134 query := ""
135 if isEncrypt(meta, reqPath) || setting.GetBool(conf.SignAll) {
136 query = "?sign=" + sign.Sign(reqPath)
137 }
138 return fmt.Sprintf("%s/p%s%s", common.GetApiUrl(ctx), utils.EncodePath(reqPath, true), query), provider, nil
139 }
140
141 if url, ok := model.GetUrl(obj); ok {
142 return url, provider, nil
143 }
144 link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{
145 IP: c.ClientIP(),
146 Header: c.Request.Header,
147 Redirect: true,
148 })
149 if err != nil {
150 return "", provider, err
151 }
152 defer link.Close()
153 return link.URL, provider, nil
154}
155
156func filterRelatedObjs(objs []model.Obj, obj model.Obj) []model.Obj {
157 related := make([]model.Obj, 0)

Callers 1

callFSGetMethod · 0.85

Calls 15

GetStorageFunction · 0.92
GetProviderFunction · 0.92
GenerateDownProxyURLFunction · 0.92
GetBoolFunction · 0.92
SignFunction · 0.92
GetApiUrlFunction · 0.92
EncodePathFunction · 0.92
GetUrlFunction · 0.92
LinkFunction · 0.92
MustProxyMethod · 0.80
isEncryptFunction · 0.70
ConfigMethod · 0.65

Tested by

no test coverage detected