aboutsummaryrefslogtreecommitdiff
path: root/src/guff/api-methods.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff/api-methods.cr')
-rw-r--r--src/guff/api-methods.cr12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/guff/api-methods.cr b/src/guff/api-methods.cr
index 598f050..859e7ce 100644
--- a/src/guff/api-methods.cr
+++ b/src/guff/api-methods.cr
@@ -27,7 +27,7 @@ module Guff
text: "Comma-separated list of tags (union)",
type: :tag_list,
required: false,
- default: "1",
+ default: "",
},
"sort": {
@@ -263,7 +263,7 @@ module Guff
slug: /^[a-z0-9\.-]+$/,
int: /^\d+$/,
int_list: /^\d+(?:,\d+)*$/,
- tag_list: /^[a-z0-9_\/ -]+(?:,[a-z0-9_\/ -]+)*$/,
+ tag_list: /^(?:[a-z0-9_\/ -]+(?:,[a-z0-9_\/ -]+)*|)$/,
sort: /^[a-z0-9_]+,(?:asc|desc)$/,
# FIXME: lock this down more
@@ -317,15 +317,17 @@ module Guff
# post methods #
################
+ NO_TAGS = [] of Array(String)
+
private def do_post_get_posts(
context : HTTP::Server::Context,
args : Hash(String, String)
)
@models.post.get_posts(
- site_id: get_site_id(context.request.headers["host"]?),
+ site_id: @models.site.to_site(context.request.headers["host"]?),
q: args["q"]? || "",
- page: args["page"]? ? args["page"].to_i : 1,
- tags: args["tags"]? ? [args["tags"].split(/,/)] : [] of Array(String),
+ tags: (args.has_key?("tags") && args["tags"].size > 0) ? [args["tags"].split(',')] : NO_TAGS,
+ page: args.has_key?("page") ? args["page"].to_i : 1,
).to_json
end