Donovan Daniels
b1c702e3cd
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
95 lines
3.4 KiB
Ruby
95 lines
3.4 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") # TODO: make routes case insensitive
|
|
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
|
|
resources(:manage, constraints: { id: /[a-z0-9\-.]+/i }, only: %i[index]) do
|
|
collection do
|
|
get(:logout)
|
|
put(:sync)
|
|
resources(:images, as: "manage_images")
|
|
end
|
|
end
|
|
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, constraints: { category: /(?!rails).*/ })
|
|
end
|
|
end
|
|
|
|
constraints(DomainConstraint.new(DOMAIN, DISCORD)) do
|
|
namespace(:discord, path: "") do
|
|
get(:count_servers)
|
|
get(:flags)
|
|
get(:apikey)
|
|
get(:manage_images)
|
|
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
|