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

dev
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
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 [

View File

@ -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