86 lines
3.0 KiB
Ruby
86 lines
3.0 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module YiffRestRoutes
|
||
|
DOMAIN = "yiff.rest"
|
||
|
V2 = "v2"
|
||
|
V2_DOMAIN = "#{V2}.#{DOMAIN}".freeze
|
||
|
DISCORD = "discord"
|
||
|
DISCORD_DOMAIN = "#{DISCORD}.#{DOMAIN}".freeze
|
||
|
THUMBS = "thumbs"
|
||
|
THUMBS_DOMAIN = "#{THUMBS}.#{DOMAIN}".freeze
|
||
|
STATE = "state"
|
||
|
STATE_DOMAIN = "#{STATE}.#{DOMAIN}".freeze
|
||
|
|
||
|
def self.extended(router)
|
||
|
router.instance_exec do
|
||
|
namespace(:yiff_rest, path: "") do
|
||
|
constraints(DomainConstraint.new(DOMAIN)) do
|
||
|
resources(:apikeys, only: %i[index new create destroy edit update]) do
|
||
|
get(:logout, on: :collection)
|
||
|
member do
|
||
|
post(:disable)
|
||
|
put(:enable)
|
||
|
put(:deactivate)
|
||
|
put(:reactivate)
|
||
|
put(:regenerate)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
namespace(:home, path: "") do
|
||
|
get(:manifest, constraints: { format: "json" })
|
||
|
get(:browserconfig, constraints: { format: "xml" })
|
||
|
end
|
||
|
|
||
|
get("/V2/(*category)", action: :index, controller: "api_v2")
|
||
|
root(to: "home#index")
|
||
|
end
|
||
|
|
||
|
constraints(DomainConstraint.new(DOMAIN, STATE)) do
|
||
|
namespace(:state, path: "") do
|
||
|
get(:manifest, constraints: { format: "json" })
|
||
|
get(:browserconfig, constraints: { format: "xml" })
|
||
|
end
|
||
|
|
||
|
root(to: "state#index", as: :state_index)
|
||
|
end
|
||
|
|
||
|
constraints(DomainConstraint.new(DOMAIN, V2)) do
|
||
|
namespace(:api_v2, path: "") do
|
||
|
get("/", to: redirect("https://yiff.rest"))
|
||
|
get(:robots, constraints: { format: "txt" })
|
||
|
get(:state, to: redirect("https://state.yiff.rest"))
|
||
|
get(:online)
|
||
|
get(:stats)
|
||
|
get(:categories)
|
||
|
get("/categories/(*category)", action: :category, as: :api_v2_category, constraints: { category: /[a-z0-9\-.]+/i })
|
||
|
get("/images/:id", action: :image, as: :api_v2_image, constraints: { id: /[a-f0-9]{32}/ })
|
||
|
post(:bulk, constraints: { format: "json" }, defaults: { format: :json })
|
||
|
get("/(*category)", action: :index, as: :api_v2_images)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
constraints(DomainConstraint.new(DOMAIN, DISCORD)) do
|
||
|
namespace(:discord, path: "") do
|
||
|
get(:count_servers)
|
||
|
get(:flags)
|
||
|
get(:apikey)
|
||
|
post(:interactions)
|
||
|
end
|
||
|
|
||
|
root(to: "discord#index", as: :discord_root)
|
||
|
end
|
||
|
|
||
|
constraints(DomainConstraint.new(DOMAIN, THUMBS)) do
|
||
|
namespace(:thumbs, path: "") do
|
||
|
get("/:id", action: :show, as: :thumbs_show, constraints: { id: /[a-f0-9]{32}|\d+/ })
|
||
|
put("/:id/:type", action: :create, as: :thumbs_create, constraints: { id: /[a-f0-9]{32}|\d+/, type: /gif|png/ })
|
||
|
get("/check/:id/:type", action: :check, as: :thumbs_check, constraints: { md5: /[a-f0-9]{32}/, type: /gif|png/ })
|
||
|
end
|
||
|
|
||
|
root(to: redirect("https://docs.yiff.rest/thumbnails"), as: :thumbs_root)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|