[Files Refactor] Object file management (#2790)

* Add Make Primary file function
* Add delete file functionality
This commit is contained in:
WithoutPants
2022-10-06 14:50:06 +11:00
committed by GitHub
parent 83359b00d5
commit ef9e138a2d
22 changed files with 759 additions and 106 deletions

View File

@@ -110,6 +110,32 @@ func (r *mutationResolver) imageUpdate(ctx context.Context, input ImageUpdateInp
}
updatedImage.Organized = translator.optionalBool(input.Organized, "organized")
if input.PrimaryFileID != nil {
primaryFileID, err := strconv.Atoi(*input.PrimaryFileID)
if err != nil {
return nil, fmt.Errorf("converting primary file id: %w", err)
}
converted := file.ID(primaryFileID)
updatedImage.PrimaryFileID = &converted
if err := i.LoadFiles(ctx, r.repository.Image); err != nil {
return nil, err
}
// ensure that new primary file is associated with scene
var f *file.ImageFile
for _, ff := range i.Files.List() {
if ff.ID == converted {
f = ff
}
}
if f == nil {
return nil, fmt.Errorf("file with id %d not associated with image", converted)
}
}
if translator.hasField("gallery_ids") {
updatedImage.GalleryIDs, err = translateUpdateIDs(input.GalleryIds, models.RelationshipUpdateModeSet)
if err != nil {