Skip to content

Commit

Permalink
use shared constant for MAX_PAGE_SIZE in api and lavinmqctl
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorerlingsson committed Jan 10, 2025
1 parent 6e2b3a8 commit e4b58a5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lavinmq/http/constants.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module LavinMQ
module HTTP
INTERNAL_UNIX_SOCKET = "/tmp/lavinmqctl.sock"
MAX_PAGE_SIZE = 10_000
end
end
4 changes: 1 addition & 3 deletions src/lavinmq/http/controller.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ module LavinMQ
value[:name]? || value["name"]?
end

MAX_PAGE_SIZE = 10_000

private def page(context, iterator : Iterator(SortableJSON))
params = context.request.query_params
page = params["page"]?.try(&.to_i) || 1
page_size = params["page_size"]?.try(&.to_i) || 100
if page_size > MAX_PAGE_SIZE
context.response.status_code = 413
{error: "payload_too_large", reason: "Max allowed page_size 10000"}.to_json(context.response)
{error: "payload_too_large", reason: "Max allowed page_size #{MAX_PAGE_SIZE}"}.to_json(context.response)
return context
end
iterator = iterator.map do |i|
Expand Down
6 changes: 2 additions & 4 deletions src/lavinmqctl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,8 @@ class LavinMQCtl
URI.encode_www_form(@options["vhost"])
end

MAX_PAGE_SIZE = 10_000

private def get(url, page = 1, items = [] of JSON::Any)
resp = http.get("#{url}?page=#{page}&page_size=#{MAX_PAGE_SIZE}", @headers)
private def get(url, page = 1, items = Array(JSON::Any).new)
resp = http.get("#{url}?page=#{page}&page_size=#{LavinMQ::HTTP::MAX_PAGE_SIZE}", @headers)
handle_response(resp, 200)
if data = JSON.parse(resp.body).as_h?
items += data["items"].as_a
Expand Down

0 comments on commit e4b58a5

Please sign in to comment.