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:
evazion
2021-09-02 06:07:52 -05:00
parent 2d976cf557
commit b068c113a8
11 changed files with 182 additions and 0 deletions
@@ -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
+7
View File
@@ -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
View 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
+1
View File
@@ -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
View File
@@ -0,0 +1,5 @@
class MediaAssetPolicy < ApplicationPolicy
def index?
true
end
end