[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

@@ -194,6 +194,32 @@ func (r *mutationResolver) galleryUpdate(ctx context.Context, input models.Galle
}
updatedGallery.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)
updatedGallery.PrimaryFileID = &converted
if err := originalGallery.LoadFiles(ctx, r.repository.Gallery); err != nil {
return nil, err
}
// ensure that new primary file is associated with scene
var f file.File
for _, ff := range originalGallery.Files.List() {
if ff.Base().ID == converted {
f = ff
}
}
if f == nil {
return nil, fmt.Errorf("file with id %d not associated with gallery", converted)
}
}
if translator.hasField("performer_ids") {
updatedGallery.PerformerIDs, err = translateUpdateIDs(input.PerformerIds, models.RelationshipUpdateModeSet)
if err != nil {