Mercurial Hosting > luan
comparison core/src/luan/modules/host/Hosting.luan @ 743:2c41f2aec92f
improve Rpc and implement rpc call for local webserver
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 13 Jul 2016 17:27:35 -0600 |
parents | 5578541125ea |
children |
comparison
equal
deleted
inserted
replaced
742:5578541125ea | 743:2c41f2aec92f |
---|---|
12 local matches = String.matches or error() | 12 local matches = String.matches or error() |
13 | 13 |
14 | 14 |
15 local M = {} | 15 local M = {} |
16 | 16 |
17 M.port = 9101 | |
18 | 17 |
19 function M.push(domain,password,dir) | 18 function M.push(domain,password,dir) |
20 local my_dir = Io.uri("file:"..dir) | 19 local my_dir = Io.uri("file:"..dir) |
21 my_dir.exists() or error("directory '"..dir.."' not found") | 20 my_dir.exists() or error("directory '"..dir.."' not found") |
22 my_dir.is_directory() or error("'"..dir.."' is not a directory") | 21 my_dir.is_directory() or error("'"..dir.."' is not a directory") |
23 local socket = "socket:" .. domain .. ":" .. M.port | 22 local host = Rpc.remote(domain) |
24 local host = Rpc.remote(socket) | |
25 local tree = host.get(domain,password) | 23 local tree = host.get(domain,password) |
26 if tree == nil then | 24 if tree == nil then |
27 print("creating "..domain) | 25 print("creating "..domain) |
28 tree = host.create(domain,password) | 26 tree = host.create(domain,password) |
29 end | 27 end |
62 | 60 |
63 host.update_handler(domain,password) | 61 host.update_handler(domain,password) |
64 end | 62 end |
65 | 63 |
66 function M.delete(domain,password) | 64 function M.delete(domain,password) |
67 local socket = "socket:" .. domain .. ":" .. M.port | 65 local host = Rpc.remote(domain) |
68 local host = Rpc.remote(socket) | |
69 host.delete(domain,password) | 66 host.delete(domain,password) |
70 end | 67 end |
71 | 68 |
72 function M.exists(domain) | 69 function M.exists(domain) |
73 local socket = "socket:" .. domain .. ":" .. M.port | 70 local host = Rpc.remote(domain) |
74 local host = Rpc.remote(socket) | |
75 return host.exists(domain) | 71 return host.exists(domain) |
76 end | 72 end |
77 | 73 |
78 function M.change_domain(old_domain,new_domain,password) | 74 function M.change_domain(old_domain,new_domain,password) |
79 local socket = "socket:" .. new_domain .. ":" .. M.port | 75 local host = Rpc.remote(new_domain) |
80 local host = Rpc.remote(socket) | |
81 return host.change_domain(old_domain,new_domain,password) | 76 return host.change_domain(old_domain,new_domain,password) |
82 end | 77 end |
83 | 78 |
84 function M.change_password(domain,old_password,new_password) | 79 function M.change_password(domain,old_password,new_password) |
85 local socket = "socket:" .. domain .. ":" .. M.port | 80 local host = Rpc.remote(domain) |
86 local host = Rpc.remote(socket) | |
87 return host.change_password(domain,old_password,new_password) | 81 return host.change_password(domain,old_password,new_password) |
88 end | 82 end |
89 | 83 |
90 function M.caller(domain) | 84 function M.caller(domain) |
91 local socket = "socket:" .. domain .. ":" .. M.port | 85 local host = Rpc.remote(domain) |
92 local host = Rpc.remote(socket) | |
93 local mt = {} | 86 local mt = {} |
94 function mt.__index(_,key) | 87 function mt.__index(_,key) |
95 return function(...) | 88 return function(...) |
96 return host.call(domain,key,...) | 89 return host.call(domain,key,...) |
97 end | 90 end |