MCPcopy Index your code
hub / github.com/cloudreve/cloudreve / CreateEntity

Method CreateEntity

inventory/file.go:934–982  ·  view source on GitHub ↗
(ctx context.Context, file *ent.File, args *EntityParameters)

Source from the content-addressed store, hash-verified

932}
933
934func (f *fileClient) CreateEntity(ctx context.Context, file *ent.File, args *EntityParameters) (*ent.Entity, StorageDiff, error) {
935 createdBy := UserFromContext(ctx)
936 var opt *types.EntityProps
937 if args.EncryptMetadata != nil {
938 opt = &types.EntityProps{
939 EncryptMetadata: &types.EncryptMetadata{
940 Algorithm: args.EncryptMetadata.Algorithm,
941 Key: args.EncryptMetadata.Key,
942 IV: args.EncryptMetadata.IV,
943 },
944 }
945 }
946
947 stm := f.client.Entity.
948 Create().
949 SetType(int(args.EntityType)).
950 SetSource(args.Source).
951 SetSize(args.Size).
952 SetStoragePolicyID(args.StoragePolicyID)
953
954 if opt != nil {
955 stm.SetProps(opt)
956 }
957
958 if createdBy != nil && !IsAnonymousUser(createdBy) {
959 stm.SetUser(createdBy)
960 }
961
962 if args.ModifiedAt != nil {
963 stm.SetUpdatedAt(*args.ModifiedAt)
964 }
965
966 if args.UploadSessionID != uuid.Nil && !args.Importing {
967 stm.SetUploadSessionID(args.UploadSessionID)
968 }
969
970 created, err := stm.Save(ctx)
971 if err != nil {
972 return nil, nil, fmt.Errorf("failed to create file entity: %v", err)
973 }
974
975 diff := map[int]int64{file.OwnerID: created.Size}
976
977 if err := f.client.Entity.UpdateOne(created).AddFile(file).Exec(ctx); err != nil {
978 return nil, diff, fmt.Errorf("failed to add file entity: %v", err)
979 }
980
981 return created, diff, nil
982}
983
984func (f *fileClient) SetParent(ctx context.Context, files []*ent.File, parent *ent.File) error {
985 groups, _ := f.batchInCondition(intsets.MaxInt, 10, 1, lo.Map(files, func(file *ent.File, index int) int {

Callers 1

CreateFileMethod · 0.95

Calls 15

UserFromContextFunction · 0.85
IsAnonymousUserFunction · 0.85
SetSourceMethod · 0.65
CreateMethod · 0.65
ExecMethod · 0.65
SetStoragePolicyIDMethod · 0.45
SetSizeMethod · 0.45
SetTypeMethod · 0.45
SetPropsMethod · 0.45
SetUserMethod · 0.45
SetUpdatedAtMethod · 0.45
SetUploadSessionIDMethod · 0.45

Tested by

no test coverage detected