mod_compact_resource/mod_compact_resource.lua
author Kim Alvefur <zash@zash.se>
Sun, 25 Jun 2023 16:27:55 +0200
changeset 5575 ca3c2d11823c
parent 1765 6f34e51a23f0
permissions -rw-r--r--
mod_pubsub_feeds: Track latest timestamp seen in feeds instead of last poll This should ensure that an entry that has a publish timestmap after the previously oldest post, but before the time of the last poll check, is published to the node. Previously if an entry would be skipped if it was published at 13:00 with a timestamp of 12:30, where the last poll was at 12:45. For feeds that lack a timestamp, it now looks for the first post that is not published, assuming that the feed is in reverse chronological order, then iterates back up from there.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1765
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     1
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     2
local base64_encode = require"util.encodings".base64.encode;
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     3
local random_bytes = require"util.random".bytes;
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     4
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     5
local b64url = { ["+"] = "-", ["/"] = "_", ["="] = "" };
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     6
local function random_resource()
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     7
	return base64_encode(random_bytes(8)):gsub("[+/=]", b64url);
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     8
end
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     9
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    10
module:hook("pre-resource-bind", function (event)
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    11
	event.resource = random_resource();
6f34e51a23f0 mod_compact_resource: Enforces short random resources
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    12
end);