Changeset 4347
- Timestamp:
- Nov 23, 2009, 12:58:44 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ws_functions.inc.php
r4346 r4347 990 990 function add_file($file_path, $type, $original_sum, $file_sum) 991 991 { 992 // resolve the $file_path depending on the $type 993 if ('thumb' == $type) { 994 $file_path = get_thumbnail_location( 995 array( 996 'path' => $file_path, 997 'tn_ext' => 'jpg', 998 ) 999 ); 1000 } 1001 1002 if ('high' == $type) { 1003 @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 1004 $file_path = get_high_location( 1005 array( 1006 'path' => $file_path, 1007 'has_high' => 'true' 1008 ) 1009 ); 1010 } 992 $file_path = file_path_for_type($file_path, $type); 1011 993 1012 994 $upload_dir = dirname($file_path); … … 1502 1484 } 1503 1485 1486 function ws_images_checkFiles($params, &$service) 1487 { 1488 if (!is_admin() or is_adviser()) 1489 { 1490 return new PwgError(401, 'Access denied'); 1491 } 1492 1493 // input parameters 1494 // 1495 // image_id 1496 // thumbnail_sum 1497 // file_sum 1498 // high_sum 1499 1500 $params['image_id'] = (int)$params['image_id']; 1501 if ($params['image_id'] <= 0) 1502 { 1503 return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id"); 1504 } 1505 1506 $query = ' 1507 SELECT 1508 path 1509 FROM '.IMAGES_TABLE.' 1510 WHERE id = '.$params['image_id'].' 1511 ;'; 1512 $result = pwg_query($query); 1513 if (mysql_num_rows($result) == 0) { 1514 return new PwgError(404, "image_id not found"); 1515 } 1516 list($path) = mysql_fetch_row($result); 1517 1518 $ret = array(); 1519 1520 foreach (array('thumb', 'file', 'high') as $type) { 1521 $param_name = $type; 1522 if ('thumb' == $type) { 1523 $param_name = 'thumbnail'; 1524 } 1525 1526 if (isset($params[$param_name.'_sum'])) { 1527 $type_path = file_path_for_type($path, $type); 1528 if (!is_file($type_path)) { 1529 $ret[$param_name] = 'missing'; 1530 } 1531 else { 1532 if (md5_file($type_path) != $params[$param_name.'_sum']) { 1533 $ret[$param_name] = 'differs'; 1534 } 1535 else { 1536 $ret[$param_name] = 'equals'; 1537 } 1538 } 1539 } 1540 } 1541 1542 return $ret; 1543 } 1544 1545 function file_path_for_type($file_path, $type='thumb') 1546 { 1547 // resolve the $file_path depending on the $type 1548 if ('thumb' == $type) { 1549 $file_path = get_thumbnail_location( 1550 array( 1551 'path' => $file_path, 1552 'tn_ext' => 'jpg', 1553 ) 1554 ); 1555 } 1556 1557 if ('high' == $type) { 1558 @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 1559 $file_path = get_high_location( 1560 array( 1561 'path' => $file_path, 1562 'has_high' => 'true' 1563 ) 1564 ); 1565 } 1566 1567 return $file_path; 1568 } 1569 1504 1570 function ws_images_setInfo($params, &$service) 1505 1571 { -
trunk/tools/piwigo_remote.pl
r3454 r4347 18 18 use JSON; 19 19 use LWP::UserAgent; 20 # LWP::Debug::level('+'); 20 21 use Getopt::Long; 21 22 use Encode qw/is_utf8 decode/; … … 41 42 42 43 our $ua = LWP::UserAgent->new; 44 $ua->agent('Mozilla/piwigo_remote.pl 1.25'); 43 45 $ua->cookie_jar({}); 44 46 … … 56 58 $conf{$conf_key} = defined $opt{$conf_key} ? $opt{$conf_key} : $conf_default{$conf_key} 57 59 } 60 61 $ua->default_headers->authorization_basic( 62 $conf{username}, 63 $conf{password} 64 ); 58 65 59 66 my $result = undef; … … 79 86 use MIME::Base64 qw(encode_base64); 80 87 use Digest::MD5::File qw/file_md5_hex/; 81 use File::Slurp;82 88 83 89 $form = {}; … … 133 139 } 134 140 else { 141 print Dumper($response); 135 142 warn 'A problem has occured during upload', "\n"; 136 143 warn $response->decoded_content, "\n"; … … 171 178 172 179 $result = $ua->get($query); 180 print Dumper($result); 173 181 my $tags = from_json($result->content)->{result}{tags}; 174 182 … … 235 243 } 236 244 245 if ($opt{action} eq 'pwg.images.checkFiles') { 246 use Digest::MD5::File qw/file_md5_hex/; 247 248 $form = {}; 249 $form->{method} = $opt{action}; 250 251 foreach my $type (qw/thumbnail file high/) { 252 if (defined $opt{$type}) { 253 $form->{$type.'_sum'} = file_md5_hex($opt{$type}); 254 } 255 } 256 257 foreach my $key (keys %{ $opt{define} }) { 258 $form->{$key} = $opt{define}{$key}; 259 } 260 261 my $response = $ua->post( 262 $conf{base_url}.'/ws.php?format=json', 263 $form 264 ); 265 266 print "-" x 50, "\n"; 267 printf("response code : %u\n", $response->code); 268 printf("response message : %s\n", $response->message); 269 print "-" x 50, "\n"; 270 print "\n"; 271 272 use Data::Dumper; 273 print Dumper(from_json($response->content)); 274 } 275 237 276 if ($opt{action} eq 'pwg.images.setInfo' or $opt{action} eq 'pwg.categories.setInfo') { 238 277 $form = { … … 254 293 } 255 294 295 if ($opt{action} eq 'pwg.categories.getList') { 296 $form = { 297 method => $opt{action}, 298 }; 299 300 foreach my $key (keys %{ $opt{define} }) { 301 $form->{$key} = $opt{define}{$key}; 302 } 303 304 my $response = $ua->post( 305 $conf{base_url}.'/ws.php?format=json', 306 $form 307 ); 308 309 use Data::Dumper; 310 print Dumper($response->content); 311 print Dumper(from_json($response->content)->{result}); 312 print Dumper($response); 313 } 314 315 256 316 $query = pwg_ws_get_query( 257 317 method => 'pwg.session.logout' … … 273 333 sub send_chunks { 274 334 my %params = @_; 335 336 use File::Slurp; 275 337 276 338 my $content = read_file($params{filepath}); -
trunk/ws.php
r3454 r4347 252 252 253 253 $service->addMethod( 254 'pwg.images.checkFiles', 255 'ws_images_checkFiles', 256 array( 257 'image_id' => array(), 258 'thumbnail_sum' => array('default' => null), 259 'file_sum' => array('default' => null), 260 'high_sum' => array('default' => null), 261 ), 262 '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"' 263 ); 264 265 $service->addMethod( 254 266 'pwg.images.setInfo', 255 267 'ws_images_setInfo',
Note: See TracChangeset
for help on using the changeset viewer.