local maps_cache
local maps_aliases
local lua_util = require "lua_util"
+local ts = require("tableshape").types
+local ucl = require "ucl"
local function maybe_fill_maps_cache()
if not maps_cache then
}
end
+local query_json_schema = ts.shape{
+ maps = ts.array_of(ts.string):is_optional(),
+ report_misses = ts.boolean:is_optional(),
+ values = ts.array_of(ts.string),
+}
+
+local function handle_query_json(task, conn)
+ maybe_fill_maps_cache()
+
+ local parser = ucl.parser()
+ local ok, err = parser:parse_text(task:get_rawbody())
+ if not ok then
+ conn:send_error(400, err)
+ return
+ end
+ local obj = parser:get_object()
+
+ ok, err = query_json_schema:transform(obj)
+ if not ok then
+ conn:send_error(400, err)
+ return
+ end
+
+ local maps_to_check = {}
+ local report_misses = obj.report_misses
+ local results = {}
+
+ if obj.maps then
+ for _,mn in ipairs(obj.maps) do
+ if maps_cache[mn] then
+ maps_to_check[mn] = maps_cache[mn]
+ else
+ local alias = maps_aliases[mn]
+
+ if alias then
+ maps_to_check[alias] = maps_cache[alias]
+ else
+ conn:send_error(400, 'no such map: ' .. mn)
+ return
+ end
+ end
+ end
+ else
+ maps_to_check = maps_cache
+ end
+
+ for _,key in ipairs(obj.values) do
+ for uri,m in pairs(maps_to_check) do
+ check_specific_map(key, uri, m, results, report_misses)
+ end
+ end
+ conn:send_ucl{
+ success = (#results > 0),
+ results = results
+ }
+end
+
return {
query = {
handler = handle_query_map,
enable = false,
},
+ query_json = {
+ handler = handle_query_json,
+ enable = false,
+ need_task = true,
+ },
query_specific = {
handler = handle_query_specific_map,
enable = false,
handler = handle_list_maps,
enable = false,
},
-}
\ No newline at end of file
+}