Websites/app/logical/api_category.rb
Donovan Daniels b1c702e3cd
Add image management ui
poorly tested but it worked well enough, I'm sure I'll be patching bugs over the next few weeks
Also remove turbo because it sucks
Also changed the way we handle hosts in dev
2024-05-06 03:25:17 -05:00

65 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class APICategory
attr_reader :name, :db, :sfw
SOURCES = [
%w[e621.net E621],
%w[furaffinity.net FurAffinity],
%w[inkbunny.net InkBunny],
%w[deviantart.com DeviantArt],
%w[twitter.com Twitter],
].freeze
def initialize(name, db, sfw)
@name = name
@db = db
@sfw = sfw
end
def count
APIImage.cached_count(db)
end
def real_count
APIImage.where(category: db).count
end
def unsourced_count
APIImage.where(category: db, sources: []).count
end
def sources
r = APIImage.joins("CROSS JOIN unnest(sources) AS source").where(category: db).distinct
other = r
list = []
APICategory::SOURCES.each do |value, name|
count = r.where("source ILIKE ?", "%#{value}%").count
list << { name: name, count: count }
other = other.where("source NOT ILIKE ?", "%#{value}%")
end
list << { name: "Unsourced", count: unsourced_count }
# noinspection RubyMismatchedArgumentType
list << { name: "Other", count: other.count }
list
end
def created_at
APIImage.where(category: db).minimum(:created_at)
end
def updated_at
APIImage.where(category: db).maximum(:updated_at)
end
def as_json(*)
{
name: name,
db: db,
sfw: sfw,
count: count,
}
end
end