Changeset 4345
- Timestamp:
- Nov 23, 2009, 12:38:57 AM (14 years ago)
- Location:
- branches/2.0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/include/ws_functions.inc.php
r4344 r4345 943 943 ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath); 944 944 945 if (is_file($output_filepath)) 946 { 947 unlink($output_filepath); 948 949 if (is_file($output_filepath)) 950 { 951 new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath); 952 exit(); 953 } 954 } 955 945 956 $upload_dir = PHPWG_ROOT_PATH.'upload/buffer'; 946 957 $pattern = '/'.$original_sum.'-'.$type.'/'; … … 1037 1048 'filesize' => $filesize, 1038 1049 ); 1050 } 1051 1052 function ws_images_addFile($params, &$service) 1053 { 1054 // image_id 1055 // type {thumb, file, high} 1056 // sum 1057 1058 global $conf; 1059 if (!is_admin() || is_adviser() ) 1060 { 1061 return new PwgError(401, 'Access denied'); 1062 } 1063 1064 $params['image_id'] = (int)$params['image_id']; 1065 if ($params['image_id'] <= 0) 1066 { 1067 return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id"); 1068 } 1069 1070 // 1071 // what is the path? 1072 // 1073 $query = ' 1074 SELECT 1075 path, 1076 md5sum 1077 FROM '.IMAGES_TABLE.' 1078 WHERE id = '.$params['image_id'].' 1079 ;'; 1080 list($file_path, $original_sum) = mysql_fetch_row(pwg_query($query)); 1081 1082 // TODO only files added with web API can be updated with web API 1083 1084 // 1085 // makes sure directories are there and call the merge_chunks 1086 // 1087 $infos = add_file($file_path, $params['type'], $original_sum, $params['sum']); 1088 1089 // 1090 // update basic metadata from file 1091 // 1092 $update = array(); 1093 1094 if ('high' == $params['type']) 1095 { 1096 $update['high_filesize'] = $infos['filesize']; 1097 $update['has_high'] = 'true'; 1098 } 1099 1100 if ('file' == $params['type']) 1101 { 1102 $update['filesize'] = $infos['filesize']; 1103 $update['width'] = $infos['width']; 1104 $update['height'] = $infos['height']; 1105 } 1106 1107 // we may have nothing to update at database level, for example with a 1108 // thumbnail update 1109 if (count($update) > 0) 1110 { 1111 $update['id'] = $params['image_id']; 1112 1113 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 1114 mass_updates( 1115 IMAGES_TABLE, 1116 array( 1117 'primary' => array('id'), 1118 'update' => array_diff(array_keys($update), array('id')) 1119 ), 1120 array($update) 1121 ); 1122 } 1039 1123 } 1040 1124 -
branches/2.0/tools/piwigo_remote.pl
r4344 r4345 84 84 85 85 if ($opt{action} eq 'pwg.images.add') { 86 use MIME::Base64 qw(encode_base64);87 86 use Digest::MD5::File qw/file_md5_hex/; 88 87 89 88 $form = {}; 90 $form->{method} = 'pwg.images.add';89 $form->{method} = $opt{action}; 91 90 92 91 my $original_sum = file_md5_hex($opt{original}); … … 115 114 $form->{high_sum} = file_md5_hex($opt{high}); 116 115 } 116 117 foreach my $key (keys %{ $opt{define} }) { 118 $form->{$key} = $opt{define}{$key}; 119 } 120 121 my $response = $ua->post( 122 $conf{base_url}.'/ws.php?format=json', 123 $form 124 ); 125 126 print "-" x 50, "\n"; 127 printf("response code : %u\n", $response->code); 128 printf("response message : %s\n", $response->message); 129 print "-" x 50, "\n"; 130 print "\n"; 131 132 # use Data::Dumper; 133 # print Dumper($response->content); 134 # print Dumper(from_json($response->content)); 135 136 if ($response->is_success) { 137 print "upload successful\n"; 138 } 139 else { 140 print Dumper($response); 141 warn 'A problem has occured during upload', "\n"; 142 warn $response->decoded_content, "\n"; 143 die $response->status_line; 144 } 145 } 146 147 if ($opt{action} eq 'pwg.images.addFile') { 148 use Digest::MD5::File qw/file_md5_hex/; 149 150 if (not defined $opt{define}{image_id}) { 151 die '--define image_id=1234 is missing'; 152 } 153 154 # which file type are we going to add/update? 155 my $type = undef; 156 157 foreach my $test_type (qw/thumbnail file high/) { 158 if (defined $opt{$test_type}) { 159 $type = $test_type; 160 last; 161 } 162 } 163 164 if (not defined $type) { 165 die 'at least one of file/thumbnail/high parameters must be set'; 166 } 167 168 my $type_code = typecode_from_typename($type); 169 170 send_chunks( 171 filepath => $opt{$type}, 172 type => $type_code, 173 original_sum => file_md5_hex($opt{original}), 174 ); 175 176 $form = {}; 177 $form->{method} = $opt{action}; 178 $form->{type} = $type_code; 179 $form->{sum} = file_md5_hex($opt{$type}); 117 180 118 181 foreach my $key (keys %{ $opt{define} }) { … … 334 397 my %params = @_; 335 398 399 use MIME::Base64 qw(encode_base64); 336 400 use File::Slurp; 337 401 … … 376 440 } 377 441 } 442 443 sub typecode_from_typename { 444 my ($typename) = @_; 445 446 my $typecode = $typename; 447 448 if ('thumbnail' eq $typename) { 449 $typecode = 'thumb'; 450 } 451 452 return $typecode; 453 } -
branches/2.0/ws.php
r4344 r4345 184 184 'POST method only. For admin only.' 185 185 ); 186 186 187 $service->addMethod( 188 'pwg.images.addFile', 189 'ws_images_addFile', 190 array( 191 'image_id' => array(), 192 'type' => array(), 193 'sum' => array(), 194 ), 195 'Add or update a file for an existing photo. pwg.images.addChunk must have been called before (maybe several times)' 196 ); 197 187 198 188 199 $service->addMethod(
Note: See TracChangeset
for help on using the changeset viewer.