Add MediaAsset model.
A MediaAsset represents an image or video file uploaded to Danbooru. It stores the metadata associated with the image or video. This is to work on decoupling files from posts so that images can be uploaded separately from posts.
This commit is contained in:
8
app/controllers/media_assets_controller.rb
Normal file
8
app/controllers/media_assets_controller.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class MediaAssetsController < ApplicationController
|
||||
respond_to :json, :xml
|
||||
|
||||
def index
|
||||
@media_assets = authorize MediaAsset.visible(CurrentUser.user).paginated_search(params, count_pages: true)
|
||||
respond_with(@media_assets)
|
||||
end
|
||||
end
|
||||
@@ -104,6 +104,13 @@ class UploadService
|
||||
p.uploader_id = upload.uploader_id
|
||||
p.uploader_ip_addr = upload.uploader_ip_addr
|
||||
p.parent_id = upload.parent_id
|
||||
p.media_asset = MediaAsset.new(
|
||||
md5: upload.md5,
|
||||
file_ext: upload.file_ext,
|
||||
file_size: upload.file_size,
|
||||
image_width: upload.image_width,
|
||||
image_height: upload.image_height,
|
||||
)
|
||||
|
||||
if !upload.uploader.can_upload_free? || upload.upload_as_pending?
|
||||
p.is_pending = true
|
||||
|
||||
7
app/models/media_asset.rb
Normal file
7
app/models/media_asset.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class MediaAsset < ApplicationRecord
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :file_ext, :file_size, :image_width, :image_height)
|
||||
q = q.apply_default_order(params)
|
||||
q
|
||||
end
|
||||
end
|
||||
@@ -40,6 +40,7 @@ class Post < ApplicationRecord
|
||||
belongs_to :approver, class_name: "User", optional: true
|
||||
belongs_to :uploader, :class_name => "User", :counter_cache => "post_upload_count"
|
||||
belongs_to :parent, class_name: "Post", optional: true
|
||||
has_one :media_asset, foreign_key: :md5, primary_key: :md5
|
||||
has_one :upload, :dependent => :destroy
|
||||
has_one :artist_commentary, :dependent => :destroy
|
||||
has_one :pixiv_ugoira_frame_data, :class_name => "PixivUgoiraFrameData", :dependent => :destroy
|
||||
|
||||
5
app/policies/media_asset_policy.rb
Normal file
5
app/policies/media_asset_policy.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class MediaAssetPolicy < ApplicationPolicy
|
||||
def index?
|
||||
true
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user