Repository navigation
Expand file tree
/
Copy pathapi.lua
More file actions
53 lines (45 loc) · 1.38 KB
/
Copy pathapi.lua
File metadata and controls
53 lines (45 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local http, url, key = ...
local api = {}
local extra_headers_auth_json = { "Content-Type: application/json", "Authorization: " .. key }
-- stats to mapserver
function api.send_stats(stats, callback)
http.fetch({
url = url .. "/api/luanti/stats",
extra_headers = extra_headers_auth_json,
timeout = 5,
post_data = minetest.write_json(stats),
quiet = true
}, callback or function() end)
end
-- search-result query
function api.search(json, callback)
http.fetch({
url = url .. "/api/mapobjects/",
timeout = 10,
extra_headers = { "Content-Type: application/json" },
post_data = json,
quiet = true
}, callback)
end
-- node definitions to mapserver
function api.send_nodedefs(nodedefs, callback)
http.fetch({
url = url .. "/api/luanti/nodedefs",
extra_headers = extra_headers_auth_json,
timeout = 5,
post_data = minetest.write_json(nodedefs),
quiet = true
}, callback)
end
-- media to mapserver
function api.send_media(media, callback)
minetest.safe_file_write(minetest.get_worldpath() .. "/tmp.json", minetest.write_json(media))
http.fetch({
url = url .. "/api/luanti/media",
extra_headers = extra_headers_auth_json,
timeout = 5,
post_data = minetest.write_json(media),
quiet = true
}, callback)
end
return api