From 858b43e87a9911269505c1fbc9036b374e89a565 Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 22 Nov 2009 23:58:44 +0000 Subject: merge r4344 from branch 2.0 to trunk feature 1051: new API method pwg.images.checkFiles. This method will be useful before asking for an update on photo files. Enhancement in code factorization. git-svn-id: http://piwigo.org/svn/trunk@4347 68402e56-0260-453c-a942-63ccdbb3a9ee --- tools/piwigo_remote.pl | 64 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/piwigo_remote.pl b/tools/piwigo_remote.pl index ceb2af4b9..91b072aeb 100644 --- a/tools/piwigo_remote.pl +++ b/tools/piwigo_remote.pl @@ -17,6 +17,7 @@ use warnings; use JSON; use LWP::UserAgent; +# LWP::Debug::level('+'); use Getopt::Long; use Encode qw/is_utf8 decode/; use POSIX qw(ceil floor); @@ -40,6 +41,7 @@ GetOptions( ); our $ua = LWP::UserAgent->new; +$ua->agent('Mozilla/piwigo_remote.pl 1.25'); $ua->cookie_jar({}); my %conf; @@ -56,6 +58,11 @@ foreach my $conf_key (keys %conf_default) { $conf{$conf_key} = defined $opt{$conf_key} ? $opt{$conf_key} : $conf_default{$conf_key} } +$ua->default_headers->authorization_basic( + $conf{username}, + $conf{password} +); + my $result = undef; my $query = undef; @@ -78,7 +85,6 @@ $result = $ua->post( if ($opt{action} eq 'pwg.images.add') { use MIME::Base64 qw(encode_base64); use Digest::MD5::File qw/file_md5_hex/; - use File::Slurp; $form = {}; $form->{method} = 'pwg.images.add'; @@ -132,6 +138,7 @@ if ($opt{action} eq 'pwg.images.add') { print "upload successful\n"; } else { + print Dumper($response); warn 'A problem has occured during upload', "\n"; warn $response->decoded_content, "\n"; die $response->status_line; @@ -170,6 +177,7 @@ if ($opt{action} eq 'pwg.tags.getAdminList') { ); $result = $ua->get($query); + print Dumper($result); my $tags = from_json($result->content)->{result}{tags}; foreach my $tag (@{$tags}) { @@ -234,6 +242,37 @@ if ($opt{action} eq 'pwg.images.exist') { # print Dumper($response); } +if ($opt{action} eq 'pwg.images.checkFiles') { + use Digest::MD5::File qw/file_md5_hex/; + + $form = {}; + $form->{method} = $opt{action}; + + foreach my $type (qw/thumbnail file high/) { + if (defined $opt{$type}) { + $form->{$type.'_sum'} = file_md5_hex($opt{$type}); + } + } + + foreach my $key (keys %{ $opt{define} }) { + $form->{$key} = $opt{define}{$key}; + } + + my $response = $ua->post( + $conf{base_url}.'/ws.php?format=json', + $form + ); + + print "-" x 50, "\n"; + printf("response code : %u\n", $response->code); + printf("response message : %s\n", $response->message); + print "-" x 50, "\n"; + print "\n"; + + use Data::Dumper; + print Dumper(from_json($response->content)); +} + if ($opt{action} eq 'pwg.images.setInfo' or $opt{action} eq 'pwg.categories.setInfo') { $form = { method => $opt{action}, @@ -253,6 +292,27 @@ if ($opt{action} eq 'pwg.images.setInfo' or $opt{action} eq 'pwg.categories.setI print Dumper($response); } +if ($opt{action} eq 'pwg.categories.getList') { + $form = { + method => $opt{action}, + }; + + foreach my $key (keys %{ $opt{define} }) { + $form->{$key} = $opt{define}{$key}; + } + + my $response = $ua->post( + $conf{base_url}.'/ws.php?format=json', + $form + ); + + use Data::Dumper; + print Dumper($response->content); + print Dumper(from_json($response->content)->{result}); + print Dumper($response); +} + + $query = pwg_ws_get_query( method => 'pwg.session.logout' ); @@ -273,6 +333,8 @@ sub pwg_ws_get_query { sub send_chunks { my %params = @_; + use File::Slurp; + my $content = read_file($params{filepath}); my $content_length = length($content); my $nb_chunks = ceil($content_length / $conf{chunk_size}); -- cgit v1.2.3