-
-
Save Lintzmaia/2b1e09fd747b56b3bbe9b7a1af9ca09f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local nk = require("nakama") | |
local function AppendTable(context, payload) | |
local user_id = "removed-for-sharing-on-gist" -- some user ID. | |
local json = nk.json_decode(payload) | |
local listWrapper = nk.json_decode(json.value) | |
local object_ids = { | |
{collection = json.collection, key = json.key, user_id = user_id} | |
} | |
local objects = nk.storage_read(object_ids) | |
for _, r in ipairs(objects) | |
do | |
local storagaTable = nk.json_decode(r.value).List | |
for _, v in iparis(storagaTable) | |
do | |
table.insert(listWrapper.List, v) | |
end | |
local new_objects = { | |
{collection = json.collection, key = json.key, user_id = user_id, value = nk.json_encode(listWrapper), permission_read = 2, permission_write = 1} | |
} | |
nk.storage_write(new_objects) | |
return "Appended" | |
end | |
return "Failed to append. Payload: " .. nk.json_encode(value) .. " On Storage: " .. nk.json_encode(r.value) | |
end | |
nk.register_rpc(AppendTable, "append_object") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment