Browse Source

starting on send_file

master
Jonathan "Duke" Leto 7 years ago
parent
commit
4f488e630f
  1. 5
      bin/hushlist
  2. 56
      lib/Hush/App.pm
  3. 5
      lib/Hush/List.pm

5
bin/hushlist

@ -1,12 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Try::Tiny;
use lib 'lib';
use Hush::List;
use Hush::Util qw/barf/;
use Data::Dumper;
use Hush::RPC;
use Hush::App;
my $command = shift;

56
lib/Hush/App.pm

@ -9,27 +9,29 @@ use Data::Dumper;
use Hush::RPC;
my $COMMANDS = {
"add" => \&add,
"contact" => \&Hush::Contact::contact,
"help" => \&help,
"new" => \&new,
"remove" => \&remove,
"send" => \&send,
"show" => \&show,
"status" => \&status,
#"public" => \&public,
"add" => \&add,
"contact" => \&Hush::Contact::contact,
"help" => \&help,
"new" => \&new,
"remove" => \&remove,
"send" => \&send,
"send-file" => \&send_file,
"show" => \&show,
"status" => \&status,
#"public" => \&public,
};
# TODO: translations
my %HELP = (
"add" => "Add a contact to a Hushlist",
"contact" => "Manage Hushlist contacts",
"help" => "Get your learn on",
"new" => "Create a new Hushlist",
"remove" => "Remove a Hushlist",
"send" => "Send a new new Hushlist memo",
"status" => "Get overview of Hushlists or a specific Hushlist",
"show" => "Show Hushlist memos",
#"public" => "Make a private Hushlist public",
"add" => "Add a contact to a Hushlist",
"contact" => "Manage Hushlist contacts",
"help" => "Get your learn on",
"new" => "Create a new Hushlist",
"remove" => "Remove a Hushlist",
"send" => "Send a new Hushlist memo, specified on command-line",
"send-file" => "Send a new Hushlist memo from a file on disk",
"status" => "Get overview of Hushlists or a specific Hushlist",
"show" => "Show Hushlist memos",
#"public" => "Make a private Hushlist public",
);
my $rpc = Hush::RPC->new;
@ -77,8 +79,26 @@ sub remove {
my ($list_name,$zaddr) = @_;
$list->remove_zaddr($list_name,$zaddr);
return $list;
}
# send a Hushlist memo from a file
sub send_file {
my ($list_name,$file) = @_;
barf "You must specify a file to attach" unless $file;
if (-e $file) {
my $memo = read_file($file);
$list->send_memo($rpc, $list_name, $memo);
} else {
barf "Cannot find $file to attach to Hushlist memo to $list_name!";
}
return $list;
}
# send a Hushlist memo to list of contacts on the chain
# specified for this list
sub send {
my ($list_name,$memo) = @_;

5
lib/Hush/List.pm

@ -312,6 +312,11 @@ sub send_memo {
barf "Invalid Hush list name" unless $name =~ m/^([a-z0-9]+)$/i;
barf "Hush memo cannot be empty" unless $memo;
my $MAX_MEMO = 512;
my $length = length($memo);
barf("Hushlist memo too large! $length > $MAX_MEMO") if ($length > $MAX_MEMO);
my $debug = sub { debug("send_memo: @_") };
# each hush list has a sending_zaddr defined at time of creation

Loading…
Cancel
Save