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

Method Get

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

Source from the content-addressed store, hash-verified

473)
474
475func (s *SingleEntityService) Get(c *gin.Context) (*GetEntityResponse, error) {
476 dep := dependency.FromContext(c)
477 fileClient := dep.FileClient()
478 hasher := dep.HashIDEncoder()
479
480 ctx := context.WithValue(c, inventory.LoadEntityUser{}, true)
481 ctx = context.WithValue(ctx, inventory.LoadEntityStoragePolicy{}, true)
482 ctx = context.WithValue(ctx, inventory.LoadEntityFile{}, true)
483 ctx = context.WithValue(ctx, inventory.LoadFileUser{}, true)
484
485 userHashIDMap := make(map[int]string)
486 entity, err := fileClient.GetEntityByID(ctx, s.ID)
487 if err != nil {
488 if ent.IsNotFound(err) {
489 return nil, serializer.NewError(serializer.CodeNotFound, "Entity not found", nil)
490 }
491 return nil, serializer.NewError(serializer.CodeDBError, "Failed to get entity", err)
492 }
493
494 for _, file := range entity.Edges.File {
495 userHashIDMap[file.OwnerID] = hashid.EncodeUserID(hasher, file.OwnerID)
496 }
497
498 return &GetEntityResponse{
499 Entity: entity,
500 UserHashID: hashid.EncodeUserID(hasher, entity.CreatedBy),
501 UserHashIDMap: userHashIDMap,
502 }, nil
503}
504
505type (
506 BatchEntityService struct {

Callers

nothing calls this directly

Calls 7

FromContextFunction · 0.92
IsNotFoundFunction · 0.92
NewErrorFunction · 0.92
EncodeUserIDFunction · 0.92
FileClientMethod · 0.65
HashIDEncoderMethod · 0.65
GetEntityByIDMethod · 0.65

Tested by

no test coverage detected