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

Method callFSGet

server/mcp/fs_get.go:29–99  ·  view source on GitHub ↗
(c *gin.Context, raw json.RawMessage)

Source from the content-addressed store, hash-verified

27}
28
29func (s *Server) callFSGet(c *gin.Context, raw json.RawMessage) (any, *rpcError) {
30 args, mcpErr := parseFSGetArgs(raw)
31 if mcpErr != nil {
32 return nil, mcpErr
33 }
34
35 user, ok := c.Request.Context().Value(conf.UserKey).(*model.User)
36 if !ok || user == nil {
37 return nil, &rpcError{Code: -32603, Message: "missing user context"}
38 }
39 if user.IsGuest() && user.Disabled {
40 return nil, &rpcError{Code: -32001, Message: "guest user is disabled"}
41 }
42
43 reqPath, err := user.JoinPath(args.Path)
44 if err != nil {
45 return nil, &rpcError{Code: -32003, Message: err.Error()}
46 }
47
48 meta, err := op.GetNearestMeta(reqPath)
49 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
50 return nil, &rpcError{Code: -32603, Message: err.Error()}
51 }
52 if !common.CanAccess(user, meta, reqPath, args.Password) {
53 return nil, &rpcError{Code: -32003, Message: "password is incorrect or you have no permission"}
54 }
55
56 ctx := context.WithValue(c.Request.Context(), conf.MetaKey, meta)
57 obj, err := fs.Get(ctx, reqPath, &fs.GetArgs{
58 WithStorageDetails: !user.IsGuest() && !setting.GetBool(conf.HideStorageDetails),
59 })
60 if err != nil {
61 return nil, &rpcError{Code: -32603, Message: err.Error()}
62 }
63
64 rawURL, provider, err := buildFSGetRawURL(ctx, c, reqPath, obj, meta)
65 if err != nil {
66 return nil, &rpcError{Code: -32603, Message: err.Error()}
67 }
68
69 parentPath := stdpath.Dir(reqPath)
70 var related []model.Obj
71 sameLevelFiles, err := fs.List(ctx, parentPath, &fs.ListArgs{})
72 if err == nil {
73 related = filterRelatedObjs(sameLevelFiles, obj)
74 }
75
76 parentMeta, _ := op.GetNearestMeta(parentPath)
77 thumb, _ := model.GetThumb(obj)
78 mountDetails, _ := model.GetStorageDetails(obj)
79 return handles.FsGetResp{
80 ObjResp: handles.ObjResp{
81 Name: obj.GetName(),
82 Size: obj.GetSize(),
83 IsDir: obj.IsDir(),
84 Modified: obj.ModTime(),
85 Created: obj.CreateTime(),
86 Sign: common.Sign(obj, parentPath, isEncrypt(meta, reqPath)),

Callers 1

handleToolsCallMethod · 0.95

Calls 15

GetNearestMetaFunction · 0.92
CanAccessFunction · 0.92
GetFunction · 0.92
GetBoolFunction · 0.92
ListFunction · 0.92
GetThumbFunction · 0.92
GetStorageDetailsFunction · 0.92
SignFunction · 0.92
GetFileTypeFunction · 0.92
parseFSGetArgsFunction · 0.85
buildFSGetRawURLFunction · 0.85
filterRelatedObjsFunction · 0.85

Tested by

no test coverage detected