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