Websites/config/routes/yiff_rest_routes.rb

110 lines
4.1 KiB
Ruby
Raw Normal View History

2024-05-03 03:04:43 +00:00
# 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" })
2024-07-23 17:38:32 +00:00
get(:support, to: redirect { Websites.config.yiffy2_discord_invite })
2024-05-03 03:04:43 +00:00
end
2024-05-03 08:32:45 +00:00
get("/v2/(*category)", action: :index, controller: "api_v2") # TODO: make routes case insensitive
2024-05-03 03:04:43 +00:00
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)
2024-05-07 06:57:00 +00:00
resources(:images, as: "manage_images") do
member do
get(:delete_with_reason)
match(:convert, via: %i[get post])
put(:toggle_viewable)
put(:update_cache)
end
2024-10-13 06:04:55 +00:00
collection do
get(:leaderboard)
2024-10-13 06:04:55 +00:00
get(:iqdb)
match("/iqdb/query", via: %i[get post], action: :query_iqdb)
2024-10-22 00:16:52 +00:00
post(:external, action: :create_external, as: "create_external")
2024-10-22 00:43:38 +00:00
get("/external/new", action: :new_external)
2024-10-13 06:04:55 +00:00
end
2024-05-07 06:57:00 +00:00
end
end
end
2024-05-03 03:04:43 +00:00
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).*/ })
2024-05-03 03:04:43 +00:00
end
end
constraints(DomainConstraint.new(DOMAIN, DISCORD)) do
namespace(:discord, path: "") do
get(:count_servers)
get(:flags)
get(:apikey)
get(:manage_images)
2024-05-03 03:04:43 +00:00
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