MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / Get

Method Get

service/admin/file.go:246–280  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

244)
245
246func (service *SingleFileService) Get(c *gin.Context) (*GetFileResponse, error) {
247 dep := dependency.FromContext(c)
248 hasher := dep.HashIDEncoder()
249 fileClient := dep.FileClient()
250
251 ctx := context.WithValue(c, inventory.LoadFileEntity{}, true)
252 ctx = context.WithValue(ctx, inventory.LoadFileMetadata{}, true)
253 ctx = context.WithValue(ctx, inventory.LoadFileShare{}, true)
254 ctx = context.WithValue(ctx, inventory.LoadFileUser{}, true)
255 ctx = context.WithValue(ctx, inventory.LoadEntityUser{}, true)
256 ctx = context.WithValue(ctx, inventory.LoadEntityStoragePolicy{}, true)
257 ctx = context.WithValue(ctx, inventory.LoadFileDirectLink{}, true)
258
259 file, err := fileClient.GetByID(ctx, service.ID)
260 if err != nil {
261 if ent.IsNotFound(err) {
262 return nil, serializer.NewError(serializer.CodeNotFound, "File not found", nil)
263 }
264
265 return nil, serializer.NewError(serializer.CodeDBError, "Failed to get file", err)
266 }
267
268 directLinkMap := make(map[int]string)
269 siteURL := dep.SettingProvider().SiteURL(c)
270 for _, directLink := range file.Edges.DirectLinks {
271 directLinkMap[directLink.ID] = routes.MasterDirectLink(siteURL, hashid.EncodeSourceLinkID(hasher, directLink.ID), directLink.Name).String()
272 }
273
274 return &GetFileResponse{
275 File: file,
276 UserHashID: hashid.EncodeUserID(hasher, file.OwnerID),
277 FileHashID: hashid.EncodeFileID(hasher, file.ID),
278 DirectLinkMap: directLinkMap,
279 }, nil
280}
281
282type (
283 UpsertFileService struct {

Callers 1

UpdateMethod · 0.95

Calls 13

FromContextFunction · 0.92
IsNotFoundFunction · 0.92
NewErrorFunction · 0.92
MasterDirectLinkFunction · 0.92
EncodeSourceLinkIDFunction · 0.92
EncodeUserIDFunction · 0.92
EncodeFileIDFunction · 0.92
HashIDEncoderMethod · 0.65
FileClientMethod · 0.65
GetByIDMethod · 0.65
SiteURLMethod · 0.65
SettingProviderMethod · 0.65

Tested by

no test coverage detected