Changeset 4291
- Timestamp:
- Nov 17, 2009, 7:14:41 PM (15 years ago)
- Location:
- extensions/pLoader/trunk/src/Uploader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/pLoader/trunk/src/Uploader/ImageList.pm
r4279 r4291 1078 1078 ) 1079 1079 ); 1080 $self->progress_msg_details_refresh(" ");1081 1080 } 1082 1081 -
extensions/pLoader/trunk/src/Uploader/PWG/WebServices.pm
r4279 r4291 61 61 upload_high 62 62 chunk_size 63 sum_high_file 64 sum_resized_file 65 sum_thumb_file 66 sum_original_file 63 67 / 64 68 ); … … 239 243 my ( $self, $progress ) = @_; 240 244 241 my $file_sum; 242 243 my $yield = $progress->{yield}; 244 $yield->(); 245 $progress->{msg_details}->( 246 sprintf( 247 "%s : %s", 248 $progress->{checksum_msg}, 249 $self->site_resized_file 250 ) 251 ); 252 eval { 253 $file_sum = file_md5_hex( 254 $self->site_resized_file 255 ); 256 }; 257 $yield->(); 245 $self->sum_resized_file( 246 $self->_checksum( 247 $self->site_resized_file, 248 $progress 249 ) 250 ); 251 252 $self->sum_thumb_file( 253 $self->_checksum( 254 $self->site_thumb_file, 255 $progress 256 ) 257 ); 258 258 259 $progress->{msg_details}->( 260 sprintf( 261 "%s : %s", 262 $progress->{checksum_msg}, 263 $self->site_thumb_file 264 ) 265 ); 266 my $thumbnail_sum = file_md5_hex( 267 $self->site_thumb_file, 268 ); 269 $yield->(); 270 271 $progress->{msg_details}->( 272 sprintf( 273 "%s : %s", 274 $progress->{checksum_msg}, 275 $self->site_high_file 276 ) 277 ); 278 279 my $original_sum = file_md5_hex( 280 $self->site_high_file 281 ); 282 283 my $form = { 284 method => 'pwg.images.exist', 285 md5sum_list => $original_sum, 286 }; 287 288 $yield->(); 289 my $result = $self->uagent->post( 290 $self->urlbase.'/ws.php?format=json', 291 $form 292 ); 293 $yield->(); 294 295 my $hresult = {}; 296 eval { 297 $hresult = from_json( 298 $result->{_content} 299 ); 300 }; 259 $self->sum_high_file( 260 $self->_checksum( 261 $self->site_high_file, 262 $progress 263 ) 264 ); 265 # is the same in pLoader but may be different 266 $self->sum_original_file( 267 $self->sum_high_file 268 ); 269 301 270 302 271 my $site_image_name = $self->site_image_name; 303 272 304 my $image_id = $ hresult->{result}{$original_sum};273 my $image_id = $self->_exists($self->sum_original_file);; 305 274 my $status = 0; 306 275 my $status_line = "An error has occured during upload."; 307 276 my $content = {}; 277 my $doubleCheck; 278 my $form; 308 279 while(1){ 309 280 if(!defined($image_id)){ 310 281 311 my $resized_params = { 312 filepath => $self->site_resized_file, 313 type => 'file', 314 original_sum => $original_sum, 315 }; 316 317 $progress->{current_msg} = $progress->{resized_msg}; 318 $yield->(); 319 $self->send_chunks( 320 $resized_params, 321 $progress, 322 ); 323 $yield->(); 324 282 my $resized_params = $self->_send_chunks('file', $progress); 325 283 $status_line = $resized_params->{message}; 326 284 last if !$resized_params->{ok}; 327 285 328 my $thumb_params = { 329 filepath => $self->site_thumb_file, 330 type => 'thumb', 331 original_sum => $original_sum, 332 }; 333 334 $progress->{current_msg} = $progress->{thumbnail_msg}; 335 $yield->(); 336 $self->send_chunks( 337 $thumb_params, 338 $progress, 339 ); 340 $yield->(); 286 my $thumb_params = $self->_send_chunks('thumb', $progress); 341 287 $status_line = $thumb_params->{message}; 342 288 last if !$thumb_params->{ok}; 343 344 289 345 290 $form = { 346 291 method => 'pwg.images.add', 347 original_sum => $ original_sum,348 file_sum => $ file_sum,349 thumbnail_sum => $ thumbnail_sum,292 original_sum => $self->sum_original_file, 293 file_sum => $self->sum_resized_file, 294 thumbnail_sum => $self->sum_thumb_file, 350 295 categories => $self->categories, 351 296 name => $site_image_name, … … 357 302 358 303 }; 359 my $high_params = {360 filepath => $self->site_high_file,361 type => 'high',362 original_sum => $original_sum,363 };364 304 365 305 if($self->upload_high){ 366 $form->{high_sum} = $original_sum; 367 $progress->{current_msg} = $progress->{highdef_msg}; 368 $yield->(); 369 $self->send_chunks( 370 $high_params, 371 $progress 372 ); 373 $yield->(); 306 my $high_params = $self->_send_chunks('high', $progress); 374 307 $status_line = $high_params->{message}; 375 308 last if !$high_params->{ok}; 376 309 } 310 $doubleCheck = 1; 377 311 } 378 312 else { … … 388 322 tag_ids => $self->site_tags, 389 323 }; 390 $ yield->();324 $progress->{yield}->(); 391 325 } 392 326 … … 394 328 delete $form->{tag_ids} if '' eq $self->site_tags; 395 329 396 $ yield->();397 $result = $self->uagent->post(330 $progress->{yield}->(); 331 my $result = $self->uagent->post( 398 332 $self->urlbase.'/ws.php?format=json', 399 333 $form … … 409 343 $status_line = $result->status_line; 410 344 345 if($doubleCheck){ 346 $content->{stat} = 'fail' if !$self->_exists($self->sum_original_file); 347 } 348 411 349 last; 412 350 } … … 414 352 return ( $status, $status_line, $content); 415 353 } 416 354 355 sub _exists { 356 my ( $self, $md5_sum ) = @_; 357 358 my $form = { 359 method => 'pwg.images.exist', 360 md5sum_list => $md5_sum, 361 }; 362 363 my $result = $self->uagent->post( 364 $self->urlbase.'/ws.php?format=json', 365 $form 366 ); 367 368 my $hresult = {}; 369 eval { 370 $hresult = from_json( 371 $result->{_content} 372 ); 373 }; 374 my $id; 375 $id = $hresult->{result}{$self->sum_original_file} if 'ok' eq $hresult->{stat}; 376 377 $id; 378 } 379 380 sub _checksum { 381 my ( $self, $file, $progress ) = @_; 382 my $file_sum; 383 384 my $yield = $progress->{yield}; 385 386 $yield->(); 387 $progress->{msg_details}->( 388 sprintf( 389 "%s : %s", 390 $progress->{checksum_msg}, 391 $file 392 ) 393 ); 394 eval { 395 $file_sum = file_md5_hex( 396 $file 397 ); 398 }; 399 $yield->(); 400 401 $file_sum; 402 } 403 404 sub _send_chunks { 405 my ( $self, $type, $progress ) = @_; 406 407 my $msg = { 408 thumb=>'thumbnail_msg', 409 file=>'resized_msg', 410 high=>'highdef_msg', 411 }; 412 413 my $filepath = { 414 thumb=>$self->site_thumb_file, 415 file=>$self->site_resized_file, 416 high=>$self->site_high_file, 417 }; 418 419 $progress->{current_msg} = $progress->{$msg->{$type}}; 420 $progress->{yield}->(); 421 422 my $params = { 423 filepath => $filepath->{$type}, 424 type => $type, 425 original_sum => $self->sum_original_file, 426 }; 427 428 $self->send_chunks( 429 $params, 430 $progress, 431 ); 432 $progress->{yield}->(); 433 434 $params; 435 } 417 436 418 437 sub AddCategories{
Note: See TracChangeset
for help on using the changeset viewer.