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

Function FsArchiveMeta

server/handles/archive.go:93–148  ·  view source on GitHub ↗
(c *gin.Context, req *ArchiveMetaReq, user *model.User)

Source from the content-addressed store, hash-verified

91}
92
93func FsArchiveMeta(c *gin.Context, req *ArchiveMetaReq, user *model.User) {
94 if !user.CanReadArchives() {
95 common.ErrorResp(c, errs.PermissionDenied, 403)
96 return
97 }
98 reqPath, err := user.JoinPath(req.Path)
99 if err != nil {
100 common.ErrorResp(c, err, 403)
101 return
102 }
103 meta, err := op.GetNearestMeta(reqPath)
104 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
105 common.ErrorResp(c, err, 500, true)
106 return
107 }
108 common.GinAppendValues(c, conf.MetaKey, meta)
109 if !common.CanAccess(user, meta, reqPath, req.Password) {
110 common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
111 return
112 }
113 archiveArgs := model.ArchiveArgs{
114 LinkArgs: model.LinkArgs{
115 Header: c.Request.Header,
116 Type: c.Query("type"),
117 },
118 Password: req.ArchivePass,
119 }
120 ret, err := fs.ArchiveMeta(c.Request.Context(), reqPath, model.ArchiveMetaArgs{
121 ArchiveArgs: archiveArgs,
122 Refresh: req.Refresh,
123 })
124 if err != nil {
125 if errors.Is(err, errs.WrongArchivePassword) {
126 common.ErrorResp(c, err, 202)
127 } else {
128 common.ErrorResp(c, err, 500)
129 }
130 return
131 }
132 s := ""
133 if isEncrypt(meta, reqPath) || setting.GetBool(conf.SignAll) {
134 s = sign.SignArchive(reqPath)
135 }
136 api := "/ae"
137 if ret.DriverProviding {
138 api = "/ad"
139 }
140 common.SuccessResp(c, ArchiveMetaResp{
141 Comment: ret.GetComment(),
142 IsEncrypted: ret.IsEncrypted(),
143 Content: toContentResp(ret.GetTree()),
144 Sort: ret.Sort,
145 RawURL: fmt.Sprintf("%s%s%s", common.GetApiUrl(c), api, utils.EncodePath(reqPath, true)),
146 Sign: s,
147 })
148}
149
150type ArchiveListReq struct {

Callers 1

FsArchiveMetaSplitFunction · 0.85

Calls 15

ErrorRespFunction · 0.92
GetNearestMetaFunction · 0.92
GinAppendValuesFunction · 0.92
CanAccessFunction · 0.92
ErrorStrRespFunction · 0.92
ArchiveMetaFunction · 0.92
GetBoolFunction · 0.92
SignArchiveFunction · 0.92
SuccessRespFunction · 0.92
GetApiUrlFunction · 0.92
EncodePathFunction · 0.92
toContentRespFunction · 0.85

Tested by

no test coverage detected