Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[fotobilder] r1466: LJSUP-11945 (API didnt create new album)

Committer: ailyin
LJSUP-11945 (API didnt create new album)
U   trunk/lib/FB/Protocol/Fotki/UploadPic.pm
Modified: trunk/lib/FB/Protocol/Fotki/UploadPic.pm
===================================================================
--- trunk/lib/FB/Protocol/Fotki/UploadPic.pm	2012-04-24 15:29:29 UTC (rev 1465)
+++ trunk/lib/FB/Protocol/Fotki/UploadPic.pm	2012-04-25 11:52:29 UTC (rev 1466)
@@ -193,24 +193,36 @@
     return $err->(401) if $free_space <= 0;
     return $err->(402) if $free_space < $length;
 
-    # TODO: process Galleries: add uploaded photo into specified galleries (albums)
-    
+    my $album;
+    if ( $vars->{'Gallery'} && @{ $vars->{'Gallery'} } ) {
+        my ($galvar) = @{ $vars->{'Gallery'} };
+        if ( my $album_id = $galvar->{'GalID'} ) {
+            $album = LJ::Pics::Album->load( $lj_user, $album_id );
 
-    # to which galleries should this picture be added?
-    my @albums;
-  GALLERY:
-    foreach my $gvar (@{$vars->{Gallery}}) {
+        } elsif ( my $album_title = $galvar->{'GalName'} ) {
+            my @albums = LJ::Pics::Album->list( 'userid' => $lj_userid );
+            ($album) = grep { $_->album_title eq $album_title } @albums;
 
-        # TODO here
+            unless ($album) {
+                my $galsec = $galvar->{'GalSec'};
 
+                my ( $security, $allowmask ) =
+                    FB::Protocol::Fotki->fb2lj_security($galsec);
 
+                $album = LJ::Pics::Album->create(
+                    'userid'      => $lj_userid,
+                    'album_title' => $album_title,
+                    'security'    => $security,
+                    'allowmask'   => $allowmask,
+                );
+            }
+        }
     }
 
     # use default upload album if no albums specified
-    unless (@albums) {
-        my $a = LJ::Pics::Album->default_album( $lj_user, 'create' => 1 )
+    unless ($album) {
+        $album = LJ::Pics::Album->default_album( $lj_user, 'create' => 1 )
             or return $err->(502 => "Cannot load default album");
-        push @albums, $a;
     }
 
     # now we're finished with all input error checking, and we know that all the
@@ -267,36 +279,33 @@
     return $err->(510) unless $content; # should never happen, but be safe
 
     # add photo to all necessary albums
-    my $photo;
-    foreach my $album (@albums) {
-        $photo = LJ::Pics::Photo->create(
-            'userid'     => $lj_userid,
-            'album_id'   => $album->album_id,
-            'security'   => $security,
-            'allowmask'  => $allowmask,
-        );
+    my $photo = LJ::Pics::Photo->create(
+        'userid'     => $lj_userid,
+        'album_id'   => $album->album_id,
+        'security'   => $security,
+        'allowmask'  => $allowmask,
+    );
 
-        my $upload_res = eval { $photo->upload_photo($content); 1 };
-        unless ($upload_res) {
-            $photo->delete;
-            return $err->( 510, $@ );
-        }
+    my $upload_res = eval { $photo->upload_photo($content); 1 };
+    unless ($upload_res) {
+        $photo->delete;
+        return $err->( 510, $@ );
+    }
 
-        return $err->(513 => 'Error adding photo to album '.$album->album_id) unless $photo;
-        # Meta information
-        # -- existence vs definition checked at top
-        if (defined $vars->{Meta}) {
-            my $meta = $vars->{Meta};
+    return $err->(513 => 'Error adding photo to album '.$album->album_id) unless $photo;
+    # Meta information
+    # -- existence vs definition checked at top
+    if (defined $vars->{Meta}) {
+        my $meta = $vars->{Meta};
 
-            # set photo title
-            if (defined $meta->{Title}) {
-                $photo->set_title($meta->{Title}) or return $err->(511 => "Couldn't set title prop");
-            }
+        # set photo title
+        if (defined $meta->{Title}) {
+            $photo->set_title($meta->{Title}) or return $err->(511 => "Couldn't set title prop");
+        }
 
-            # set photo description
-            if (defined $meta->{Description}) {
-                $photo->set_desc($meta->{Description}) or return $err->(511 => "Couldn't set Description");
-            }
+        # set photo description
+        if (defined $meta->{Description}) {
+            $photo->set_desc($meta->{Description}) or return $err->(511 => "Couldn't set Description");
         }
     }
 

Tags: ailyin, andy, fotobilder, pm
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments