aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ws_functions.inc.php104
-rw-r--r--tools/piwigo_remote.pl64
-rw-r--r--ws.php12
3 files changed, 160 insertions, 20 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index bd5fb8418..a01322547 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -989,25 +989,7 @@ function merge_chunks($output_filepath, $original_sum, $type)
*/
function add_file($file_path, $type, $original_sum, $file_sum)
{
- // resolve the $file_path depending on the $type
- if ('thumb' == $type) {
- $file_path = get_thumbnail_location(
- array(
- 'path' => $file_path,
- 'tn_ext' => 'jpg',
- )
- );
- }
-
- if ('high' == $type) {
- @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
- $file_path = get_high_location(
- array(
- 'path' => $file_path,
- 'has_high' => 'true'
- )
- );
- }
+ $file_path = file_path_for_type($file_path, $type);
$upload_dir = dirname($file_path);
@@ -1501,6 +1483,90 @@ SELECT
return $result;
}
+function ws_images_checkFiles($params, &$service)
+{
+ if (!is_admin() or is_adviser())
+ {
+ return new PwgError(401, 'Access denied');
+ }
+
+ // input parameters
+ //
+ // image_id
+ // thumbnail_sum
+ // file_sum
+ // high_sum
+
+ $params['image_id'] = (int)$params['image_id'];
+ if ($params['image_id'] <= 0)
+ {
+ return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
+ }
+
+ $query = '
+SELECT
+ path
+ FROM '.IMAGES_TABLE.'
+ WHERE id = '.$params['image_id'].'
+;';
+ $result = pwg_query($query);
+ if (mysql_num_rows($result) == 0) {
+ return new PwgError(404, "image_id not found");
+ }
+ list($path) = mysql_fetch_row($result);
+
+ $ret = array();
+
+ foreach (array('thumb', 'file', 'high') as $type) {
+ $param_name = $type;
+ if ('thumb' == $type) {
+ $param_name = 'thumbnail';
+ }
+
+ if (isset($params[$param_name.'_sum'])) {
+ $type_path = file_path_for_type($path, $type);
+ if (!is_file($type_path)) {
+ $ret[$param_name] = 'missing';
+ }
+ else {
+ if (md5_file($type_path) != $params[$param_name.'_sum']) {
+ $ret[$param_name] = 'differs';
+ }
+ else {
+ $ret[$param_name] = 'equals';
+ }
+ }
+ }
+ }
+
+ return $ret;
+}
+
+function file_path_for_type($file_path, $type='thumb')
+{
+ // resolve the $file_path depending on the $type
+ if ('thumb' == $type) {
+ $file_path = get_thumbnail_location(
+ array(
+ 'path' => $file_path,
+ 'tn_ext' => 'jpg',
+ )
+ );
+ }
+
+ if ('high' == $type) {
+ @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
+ $file_path = get_high_location(
+ array(
+ 'path' => $file_path,
+ 'has_high' => 'true'
+ )
+ );
+ }
+
+ return $file_path;
+}
+
function ws_images_setInfo($params, &$service)
{
global $conf;
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});
diff --git a/ws.php b/ws.php
index e2e128f1b..66bab7577 100644
--- a/ws.php
+++ b/ws.php
@@ -251,6 +251,18 @@ function ws_addDefaultMethods( $arr )
);
$service->addMethod(
+ 'pwg.images.checkFiles',
+ 'ws_images_checkFiles',
+ array(
+ 'image_id' => array(),
+ 'thumbnail_sum' => array('default' => null),
+ 'file_sum' => array('default' => null),
+ 'high_sum' => array('default' => null),
+ ),
+ 'check if you have updated version of your files for a given photo, for each requested file type, the answer can be "missing", "equals" or "differs"'
+ );
+
+ $service->addMethod(
'pwg.images.setInfo',
'ws_images_setInfo',
array(