File

mod_pubsub_get/mod_pubsub_get.lua @ 6299:611380cfad75

mod_csi_grace_period: Readme Fix Tab at beginning of line diff --git a/mod_csi_grace_period/README.md b/mod_csi_grace_period/README.md --- a/mod_csi_grace_period/README.md +++ b/mod_csi_grace_period/README.md @@ -16,9 +16,9 @@ pocket is not the best use of radio time Works with [mod_csi_simple][doc:modules:mod_csi_simple] which is included with Prosody. - ------- ------- - trunk* Works - 13 Works - 0.12 Works + ------- ------- + trunk* Works + 13 Works + 0.12 Works - *as of 2025-06-13 + *as of 2025-06-13
author Menel <menel@snikket.de>
date Fri, 13 Jun 2025 10:08:21 +0200
parent 6204:119c0eb65bf3
line wrap: on
line source

module:depends("http")
local pubsub_service = module:depends("pubsub").service
local json = require "util.json"

function handle_GET(event)
	local request, response = event.request, event.response
	local query = request.url.query

	if query:sub(1, 5) ~= "node=" then return 400 end

	local node = query:sub(6)
	local ok, items = pubsub_service:get_items(node, true)

	if not ok then return 404 end
	response.status_code = 200
	return json.encode(items)
end

module:provides("http", {route = {GET = handle_GET}})