diff options
Diffstat (limited to 'server.lua')
-rw-r--r-- | server.lua | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -64,13 +64,14 @@ return function(env) txn_id = tonumber(env.HTTP_X_ACF_TRANSACTION_ID) end - local txn + local parent_txn if txn_id then - txn = txns[txn_id] - if not txn then + parent_txn = txns[txn_id] + if not parent_txn then return wrap(400, nil, 'Invalid transaction ID') end - else txn = acf.transaction.start() end + end + local txn = acf.transaction.start(parent_txn, true) local function fetch_user(name) user = name and txn:search('/auth/users')[name] @@ -150,7 +151,7 @@ return function(env) elseif method == 'PUT' then parent[name] = data else return 405 end - if not txn_id then txn:commit() end + txn:commit() return 205 end @@ -159,21 +160,18 @@ return function(env) return 301, {['Location']='/browser/'} end - if not ({DELETE=true, POST=true})[method] then - return 405 - end - - if txn_id then - if method == 'POST' then txn:commit() end + if ({DELETE=true, PUT=true})[method] then + if not txn_id then return 405 end + if method == 'PUT' then parent_txn:commit() end txns[txn_id] = nil return 204 end - if method == 'DELETE' then return 405 end + if method ~= 'POST' then return 405 end last_txn_id = last_txn_id + 1 local txn_id = last_txn_id - txns[txn_id] = txn + txns[txn_id] = acf.transaction.start(parent_txn) return 204, {['X-ACF-Transaction-ID']=txn_id} end |