diff --git a/src/backend.lua b/src/backend.lua index 2999504..e863c52 100644 --- a/src/backend.lua +++ b/src/backend.lua @@ -52,11 +52,12 @@ return end -logger:info("Configuration loaded. Indexing chests") +logger:info("Configuration loaded. Waiting for chests to be indexed.") + +os.pullEvent("kristify:storageRefreshed") local storage = ctx.storage -storage.refreshStorage(true) -logger:info("Chests indexed.") +logger:info("Chests indexed according to frontend.") local ws = kristly.websocket(config.pkey) diff --git a/src/frontend.lua b/src/frontend.lua index be80c11..2d5370c 100644 --- a/src/frontend.lua +++ b/src/frontend.lua @@ -2,11 +2,13 @@ local storage = ctx.storage local basalt = {} -if not fs.exists(fs.combine(ctx.path.src, "lib","basalt")) then - local authenticate = _G._GIT_API_KEY and {Authorization = "Bearer ".._G._GIT_API_KEY} - local basaltDL,err,errCode = http.get("https://raw.githubusercontent.com/Kristify/kristify/main/src/libs/basalt.lua", authenticate) +if not fs.exists(fs.combine(ctx.path.src, "lib", "basalt")) then + local authenticate = _G._GIT_API_KEY and { Authorization = "Bearer " .. _G._GIT_API_KEY } + local basaltDL, err, errCode = http.get("https://raw.githubusercontent.com/Kristify/kristify/main/src/libs/basalt.lua" + , authenticate) if not basaltDL then - ctx.logger:error("Couldn't load Basalt into memory! Reason: \'"..err.."\' (code "..errCode.getResponseCode()..')') + ctx.logger:error("Couldn't load Basalt into memory! Reason: \'" .. + err .. "\' (code " .. errCode.getResponseCode() .. ')') return end @@ -118,7 +120,12 @@ -- Events basalt.onEvent(function(event) if event == "kstUpdateProducts" then + ctx.logger:debug("Received event: kstUpdateProducts. Will refresh cache") + storage.refreshStorage(true) + + os.queueEvent("kristify:storageRefreshed") + local body = searchObject(base, "_body") -- Clear repeat