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
|
2024-05-06 07:47:53 +00:00
|
|
|
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
|
2024-10-21 22:58:53 +00:00
|
|
|
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
|
2024-10-24 06:36:13 +00:00
|
|
|
get(:leaderboard)
|
2024-10-13 06:04:55 +00:00
|
|
|
get(:iqdb)
|
2024-10-21 22:58:53 +00:00
|
|
|
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
|
2024-05-06 07:47:53 +00:00
|
|
|
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 })
|
2024-05-06 07:47:53 +00:00
|
|
|
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)
|
2024-05-06 07:47:53 +00:00
|
|
|
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
|