Add optional API key support for server authentication in inventoryWebBridge

This commit is contained in:
MayaTheShy
2026-03-22 02:35:06 -04:00
parent 5162a71be4
commit b3c3faa06d

View File

@@ -22,6 +22,7 @@ local ORDER_CHANNEL = 4201
-------------------------------------------------
local CONFIG_FILE = ".webbridge_config"
local API_KEY = nil -- optional API key for server auth
local function loadConfig()
if fs.exists(CONFIG_FILE) then
@@ -47,7 +48,6 @@ local latestState = nil -- last broadcast from master
local modem = nil
local modemName = nil
local running = true
local API_KEY = nil -- optional API key for server auth
-------------------------------------------------
-- Find modem
@@ -75,7 +75,7 @@ local function httpPost(path, body)
local headers = { ["Content-Type"] = "application/json" }
if API_KEY then headers["Authorization"] = "Bearer " .. API_KEY end
local ok, err = pcall(function()
local ok, result = pcall(function()
local response = http.post(url, data, headers)
if response then
local responseData = response.readAll()
@@ -84,10 +84,10 @@ local function httpPost(path, body)
end
end)
if not ok then
-- Silent fail, will retry
return nil
if ok then
return result
end
return nil
end
local function httpGet(path)