uploads: allow searching uploads and media assets by metatag.
Allow searching the /uploads and /media_assets pages by the following metatags: * id: * md5: * width: * height: * duration: * mpixels: * ratio: * filesize: * filetype: * date: * age: * status:<processing|active|deleted|expunged|failed> (for /media_assets) * status:<pending|processing|active|failed> (for /uploads) * is:<filetype>, is:<status> * exif: Examples: * https://betabooru.donmai.us/media_assets?search[ai_tags_match]=filetype:png * https://betabooru.donmai.us/uploads?search[ai_tags_match]=filetype:png Note that in /uploads search, the id:, date:, and age: metatags refer to the upload media asset, not the upload itself. Note also that uploads may contain multiple assets, so for example searching uploads by `filetype:png` will return all uploads containing at least one PNG file, even if they contain other non-PNG files.
This commit is contained in:
@@ -1284,17 +1284,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def exif_matches(string)
|
||||
# string = exif:File:ColorComponents=3
|
||||
if string.include?("=")
|
||||
key, value = string.split(/=/, 2)
|
||||
hash = { key => value }
|
||||
metadata = MediaMetadata.joins(:media_asset).where_json_contains(:metadata, hash)
|
||||
# string = exif:File:ColorComponents
|
||||
else
|
||||
metadata = MediaMetadata.joins(:media_asset).where_json_has_key(:metadata, string)
|
||||
end
|
||||
|
||||
where(md5: metadata.select(:md5))
|
||||
where(md5: MediaAsset.exif_matches(string).select(:md5))
|
||||
end
|
||||
|
||||
def ai_tags_include(value, default_confidence: ">=50")
|
||||
|
||||
Reference in New Issue
Block a user