uploads: refactor /uploads/:id page for multi-file uploads.

This commit is contained in:
evazion
2022-02-13 16:55:26 -06:00
parent 229759cc72
commit bdf83d1ffd
12 changed files with 150 additions and 116 deletions

View File

@@ -74,7 +74,10 @@ class Post < ApplicationRecord
has_many :versions, -> { Rails.env.test? ? order("post_versions.updated_at ASC, post_versions.id ASC") : order("post_versions.updated_at ASC") }, class_name: "PostVersion", dependent: :destroy
end
def self.new_from_upload(upload, media_asset, tag_string: nil, rating: nil, parent_id: nil, source: nil, artist_commentary_title: nil, artist_commentary_desc: nil, translated_commentary_title: nil, translated_commentary_desc: nil, is_pending: nil)
def self.new_from_upload(upload_media_asset, tag_string: nil, rating: nil, parent_id: nil, source: nil, artist_commentary_title: nil, artist_commentary_desc: nil, translated_commentary_title: nil, translated_commentary_desc: nil, is_pending: nil, add_artist_tag: false)
upload = upload_media_asset.upload
media_asset = upload_media_asset.media_asset
# XXX depends on CurrentUser
commentary = ArtistCommentary.new(
original_title: artist_commentary_title,
@@ -83,6 +86,11 @@ class Post < ApplicationRecord
translated_description: translated_commentary_desc,
)
if add_artist_tag
tag_string = "#{tag_string} #{upload_media_asset.source_strategy&.artists.to_a.map(&:tag).map(&:name).join(" ")}".strip
tag_string += " " if tag_string.present?
end
post = Post.new(
uploader: upload.uploader,
uploader_ip_addr: upload.uploader_ip_addr,

View File

@@ -1,8 +1,6 @@
# frozen_string_literal: true
class Upload < ApplicationRecord
extend Memoist
attr_accessor :file
belongs_to :uploader, class_name: "User"
@@ -45,6 +43,10 @@ class Upload < ApplicationRecord
def is_errored?
status == "error"
end
def is_finished?
is_completed? || is_errored?
end
end
concerning :ValidationMethods do
@@ -65,11 +67,6 @@ class Upload < ApplicationRecord
Addressable::URI.normalized_encode(url)
end
end
def source_strategy
return nil if source.blank?
Sources::Strategies.find(source, referer_url)
end
end
def self.search(params)
@@ -116,6 +113,4 @@ class Upload < ApplicationRecord
def self.available_includes
[:uploader, :upload_media_assets, :media_assets]
end
memoize :source_strategy
end

View File

@@ -1,6 +1,8 @@
# frozen_string_literal: true
class UploadMediaAsset < ApplicationRecord
extend Memoist
belongs_to :upload
belongs_to :media_asset, optional: true
@@ -23,4 +25,15 @@ class UploadMediaAsset < ApplicationRecord
q = search_attributes(params, :id, :created_at, :updated_at, :status, :source_url, :page_url, :error, :upload, :media_asset)
q.apply_default_order(params)
end
def finished?
active? || failed?
end
def source_strategy
return nil if source_url.blank?
Sources::Strategies.find(source_url, page_url)
end
memoize :source_strategy
end