comparison src/luan/modules/host/Hosting.luan @ 1596:a9ff30fb5d89

add Hosting.push_file
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Mar 2021 20:10:44 -0600
parents fe5bcd8133e0
children cd2a0c41b23f
comparison
equal deleted inserted replaced
1595:e4deb32bd233 1596:a9ff30fb5d89
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local ipairs = Luan.ipairs or error() 3 local ipairs = Luan.ipairs or error()
4 local pairs = Luan.pairs or error() 4 local pairs = Luan.pairs or error()
5 local set_metatable = Luan.set_metatable or error() 5 local set_metatable = Luan.set_metatable or error()
6 local stringify = Luan.stringify or error()
6 local Io = require "luan:Io.luan" 7 local Io = require "luan:Io.luan"
7 local print = Io.print or error() 8 local print = Io.print or error()
8 local Rpc = require "luan:Rpc.luan" 9 local Rpc = require "luan:Rpc.luan"
9 local String = require "luan:String.luan" 10 local String = require "luan:String.luan"
10 local matches = String.matches or error() 11 local matches = String.matches or error()
12 local substring = String.sub or error()
13 local split = String.split or error()
11 local Logging = require "luan:logging/Logging.luan" 14 local Logging = require "luan:logging/Logging.luan"
12 local logger = Logging.logger "Hosting" 15 local logger = Logging.logger "Hosting"
13 16
14 17
15 local Hosting = {} 18 local Hosting = {}
59 62
60 host.update_handler(domain,password) 63 host.update_handler(domain,password)
61 host.close() 64 host.close()
62 end 65 end
63 66
67 function Hosting.push_file(domain,password,dir,file)
68 local my_dir = Io.uri("file:"..dir)
69 my_dir.exists() or error("directory '"..dir.."' not found")
70 my_dir.is_directory() or error("'"..dir.."' is not a directory")
71 local my_file = Io.uri("file:"..file)
72 my_file.exists() or error("file '"..file.."' not found")
73 my_file.is_file() or error("'"..file.."' is not a file")
74 local my_file_string = my_file.to_string()
75 local my_dir_string = my_dir.to_string().."/"
76 matches( my_file_string, [[^\Q]]..my_dir_string..[[\E]] ) or error "file must be in dir"
77 my_file_string = substring(my_file_string,#my_dir_string+1)
78 local path = {split( my_file_string, "/" )}
79 path[#path] = nil
80 local host = Rpc.remote(domain)
81 local there = host.get(domain,password)
82 there~=nil or error "site not created"
83 for _, s in ipairs(path) do
84 there = there.children[s] or error("'"..s.."' not found on remote")
85 end
86 host.copy_file(domain,password,there.path,my_file.name(),my_file.read_binary())
87 end
88
64 function Hosting.delete(domain,password) 89 function Hosting.delete(domain,password)
65 local host = Rpc.remote(domain) 90 local host = Rpc.remote(domain)
66 host.delete(domain,password) 91 host.delete(domain,password)
67 host.close() 92 host.close()
68 end 93 end