Skip to content

Commit

Permalink
Add bump cache, imageRepeat to API
Browse files Browse the repository at this point in the history
  • Loading branch information
qpfiffer committed Oct 3, 2023
1 parent 37f6fe3 commit f2eb031
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function Filters.all_bumps(text, ctext)
return table.concat(to_return)
end

local bump_cache = {}
function Filters.all_bumps_json(text, ctext)
local to_return = {}
local first = true
Expand All @@ -141,24 +142,40 @@ function Filters.all_bumps_json(text, ctext)

for line in all_bumps:lines() do
local meta_data = Utils.check_for_bump(line)
local obj = {}

local is_nsfw = false
local text = ""
local video = ""
local image = ""

if meta_data then
if bump_cache[line] then
local cached_bump = bump_cache[line]
text = cached_bump["text"]
is_nsfw = cached_bump["is_nsfw"]
video = cached_bump["video"]
image = cached_bump["image"]
elseif meta_data then
local ctext = fuck_json.decode(meta_data:read("*all"))
bump_cache[line] = {text = "", is_nsfw = false, video = "", image = ""}
if ctext["nsfw"] then
is_nsfw = ctext["nsfw"]
bump_cache[line]["nsfw"] = is_nsfw
end
if ctext["text"] then
text = ctext["text"]
bump_cache[line]["text"] = text
end
if ctext["webm"] then
video = ctext["webm"]
bump_cache[line]["video"] = video
end
if ctext["image"] then
image = ctext["image"]
bump_cache[line]["image"] = image
elseif ctext["imageRepeat"] then
image = ctext["imageRepeat"]
bump_cache[line]["image"] = image
end
meta_data:close()
end
Expand Down

0 comments on commit f2eb031

Please sign in to comment.