Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# Redirect on create and json error #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions actions/create_document.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ end

contentdb.write_file (store, id or document_uuid, fields, request.body.body)

local redirect = "<!DOCTYPE html><html><head><meta http-equiv=\"refresh\" content=\"0; URL='/".. fields['model'] .."/'\" /></head></html>"

return {
headers = {
["content-type"] = "application/json",
["content-type"] = "text/html",
["X-Request-ID"] = request.uuid
},
body = json.from_table(params)
body = redirect
}
28 changes: 19 additions & 9 deletions actions/list_documents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@ priority = 1
input_parameters = ["request"]

-- GET /[type]/[uuid]

local model_name = request.path_segments[1]

local uuids = {}

contentdb.walk_documents(nil, function (file_uuid, header, body)
if fields.model ~= model_name then return end
-- Filter the documents using the query params
for k, v in pairs(request.query) do
if header[k] ~= v then
-- Don't add this document to the list
return

contentdb.walk_documents(nil,
function (file_uuid, fields, body, store)
if fields.model ~= model_name then return end

-- Filter the documents using the query params
for k, v in pairs(request.query) do
if fields[k] ~= v then
-- Don't add this document to the list
return
end
end

table.insert(uuids, {
name = fields.name or fields.title,
uuid = file_uuid,
store = store
})
end
)

table.insert(uuids, file_uuid)
end)

return {
headers = {
Expand Down
3 changes: 1 addition & 2 deletions actions/list_subdocuments.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ contentdb.walk_documents(nil, function (doc_id, fields, body)
end)



if #uuids == 0 then uuids = nil end

return {
headers = {
["content-type"] = "text/html",
["content-type"] = "application/json",
},
body = json.from_table({
base_model = base_model,
Expand Down