Fix handling of files to delete during delete Gallery operation (#5213)

* Only remove file in zip from image if deleting from zip file
* Only remove file in folder from image if deleting from folder
This commit is contained in:
WithoutPants
2024-09-05 11:27:31 +10:00
committed by GitHub
parent 7a2e59fcef
commit ad17e7defe
8 changed files with 136 additions and 99 deletions

View File

@@ -997,6 +997,21 @@ func (qb *ImageStore) AddFileID(ctx context.Context, id int, fileID models.FileI
return imagesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []models.FileID{fileID})
}
// RemoveFileID removes the file ID from the image.
// If the file ID is the primary file, then the next file in the list is set as the primary file.
func (qb *ImageStore) RemoveFileID(ctx context.Context, id int, fileID models.FileID) error {
fileIDs, err := imagesFilesTableMgr.get(ctx, id)
if err != nil {
return fmt.Errorf("getting file IDs for image %d: %w", id, err)
}
fileIDs = sliceutil.Filter(fileIDs, func(f models.FileID) bool {
return f != fileID
})
return imagesFilesTableMgr.replaceJoins(ctx, id, fileIDs)
}
func (qb *ImageStore) GetGalleryIDs(ctx context.Context, imageID int) ([]int, error) {
return imageRepository.galleries.getIDs(ctx, imageID)
}