filestoraged now handles timer, new ipc.cr API OK.

This commit is contained in:
Karchnu 2020-07-21 12:42:19 +02:00
parent c8d3cf9e3f
commit abd8561308
2 changed files with 16 additions and 6 deletions

View File

@ -9,7 +9,7 @@ class FileStorage::Client < IPC::Client
def login def login
request = FileStorage::Request::Login.new auth_token request = FileStorage::Request::Login.new auth_token
send request send @server_fd.not_nil!, request
response = parse_message [ response = parse_message [
FileStorage::Response::Login, FileStorage::Response::Login,
@ -46,13 +46,12 @@ class FileStorage::Client < IPC::Client
size = 0 size = 0
while (size = file.read(buffer)) > 0 while (size = file.read(buffer)) > 0
puts "loop !!!"
# transfer message = file_info, chunk count, data (will be base64'd) # transfer message = file_info, chunk count, data (will be base64'd)
transfer_message = FileStorage::Request::PutChunk.new file_info, transfer_message = FileStorage::Request::PutChunk.new file_info,
counter, counter,
buffer[0 ... size] buffer[0 ... size]
send transfer_message send @server_fd.not_nil!, transfer_message
counter += 1 counter += 1
buffer = Bytes.new buffer_size buffer = Bytes.new buffer_size
@ -78,7 +77,7 @@ class FileStorage::Client < IPC::Client
def download(filedigest = nil, name = nil, tags = nil) def download(filedigest = nil, name = nil, tags = nil)
request = FileStorage::Request::Download.new filedigest, name, tags request = FileStorage::Request::Download.new filedigest, name, tags
send request send @server_fd.not_nil!, request
response = parse_message [ response = parse_message [
FileStorage::Response::Download, FileStorage::Response::Download,
@ -93,7 +92,7 @@ class FileStorage::Client < IPC::Client
File.open(file) do |f| File.open(file) do |f|
file_info = FileStorage::FileInfo.new f file_info = FileStorage::FileInfo.new f
request = FileStorage::Request::Upload.new file_info request = FileStorage::Request::Upload.new file_info
send request send @server_fd.not_nil!, request
end end
response = parse_message [ response = parse_message [

View File

@ -248,6 +248,7 @@ class FileStorage::Service < IPC::Server
def self.from_cli def self.from_cli
storage_directory = "files/" storage_directory = "files/"
key = "nico-nico-nii" # Default authd key, as per the specs. :eyes: key = "nico-nico-nii" # Default authd key, as per the specs. :eyes:
timer = 30_000 # Default timer: 30 seconds.
OptionParser.parse do |parser| OptionParser.parse do |parser|
parser.banner = "usage: filestoraged [options]" parser.banner = "usage: filestoraged [options]"
@ -258,6 +259,12 @@ class FileStorage::Service < IPC::Server
storage_directory = opt storage_directory = opt
end end
parser.on "-t timer",
"--timer timer",
"Timer. Default: 30 000 (30 seconds)." do |t|
timer = t.to_i
end
parser.on "-h", parser.on "-h",
"--help", "--help",
"Displays this help and exits." do "Displays this help and exits." do
@ -273,7 +280,11 @@ class FileStorage::Service < IPC::Server
end end
end end
::FileStorage::Service.new storage_directory, key service = ::FileStorage::Service.new storage_directory, key
service.base_timer = timer
service.timer = timer
service
end end
end end