From 66623131bdeaae3fbe4ed9eb125a471f3408be21 Mon Sep 17 00:00:00 2001 From: Bauumm Date: Mon, 5 Feb 2024 17:02:02 +0100 Subject: [PATCH] change /get_packs to not send everything --- server/web_api.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/server/web_api.lua b/server/web_api.lua index 462e213..b4353a2 100644 --- a/server/web_api.lua +++ b/server/web_api.lua @@ -118,9 +118,24 @@ app.handlers["/get_pack_preview_data/.../..."] = function(captures, headers) return json.encode(result) end -app.handlers["/get_packs"] = function(_, headers) +local pack_list = {} +app.handlers["/get_packs/.../..."] = function(captures, headers) headers["content-type"] = "application/json" - return json.encode(packs) + local start = tonumber(captures[1]) + local stop = tonumber(captures[2]) + local last_index + for i = 1, stop - start + 1 do + local index = i + start - 1 + if not packs[index] then + break + end + pack_list[i] = packs[index] + last_index = i + end + while pack_list[last_index + 1] do + pack_list[#pack_list] = nil + end + return json.encode(pack_list) end app.handlers["/get_pack/.../..."] = function(captures, headers)