changes
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
--[[
|
||||
ME system uploader for ComputerCraft (CC: Tweaked).
|
||||
Storage system uploader for ComputerCraft (CC: Tweaked).
|
||||
|
||||
Requires an "ME Bridge" peripheral (Advanced Peripherals) connected to the
|
||||
computer and wired to an Applied Energistics 2 / Refined Storage network.
|
||||
Works with both Advanced Peripherals bridges:
|
||||
* "meBridge" -> Applied Energistics 2 (listItems / item.amount)
|
||||
* "rsBridge" -> Refined Storage (getItems / item.count)
|
||||
|
||||
It periodically reads the network contents and POSTs them to the backend's
|
||||
Periodically reads the network contents and POSTs them to the backend's
|
||||
/api/me-system/update endpoint.
|
||||
|
||||
NOTE: the backend serves HTTPS with a self-signed certificate by default.
|
||||
@@ -14,25 +15,55 @@
|
||||
* terminate TLS with a proxy that uses a certificate CC trusts.
|
||||
]]
|
||||
|
||||
local API_URL = "http://your-server:3000/api/me-system/update"
|
||||
local API_URL = "https://192.168.2.150:3000/api/me-system/update"
|
||||
local INTERVAL = 10 -- seconds between uploads
|
||||
|
||||
-- Resolve the bridge peripheral and pick the right method for it.
|
||||
local bridge = peripheral.find("meBridge")
|
||||
local listFn
|
||||
if bridge then
|
||||
listFn = "listItems"
|
||||
else
|
||||
bridge = peripheral.find("rsBridge")
|
||||
if bridge then
|
||||
listFn = "getItems"
|
||||
end
|
||||
end
|
||||
if not bridge then
|
||||
error("No ME Bridge peripheral found")
|
||||
error("No meBridge or rsBridge peripheral found")
|
||||
end
|
||||
if type(bridge[listFn]) ~= "function" then
|
||||
error("Bridge peripheral does not expose " .. listFn .. "()")
|
||||
end
|
||||
|
||||
local function cleanDisplayName(raw)
|
||||
if type(raw) ~= "string" then return nil end
|
||||
-- ME/RS display names are wrapped in [brackets] — strip them.
|
||||
return (raw:gsub("[%[%]]", ""))
|
||||
end
|
||||
|
||||
-- Bridges report the same item id once per storage cell. Merge the rows here
|
||||
-- so the backend receives a clean snapshot.
|
||||
local function collect()
|
||||
local items = bridge.listItems()
|
||||
local payload = {}
|
||||
local items = bridge[listFn](bridge)
|
||||
local byName = {}
|
||||
local order = {}
|
||||
for _, item in ipairs(items) do
|
||||
payload[#payload + 1] = {
|
||||
name = item.name,
|
||||
amount = item.amount or item.count or 0,
|
||||
displayName = item.displayName,
|
||||
}
|
||||
local amount = item.amount or item.count or 0
|
||||
local entry = byName[item.name]
|
||||
if entry then
|
||||
entry.amount = entry.amount + amount
|
||||
else
|
||||
entry = {
|
||||
name = item.name,
|
||||
amount = amount,
|
||||
displayName = cleanDisplayName(item.displayName),
|
||||
}
|
||||
byName[item.name] = entry
|
||||
order[#order + 1] = entry
|
||||
end
|
||||
end
|
||||
return payload
|
||||
return order
|
||||
end
|
||||
|
||||
local function upload(payload)
|
||||
@@ -48,7 +79,9 @@ local function upload(payload)
|
||||
response.close()
|
||||
end
|
||||
|
||||
print("ME uploader started. Target: " .. API_URL)
|
||||
print("Storage uploader started.")
|
||||
print(" Bridge: " .. listFn)
|
||||
print(" Target: " .. API_URL)
|
||||
while true do
|
||||
local ok, payload = pcall(collect)
|
||||
if ok then
|
||||
|
||||
Reference in New Issue
Block a user