From abd8561308a107d8afddd9f6e637734f0cb082b2 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Tue, 21 Jul 2020 12:42:19 +0200 Subject: [PATCH] filestoraged now handles timer, new ipc.cr API OK. --- src/common/requests/client.cr | 9 ++++----- src/server/main.cr | 13 ++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/common/requests/client.cr b/src/common/requests/client.cr index 322107e..af3c82d 100644 --- a/src/common/requests/client.cr +++ b/src/common/requests/client.cr @@ -9,7 +9,7 @@ class FileStorage::Client < IPC::Client def login request = FileStorage::Request::Login.new auth_token - send request + send @server_fd.not_nil!, request response = parse_message [ FileStorage::Response::Login, @@ -46,13 +46,12 @@ class FileStorage::Client < IPC::Client size = 0 while (size = file.read(buffer)) > 0 - puts "loop !!!" # transfer message = file_info, chunk count, data (will be base64'd) transfer_message = FileStorage::Request::PutChunk.new file_info, counter, buffer[0 ... size] - send transfer_message + send @server_fd.not_nil!, transfer_message counter += 1 buffer = Bytes.new buffer_size @@ -78,7 +77,7 @@ class FileStorage::Client < IPC::Client def download(filedigest = nil, name = nil, tags = nil) request = FileStorage::Request::Download.new filedigest, name, tags - send request + send @server_fd.not_nil!, request response = parse_message [ FileStorage::Response::Download, @@ -93,7 +92,7 @@ class FileStorage::Client < IPC::Client File.open(file) do |f| file_info = FileStorage::FileInfo.new f request = FileStorage::Request::Upload.new file_info - send request + send @server_fd.not_nil!, request end response = parse_message [ diff --git a/src/server/main.cr b/src/server/main.cr index a546166..f0d49ae 100644 --- a/src/server/main.cr +++ b/src/server/main.cr @@ -248,6 +248,7 @@ class FileStorage::Service < IPC::Server def self.from_cli storage_directory = "files/" key = "nico-nico-nii" # Default authd key, as per the specs. :eyes: + timer = 30_000 # Default timer: 30 seconds. OptionParser.parse do |parser| parser.banner = "usage: filestoraged [options]" @@ -258,6 +259,12 @@ class FileStorage::Service < IPC::Server storage_directory = opt end + parser.on "-t timer", + "--timer timer", + "Timer. Default: 30 000 (30 seconds)." do |t| + timer = t.to_i + end + parser.on "-h", "--help", "Displays this help and exits." do @@ -273,7 +280,11 @@ class FileStorage::Service < IPC::Server 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