aboutsummaryrefslogtreecommitdiffstats
path: root/tools/piwigo_remote.pl
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2009-11-22 23:59:14 +0000
committerplegall <plg@piwigo.org>2009-11-22 23:59:14 +0000
commitf974668ef53c529ad4f44b594393ab04043696ad (patch)
tree489d64b152ed43ff8ea36f9143dd747a488c0254 /tools/piwigo_remote.pl
parent858b43e87a9911269505c1fbc9036b374e89a565 (diff)
merge r4345 from branch 2.0 to trunk
feature 1051: ability to add/update a file for an existing photo. For example, you can add the "high" later. Another example is to update the "web resized" file (new dimensions is a common example). It also works for thumbnails. Updating an existing file has no impact on the logical level (list of tags, list of categories, title, description and so on). git-svn-id: http://piwigo.org/svn/trunk@4348 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--tools/piwigo_remote.pl80
1 files changed, 78 insertions, 2 deletions
diff --git a/tools/piwigo_remote.pl b/tools/piwigo_remote.pl
index 91b072aeb..8c8098daf 100644
--- a/tools/piwigo_remote.pl
+++ b/tools/piwigo_remote.pl
@@ -83,11 +83,10 @@ $result = $ua->post(
# print "\n", $ua->cookie_jar->as_string, "\n";
if ($opt{action} eq 'pwg.images.add') {
- use MIME::Base64 qw(encode_base64);
use Digest::MD5::File qw/file_md5_hex/;
$form = {};
- $form->{method} = 'pwg.images.add';
+ $form->{method} = $opt{action};
my $original_sum = file_md5_hex($opt{original});
$form->{original_sum} = $original_sum;
@@ -145,6 +144,70 @@ if ($opt{action} eq 'pwg.images.add') {
}
}
+if ($opt{action} eq 'pwg.images.addFile') {
+ use Digest::MD5::File qw/file_md5_hex/;
+
+ if (not defined $opt{define}{image_id}) {
+ die '--define image_id=1234 is missing';
+ }
+
+ # which file type are we going to add/update?
+ my $type = undef;
+
+ foreach my $test_type (qw/thumbnail file high/) {
+ if (defined $opt{$test_type}) {
+ $type = $test_type;
+ last;
+ }
+ }
+
+ if (not defined $type) {
+ die 'at least one of file/thumbnail/high parameters must be set';
+ }
+
+ my $type_code = typecode_from_typename($type);
+
+ send_chunks(
+ filepath => $opt{$type},
+ type => $type_code,
+ original_sum => file_md5_hex($opt{original}),
+ );
+
+ $form = {};
+ $form->{method} = $opt{action};
+ $form->{type} = $type_code;
+ $form->{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($response->content);
+# print Dumper(from_json($response->content));
+
+ if ($response->is_success) {
+ 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;
+ }
+}
+
if ($opt{action} eq 'pwg.tags.list') {
use Text::ASCIITable;
@@ -333,6 +396,7 @@ sub pwg_ws_get_query {
sub send_chunks {
my %params = @_;
+ use MIME::Base64 qw(encode_base64);
use File::Slurp;
my $content = read_file($params{filepath});
@@ -375,3 +439,15 @@ sub send_chunks {
$chunk_id++;
}
}
+
+sub typecode_from_typename {
+ my ($typename) = @_;
+
+ my $typecode = $typename;
+
+ if ('thumbnail' eq $typename) {
+ $typecode = 'thumb';
+ }
+
+ return $typecode;
+}