post regenerations: replace PostRegeneration model with mod actions.
* Remove the PostRegeneration model. Instead just use a mod action to log when a post is regenerated. * Change it so that IQDB is also updated when the image samples are regenerated. This is necessary because when the images samples are regenerated, the thumbnail may change, which means IQDB needs to be updated too. This can happen when regenerating old images with transparent backgrounds where the transparency was flattened to black instead of white in the thumbnail. * Only display one "Regenerate image" option in the post sidebar, to regenerate both the images and IQDB. Regenerating IQDB only can be done through the API. Having two options in the sidebar is too much clutter, and it's too confusing for Mods who don't know the difference between an IQDB-only regeneration and a full image regeneration. * Add a confirm prompt to the "Regenerate image" link.
This commit is contained in:
@@ -29,6 +29,8 @@ class ModAction < ApplicationRecord
|
||||
post_unban: 45,
|
||||
post_permanent_delete: 46,
|
||||
post_move_favorites: 47,
|
||||
post_regenerate: 48,
|
||||
post_regenerate_iqdb: 49,
|
||||
pool_delete: 62,
|
||||
pool_undelete: 63,
|
||||
artist_ban: 184,
|
||||
|
||||
@@ -1325,6 +1325,22 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
concerning :RegenerationMethods do
|
||||
def regenerate!(category, user)
|
||||
if category == "iqdb"
|
||||
update_iqdb_async
|
||||
|
||||
ModAction.log("<@#{user.name}> regenerated IQDB for post ##{id}", :post_regenerate_iqdb, user)
|
||||
else
|
||||
media_file = MediaFile.open(file, frame_data: pixiv_ugoira_frame_data)
|
||||
UploadService::Utils.process_resizes(self, nil, id, media_file: media_file)
|
||||
update_iqdb_async
|
||||
|
||||
ModAction.log("<@#{user.name}> regenerated image samples for post ##{id}", :post_regenerate, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module IqdbMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
class PostRegeneration < ApplicationRecord
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :post
|
||||
|
||||
validates :category, inclusion: %w[iqdb resizes]
|
||||
|
||||
module SearchMethods
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :creator, :post)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
|
||||
def execute_category_action!
|
||||
if category == "iqdb"
|
||||
post.update_iqdb_async
|
||||
elsif category == "resizes"
|
||||
media_file = MediaFile.open(post.file, frame_data: post.pixiv_ugoira_frame_data)
|
||||
UploadService::Utils.process_resizes(post, nil, post.id, media_file: media_file)
|
||||
else
|
||||
# should never happen
|
||||
raise Error, "Unknown category: #{category}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.searchable_includes
|
||||
[:creator, :post]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user