Ignore:
Timestamp:
Dec 10, 2009, 3:21:06 PM (14 years ago)
Author:
ronosman
Message:

Feature 1052 added : photo re-upload management. When uploading an already added photo, the user is warned and has a choice on action for files, simple properties and multi-values properties.

Location:
extensions/pLoader/trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/pLoader/trunk/locale/fr_FR/pLoader.po

    r4422 r4467  
    4141msgstr "Transfert haute définition ( taille originale )"
    4242
     43msgid "Upload high definition  :"
     44msgstr "Transfert haute définition :"
     45
     46msgid "High definition"
     47msgstr "Haute définition"
     48
    4349msgid "Yes"
    4450msgstr "Oui"
     
    491497msgstr "Erreur de communication avec"
    492498
     499msgid "Thumbnail image done for"
     500msgstr "Miniature de l'image terminée pour"
     501
     502msgid "HD image done for"
     503msgstr "Image haute définition terminée pour"
     504
     505msgid "Resized image done for"
     506msgstr "Image réduite terminée pour"
     507
    493508msgid "Uploaded"
    494509msgstr "Transféré"
     
    532547msgid "HD image interlace :"
    533548msgstr "Entrelacement de l'image HD :"
     549
     550msgid "nothing"
     551msgstr "ne rien faire"
     552
     553msgid "replace"
     554msgstr "remplacer"
     555
     556msgid "fill if empty (only replace properties currently empty in Piwigo)"
     557msgstr "remplir si non renseigné (ne remplacer que les propriétés vides dans Piwigo)"
     558
     559msgid "append (keep existing and add new)"
     560msgstr "cumuler (garder l'existant et ajouter)"
     561
     562msgid "Do not ask me again"
     563msgstr "Ne plus me demander"
     564
     565msgid "A least one photo has already been added in the past."
     566msgstr "Au moins une photo a déjà été ajoutée dans le passé."
     567
     568msgid "What shall we do with files? (thumbnail, resized, high resolution)"
     569msgstr "Que faire pour les fichiers ? (miniature, taille web, haute définition)"
     570
     571msgid "What shall we do with single value properties?(caption, comment, author, create date)"
     572msgstr "Que faire pour les propriétés simples ? (titre, commentaire, auteur, date de création)"
     573
     574msgid "What shall we do with multiple values properties? (categories, tags)"
     575msgstr "Que faire pour les propriétés à valeurs multiples ? (catégories, tags)"
     576
     577msgid "Photo update management"
     578msgstr "Gestion de la mise à jour des photos"
  • extensions/pLoader/trunk/src/Uploader/GUI/wxApp.pm

    r4422 r4467  
    519519        watermark_x => 10,
    520520        watermark_color => 'White',
     521                reupload_action_files => 1,
     522                reupload_action_properties => 2,
     523                reupload_action_properties_m => 1,
    521524    };
    522525
  • extensions/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm

    r4422 r4467  
    148148use Uploader::GUI::wxImageProcessingProgressDlg;
    149149use Uploader::GUI::wxChoiceFilteredPanel;
     150use Uploader::GUI::wxImageReuploadDlg;
    150151use Wx::Html;
    151152use Uploader::GUI::wxImagePreview;
     
    155156use Storable;
    156157use Uploader::GUI::wxPropertyGridPanel;
     158use Uploader::GUI::wxPhotoProperties;
    157159use utf8;
    158160$|=1;
     
    206208        sub { $self->UploadImagesViewerRefresh(@_) }
    207209    );
     210       
     211        $self->imagelist->ReuploadCallback(
     212            sub {
     213                    Uploader::GUI::wxImageReuploadDlg->new(
     214            {
     215                                title      => gettext("Photo update management"),
     216                properties => {
     217                                        $main::ID_REUPLOAD_ACTION_FILES        => {
     218                                                                                                                    selection=>sub {$self->imagelist->reupload_action_files(@_)},
     219                                                                                                                                                                label=>gettext("What shall we do with files? (thumbnail, resized, high resolution)"),
     220                                                                                labels=>[
     221                                                                                                                                                                           gettext("nothing"),
     222                                                                                                                                                                           gettext("replace"),
     223                                                                                                                                                                       ],                                                                                                                                                               
     224                                                                                                            },
     225                                                                    $main::ID_REUPLOAD_ACTION_PROPERTIES   => {
     226                                                                                                                    selection=>sub{$self->imagelist->reupload_action_properties(@_)},
     227                                                                                                                                                                label=>gettext("What shall we do with single value properties?(caption, comment, author, create date)"),
     228                                                                                labels=>[
     229                                                                                                                                                                           gettext("nothing"),
     230                                                                                                                                                                           gettext("fill if empty (only replace properties currently empty in Piwigo)"),
     231                                                                                                                                                                           gettext("replace"),
     232                                                                                                                                                                       ],                                                                                                                                                               
     233                                                                                                                  },
     234                                                                        $main::ID_REUPLOAD_ACTION_PROPERTIES_M => {
     235                                                                                                                    selection=>sub{$self->imagelist->reupload_action_properties_m(@_)},
     236                                                                                                                                                                label=>gettext("What shall we do with multiple values properties? (categories, tags)"),
     237                                                                                labels=>[
     238                                                                                                                                                                           gettext("nothing"),
     239                                                                                                                                                                           gettext("append (keep existing and add new)"),
     240                                                                                                                                                                           gettext("replace"),
     241                                                                                                                                                                       ],                                                                                                                                                               
     242                                                                                                                  },
     243                                                                        $main::ID_REUPLOAD_NOT_ASK             => {
     244                                                                                                                    value=>sub{$self->imagelist->reupload_not_ask(@_)},
     245                                                                                label=>gettext("Do not ask me again"),                                                                                                                                                         
     246                                                                                                                  },
     247                                                                        $main::ID_REUPLOAD_TEXT                => {
     248                                                                                label=>gettext("A least one photo has already been added in the past."),                                                                                                                                                               
     249                                                                                                                  },
     250                                                },
     251            }
     252                        )->ShowModal();
     253                }
     254        );
    208255
    209256
     
    277324sub _set_setting_properties {
    278325    my ( $self ) = @_;
     326       
    279327
    280328    $self->piwigo_properties(
     
    607655    }
    608656    (
    609         $self->image_prop_piwigo,
     657        $self->image_prop_piwigo,
    610658        $self->image_prop_exif,
    611659        $self->image_prop_tags,
     
    663711sub _refresh_settings_panels_properties {
    664712    my ( $self ) = @_; 
    665 
     713       
    666714    $self->image_prop_piwigo->properties(
    667715        $self->piwigo_properties
     
    701749sub _init_settings_panels {
    702750    my ( $self ) = @_; 
     751
    703752
    704753    $self->image_prop_piwigo(
     
    868917        ->CenterPane->Resizable->CloseButton(0) );
    869918
     919               
    870920    $self->manager->AddPane(
    871921        $self->create_tree,
     
    10791129        [
    10801130            $self->hd_settings_panel,
    1081             gettext("HD"),
     1131            gettext("High definition"),
    10821132        ],
    10831133        [
     
    17451795    my ( $self ) = @_; 
    17461796
     1797
    17471798    $self->imageviewer->Refresh;
     1799
     1800    $self->image_preview->image(
     1801        0
     1802    ) if !$self->imageviewer->GetItemCount;
     1803
     1804
     1805    $self->image_preview->Refresh;
    17481806    Wx::Yield();
    17491807}
     
    18411899
    18421900    my $wximagelist = $self->imagelist->wx_thumb_imglist;
    1843 print Dumper "SetNewFilesViewerRefresh", $self->imagelist->current_image;
     1901    #print Dumper "SetNewFilesViewerRefresh", $self->imagelist->current_image;
    18441902    my $indx = $wximagelist->Add(
    18451903        Wx::Bitmap->new(
  • extensions/pLoader/trunk/src/Uploader/ImageList.pm

    r4422 r4467  
    9595                use_exif_preview
    9696                image_sums
     97                                upload_image_sums
    9798                sums
    9899                version
     
    120121                upload_file
    121122                upload_name
     123                                ReuploadCallback
     124                                reupload_action_files
     125                                reupload_action_properties
     126                                reupload_action_properties_m
     127                                reupload_not_ask
    122128     /
    123129);
     
    253259            # ok
    254260            if(!$@){
    255                 $self->progress_msg("Selection thumbnail created for %s");
     261                $self->progress_msg(gettext("Selection thumbnail created for %s"));
    256262            }
    257263            else {
     
    554560   
    555561    my $rval = 1 ;
    556     return $rval if( -e $self->current_image->site_resized_file );
     562    #return $rval if( -e $self->current_image->site_resized_file );
    557563
    558564    printf(
     
    634640    my ( $self ) = @_;
    635641   
    636     return 1 if( -e $self->current_image->site_thumb_file );
     642    #return 1 if( -e $self->current_image->site_thumb_file );
    637643   
    638644    my $rval = 1;
     
    765771                watermark_x
    766772                watermark_color
     773                                reupload_action_files
     774                                reupload_action_properties
     775                                reupload_action_properties_m
    767776            /
    768777        ]
     
    797806    $self->upload_begin_time(time);
    798807    $self->upload_selection_count(scalar @{$self->image_selection});
     808        # for re-upload management
     809    $self->upload_image_sums( [
     810                map { $self->GetImage($_)->file_sum }
     811                    @{$self->image_selection}
     812            ]
     813        );
     814
     815        # check if already exist on server
     816        my $uploaded = $self->pwg->IsAlreadyUploaded($self->upload_image_sums);
     817        my @already_uploaded = grep { $_ } values %$uploaded ;
     818        $self->ReuploadCallback->() if ( scalar @already_uploaded and !$self->reupload_not_ask );
     819
     820       
    799821    foreach(@{$self->image_selection}) {
    800         # current image object         
     822        # current image object         
    801823        $self->current_image(
    802824            $self->GetImage($_)
    803         );
     825        ); 
    804826        # prepare resized, high, thumbnail
    805         $self->_upload_selection_prepare();
     827                # if not already uploaded
     828        $self->_set_site_resized_file();
     829        $self-> _set_site_high_file ();
     830        # photo metadata
     831        $self->_prepare_upload_properties();           
     832        $self->_upload_selection_prepare() if (!$uploaded->{$self->current_image->file_sum} or $self->reupload_action_files);
    806833
    807834        # transfert resized, high, thumbnail to site
     
    827854    $self->progress_thumbnail_refresh->();
    828855    # PREPARE
    829     $self->_set_site_resized_file();
    830856    $self->_set_upload_msg(gettext("Preparing resized image for"));
    831857    $self->_upload_progress();
     
    848874            'Yes, use a copy of the original photo' => 'ORIGINAL',
    849875    }; 
    850 
     876printf("upload HD %s\n", $self->upload_hd);
    851877        $self->upload_high(
    852878            $decode->{$self->upload_hd}
     
    866892    $self->_upload_progress();
    867893
    868     # photo metadata
    869     $self->_prepare_upload_properties();       
    870894
    871895}
     
    923947            highdef_msg=>gettext("Uploading high definition"),
    924948            checksum_msg=>gettext("Checksum for"),
     949            original_sum=>$self->current_image->file_sum,
    925950        }
    926951    );
     
    11021127
    11031128    if($bModifyOriginal){
    1104         $self-> _set_site_high_file ();
    11051129
    11061130        my $image = Image::Magick->new();
     
    12381262sub _prepare_upload_properties {
    12391263    my ( $self ) = @_;
     1264
     1265        $self->pwg->reupload_action_files(
     1266            $self->reupload_action_files||1
     1267        );
     1268        $self->pwg->reupload_action_properties(
     1269            $self->reupload_action_properties||2
     1270        );
     1271
     1272        $self->pwg->reupload_action_properties_m(
     1273            $self->reupload_action_properties_m||1
     1274        );
    12401275   
    12411276    $self->pwg->upload_high(
     
    12851320        join(',', @{$self->current_image->site_tags})
    12861321    );
     1322
    12871323       
    12881324}
  • extensions/pLoader/trunk/src/Uploader/PWG/WebServices.pm

    r4422 r4467  
    6161           upload_high
    6262           chunk_size
    63            sum_high_file
    64            sum_resized_file
    65            sum_thumb_file
    66            sum_original_file
     63           sum
     64           image_id
     65           typecode
     66                   reupload_action_files
     67                   reupload_action_properties
     68                   reupload_action_properties_m
     69                   single_value_mode
     70                   multiple_value_mode
    6771      /
    6872);
     
    7276sub Init {
    7377    my ( $self, $version ) = @_ ;
    74  
     78
     79    # to transform a type_code into a typename
     80    $self->typecode(
     81        {
     82             file => 'file',
     83             thumbnail => 'thumb',
     84             high => 'high',   
     85        }
     86    );
     87       
     88        $self->single_value_mode(
     89            {
     90                    1 => 'fill_if_empty',
     91                        2 => 'replace',
     92                }
     93        );
     94
     95        $self->multiple_value_mode(
     96            {
     97                    1 => 'append',
     98                        2 => 'replace',
     99                }
     100        );
     101       
    75102    $self->uagent(
    76103        LWP::UserAgent->new(
     
    125152    };
    126153 
    127     $self->uagent_response(
    128         $self->uagent->post(
    129             $self->urlbase.'/ws.php?format=json',
    130             $form
    131         )
    132     );
    133    
     154    $self->_execute_post(
     155        $form
     156    );   
     157
     158    $self->login_result(
     159        $self->_json_response_content
     160    );
     161
     162}
     163
     164sub _json_response_content {
     165    my ( $self ) = @_;
     166
    134167    my $hresult = {} ;
    135168
    136169    if($self->uagent_response->is_success){
     170        # when server response has warnings, the content response is not a valid json string
     171                # find the json response
     172                #printf("%s\n", $self->uagent_response->content);
     173        $self->uagent_response->content =~ /(\{.+\})/;
     174                #printf("json response %s\n", $1);
    137175        eval {
    138176            $hresult = from_json(
    139                 $self->uagent_response->content
     177                $1
    140178            );
    141179        };
     180               
    142181    }
    143182    else{
    144         $hresult = {
     183        $hresult = {
    145184            'message' => $self->uagent_response->message,
    146185            'stat'    => 'fail',
    147186        };
    148187    }
    149 
    150     $self->login_result(
    151         $hresult
    152     );
    153 
    154 }
    155 
    156 sub GetCategories {
    157     my ( $self ) = @_;
    158 
    159     my $result;
     188       
     189        $hresult;
     190}
     191
     192sub _execute_get {
     193    my ( $self, $query ) = @_;
     194
    160195    eval {
    161         $result = $self->uagent->get(
    162             $self->qry_list_categories
     196        $self->uagent_response(
     197            $self->uagent->get(
     198                $query
     199                    )
    163200        );
    164201    };
     
    166203    if($@){
    167204        printf("An error occured in query execution %s\n%s",
    168             $self->qry_list_categories,
     205            $query,
    169206            $@,
    170207        );     
    171208    }
    172     my $hresult;
    173    
    174     eval {
    175         $hresult = from_json(
    176             $result->content
    177         );
    178     };
    179    
    180     $hresult ||= {};
    181 
    182     my $categories = $hresult->{result}{categories};
    183 
    184     $categories;       
    185 }
    186 
    187 sub GetTags {
    188     my ( $self ) = @_;
     209}
     210
     211sub _execute_post {
     212    my ( $self, $form ) = @_;
    189213
    190214    my $result;
    191215    eval {
    192         $result = $self->uagent->get(
    193             $self->qry_list_tags
     216        $result = $self->uagent_response(
     217            $self->uagent->post(
     218                $self->urlbase.'/ws.php?format=json',
     219                $form
     220            )
    194221        );
    195     };
     222        };
    196223
    197224    if($@){
    198         printf("An error occured in query execution %s\n%s",
    199             $self->qry_list_tags,
     225        printf("An error occured in post execution %s\n%s",
     226            $form->{method},
    200227            $@,
    201228        );     
    202229    }
    203     my $hresult;
    204    
    205     eval {
    206         $hresult = from_json(
    207             $result->content
    208         );
    209     };
    210    
    211     $hresult ||= {};
    212 
    213     $hresult->{result}{tags};
     230       
     231        return ( $result->is_success, $result->status_line );
     232}
     233sub GetCategories {
     234    my ( $self ) = @_;
     235
     236 
     237    $self->_execute_get(
     238            $self->qry_list_categories
     239        );
     240    $self->_json_response_content->{result}{categories};
     241}
     242
     243sub GetTags {
     244    my ( $self ) = @_;
     245
     246    $self->_execute_get(
     247        $self->qry_list_tags   
     248        );
     249    $self->_json_response_content->{result}{tags};
    214250}
    215251
     
    223259    };
    224260
    225     my $result = $self->uagent->post(
    226         $self->urlbase.'/ws.php?format=json',
    227         $form
    228     );
    229 
    230     my $content = {};
    231         eval {
    232             $content = from_json(
    233                 $result->content
    234             );
    235         };
    236 
    237     return ( $result->is_success, $result->status_line, $content );
    238        
     261    return ( $self->_execute_post($form), $self->_json_response_content );
    239262}
    240263
     
    243266    my ( $self, $progress ) = @_;
    244267
    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  
    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 
    270 
    271     my $site_image_name = $self->site_image_name;
    272 
    273     my $image_id = $self->_exists($self->sum_original_file);;
    274     my $status = 0;
    275     my $status_line = "An error has occured during upload.";
     268    $self->image_id(
     269        $self->_exists($progress->{original_sum})
     270    );
     271
     272    my $status = 1;
     273    my $status_line ="OK";
    276274    my $content = {};
    277275    my $doubleCheck;
    278276    my $form;
    279     while(1){
    280         if(!defined($image_id)){
    281                
    282             my $resized_params = $self->_send_chunks('file', $progress);
    283             $status_line = $resized_params->{message};
    284             last if !$resized_params->{ok};
     277    UPLOAD: while(1){
     278        # first upload
     279        if(!defined($self->image_id)){
     280            $doubleCheck = 1;
     281            $self->_checksum_files($progress);
     282            my @types = ('file', 'thumb');
     283            push @types, 'high' if $self->upload_high;
     284            map{
     285                my $rval = $self->_send_chunks($_, $progress);
     286                $status_line = $rval->{message};
     287                last UPLOAD if !$rval->{ok};
     288            } @types;
    285289         
    286             my $thumb_params = $self->_send_chunks('thumb', $progress);
    287             $status_line = $thumb_params->{message};
    288             last if !$thumb_params->{ok};
    289290       
    290291            $form = {
    291292                method            => 'pwg.images.add',
    292                 original_sum      => $self->sum_original_file,
    293                 file_sum          => $self->sum_resized_file,
    294                 thumbnail_sum     => $self->sum_thumb_file,
     293                original_sum      => $self->sum->{original},
     294                file_sum          => $self->sum->{file},
     295                thumbnail_sum     => $self->sum->{thumb},
    295296                categories        => $self->categories,
    296                 name              => $site_image_name,
    297                 rank              => $self->rank,
     297                name              => $self->site_image_name,
    298298                author            => $self->site_author,
    299299                comment           => $self->site_comment,
     
    302302               
    303303            };
    304    
    305             if($self->upload_high){
    306                 my $high_params = $self->_send_chunks('high', $progress);
    307                 $status_line = $high_params->{message};
    308                 last if !$high_params->{ok};
    309                                 # high is a HD resized copy of original
    310                                 $form->{high_sum} = $self->sum_high_file;
     304
     305           $form->{high_sum} = $self->sum->{high} if $self->upload_high;
     306                   
     307           $progress->{yield}->();
     308           ( $status, $status_line ) = $self->_execute_post($form);
     309                }
     310        # re-upload
     311        else{
     312                    #printf("reupload, files %s, properties %s\n", $self->reupload_action_files, $self->reupload_action_properties);
     313            # need to check if files have changed
     314            # and update image info
     315            if($self->reupload_action_files){
     316                $self->_checksum_files($progress);
     317                my $files = $self->_check_files();
     318                if(defined($files)){
     319                    $self->_add_files($files, $progress);       
     320                }
    311321            }
    312             $doubleCheck = 1;
    313         }
    314         else {
     322
    315323            $form = {
    316                 method            => 'pwg.images.setInfo',
    317                 image_id          => $image_id,
    318                 categories        => $self->categories,
    319                 name              => $site_image_name,
    320                 rank              => $self->rank,
    321                 author            => $self->site_author,
    322                 comment           => $self->site_comment,
    323                 date_creation     => $self->site_img_date_creation,
    324                 tag_ids           => $self->site_tags,
     324                    method        => 'pwg.images.setInfo',
     325                    image_id      => $self->image_id,
     326                    };
     327            # update metadata info
     328            if($self->reupload_action_properties){     
     329                            #printf("reupload_action_properties %s\n", $self->reupload_action_properties);
     330                $form->{name} = $self->site_image_name;
     331                $form->{author}        = $self->site_author;
     332                $form->{comment}       = $self->site_comment;
     333                $form->{date_creation} = $self->site_img_date_creation;
     334                                $form->{single_value_mode}  = $self->single_value_mode->{$self->reupload_action_properties};
     335                    }
     336            if($self->reupload_action_properties_m){   
     337                            #printf("reupload_action_properties_m %s\n", $self->reupload_action_properties_m);
     338                $form->{tag_ids} = $self->site_tags if $self->site_tags;
     339                $form->{categories} = $self->categories;
     340                                $form->{multiple_value_mode} = $self->multiple_value_mode->{$self->reupload_action_properties_m};
    325341            };
    326342            $progress->{yield}->();
    327         }
     343            ( $status, $status_line ) = $self->_execute_post($form);
     344            }
    328345
    329346        delete $form->{tag_ids} unless defined $self->site_tags;
     
    331348
    332349        $progress->{yield}->();
    333         my $result = $self->uagent->post(
    334             $self->urlbase.'/ws.php?format=json',
    335             $form
    336         );
    337         eval {
    338             $content = from_json(
    339                 $result->content
    340             );
    341         };
    342 
    343    
    344         $status = $result->is_success;
    345         $status_line = $result->status_line;
    346 
    347         if($doubleCheck){
    348             $content->{stat} = 'fail' if !$self->_exists($self->sum_original_file);
     350            #print "form ", Dumper $form;
     351                #print "status ", $status, "\n";
     352                #print "status_line ", $status_line, "\n";
     353            # basic check, should perform a checkfile
     354        $content->{stat} = !$self->_exists($progress->{original_sum}) ? 'fail' : 'ok';
     355
     356                last UPLOAD;
     357    }# UPLOAD
     358   
     359    return ( $status,  $status_line, $content);
     360}
     361
     362sub _checksum_files {
     363    my ( $self, $progress ) = @_;
     364
     365    $self->sum(
     366        {
     367            file => $self->_checksum(
     368                        $self->site_resized_file,
     369                        $progress
     370                    ),
     371            thumb => $self->_checksum(
     372                             $self->site_thumb_file,
     373                             $progress
     374                         ),
     375            high => $self->_checksum(
     376                        $self->site_high_file,
     377                        $progress
     378                    ),
     379            original => $progress->{original_sum}
    349380        }
    350 
    351         last;
     381    );
     382}
     383
     384sub _check_files {
     385    my ( $self ) = @_;
     386
     387    my $form = {
     388        method   => 'pwg.images.checkFiles',
     389        image_id => $self->image_id,
     390    };
     391   
     392    @$form{'thumbnail_sum', 'file_sum' } = (
     393        $self->sum->{thumb},
     394        $self->sum->{file},
     395    );
     396
     397    if($self->upload_high){
     398        $form->{high_sum} = $self->sum->{high};
    352399    }
    353    
    354     return ( $status,  $status_line, $content);
     400
     401    $self->_execute_post($form);   
     402    my $hresult = $self->_json_response_content;
     403
     404    my $rval = 'ok' eq $hresult->{stat} ? $hresult->{result} : undef;
     405   
     406    $rval;
     407}
     408
     409# $files is returned by _check_files
     410# {
     411#     thumbnail => 'equals', 'differs', 'missing'
     412#     file => 'equals', 'differs', 'missing'
     413#     high => 'equals', 'differs', 'missing'
     414#}
     415
     416sub _add_files {
     417    my ( $self, $files, $progress ) = @_;
     418
     419    map{
     420        $self->_add_file($_, $progress);
     421    }
     422    map{
     423        $self->typecode->{$_};
     424    } grep { 'equals' ne $files->{$_} } keys %$files ;
     425       
     426}
     427
     428sub _add_file {
     429    my ( $self, $type_code, $progress ) = @_;
     430
     431    $self->_send_chunks(
     432        $type_code,
     433        $progress,
     434    );
     435
     436    my $form = {
     437        method => 'pwg.images.addFile',
     438        image_id => $self->image_id,
     439        type     => $type_code,
     440        sum      => $self->sum->{$type_code},           
     441    }; 
     442
     443    $self->_execute_post($form);   
     444    my $hresult = $self->_json_response_content;
     445print Dumper $hresult;
     446    my $rval = 'ok' eq $hresult->{stat} ? $hresult->{result} : undef;
     447   
     448    $rval;
     449}
     450
     451sub IsAlreadyUploaded {
     452    my ( $self, $md5_sums ) = @_;
     453       
     454        # md5_sums is an array ref
     455        $self->_execute_post({
     456        method      => 'pwg.images.exist',
     457        md5sum_list => join(',', @$md5_sums)
     458            }
     459        );
     460
     461        my $sums = $self->_json_response_content->{result};
     462
     463    $sums;
    355464}
    356465
     
    363472    };
    364473
    365     my $result = $self->uagent->post(
    366         $self->urlbase.'/ws.php?format=json',
    367         $form
    368     );
    369 
    370     my $hresult = {};
    371     eval {
    372         $hresult = from_json(
    373             $result->{_content}
    374         );
    375     };
    376     my $id;
    377     $id = $hresult->{result}{$self->sum_original_file} if 'ok' eq $hresult->{stat};
    378    
     474    $self->_execute_post($form);   
     475    my $hresult = $self->_json_response_content;
     476
     477        $hresult->{result} = {} if 'HASH' ne ref $hresult->{result};
     478    my $id = 'ok' eq $hresult->{stat} ? $hresult->{result}{$md5_sum} : undef ;
     479
    379480    $id;
    380481}
     
    405506
    406507sub _send_chunks {
    407     my ( $self, $type, $progress ) = @_;
     508    my ( $self, $type_code, $progress ) = @_;
    408509
    409510    my $msg = {
     
    419520    };
    420521
    421     $progress->{current_msg} = $progress->{$msg->{$type}};
     522    $progress->{current_msg} = $progress->{$msg->{$type_code}};
    422523    $progress->{yield}->();
    423524
    424525    my $params = {
    425          filepath      => $filepath->{$type},
    426          type          => $type,
    427          original_sum  => $self->sum_original_file,
    428     };
    429 
     526         filepath      => $filepath->{$type_code},
     527         type          => $type_code,
     528         original_sum  => $self->sum->{original},
     529    };
     530print Dumper $params;
    430531    $self->send_chunks(
    431532       $params,
     
    446547       
    447548    };
    448 
    449     my $result = $self->uagent->post(
    450         $self->urlbase.'/ws.php?format=json',
    451         $form
    452     );
    453 
    454     my $content = {};
    455         eval {
    456             $content = from_json(
    457                 $result->content
    458             );
    459         };
    460 
    461     return ( $result->is_success, $result->status_line, $content );
    462549       
     550    return ( $self->_execute_post($form), $self->_json_response_content );
    463551}
    464552
     
    474562    };
    475563
    476     my $result = $self->uagent->post(
    477         $self->urlbase.'/ws.php?format=json',
    478         $form
    479     );
    480 
    481     my $content = {};
    482         eval {
    483             $content = from_json(
    484                 $result->content
    485             );
    486         };
    487 
    488     return ( $result->is_success, $result->status_line, $content );
    489        
     564    return ( $self->_execute_post($form), $self->_json_response_content );
    490565}
    491566
Note: See TracChangeset for help on using the changeset viewer.