(ctx context.Context, file *ent.File, args *EntityParameters)
| 932 | } |
| 933 | |
| 934 | func (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 | |
| 984 | func (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 { |
no test coverage detected