Committer: ailyin
LJSUP-10815 (Fotki.ru: store data on our own servers)U trunk/lib/FB/Protocol/Fotki/CreateGals.pm U trunk/lib/FB/Protocol/Fotki/GetGals.pm U trunk/lib/FB/Protocol/Fotki/GetGalsTree.pm U trunk/lib/FB/Protocol/Fotki/GetPics.pm U trunk/lib/FB/Protocol/Fotki/Login.pm U trunk/lib/FB/Protocol/Fotki/UploadPic.pm U trunk/lib/FB/Protocol/Fotki/UploadPrepare.pm U trunk/lib/FB/Protocol/Fotki/UploadTempFile.pm U trunk/lib/FB/Protocol/Response.pm
Modified: trunk/lib/FB/Protocol/Fotki/CreateGals.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/CreateGals.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/CreateGals.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -6,7 +6,7 @@ use strict; -use LJ::Fotki::Album; +use LJ::Pics::Album; sub handler { my $resp = shift or return undef; @@ -58,15 +58,21 @@ my $album; eval { - $album = LJ::Fotki::Album->create(userid => $lj_userid, album_title => $galname, album_desc => '', security => $security, allowmask => $allowmask); + $album = LJ::Pics::Album->create( + 'userid' => $lj_userid, + 'album_title' => $galname, + 'album_desc' => '', + 'security' => $security, + 'allowmask' => $allowmask, + ); }; - return $err->(512 => 'Error creation LJ Fotki album' ) if $@; + return $err->(512 => 'Error creating LJ Pics album' ) if $@; - return $err->(512 => 'Error creation LJ Fotki album' ) unless($album); + return $err->(512 => 'Error creating LJ Pics album' ) unless($album); push @{$ret->{Gallery}}, { GalID => [ $album->album_id ], - GalName => [ $album->title ], - GalURL => [ $album->url ] }; + GalName => [ $album->album_title ], + GalURL => [ $album->page_url ] }; } Modified: trunk/lib/FB/Protocol/Fotki/GetGals.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/GetGals.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/GetGals.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -5,7 +5,7 @@ use FB::Protocol::Fotki; use strict; -use LJ::Fotki::Album; +use LJ::Pics; sub handler { my $resp = shift or return undef; @@ -21,7 +21,7 @@ my $lj_user = LJ::load_userid($lj_userid); # TODO: eval to catch all errors - my $albums = LJ::Fotki::Album->get_albums($lj_userid, $lj_user); + my $albums = [ LJ::Pics::Album->list( 'userid' => $lj_userid ) ]; my $ret = {Gal => [] }; @@ -30,17 +30,17 @@ next unless($album); my $album_ret = { id => $album->album_id, - Name => [ FB::transform_gal_name($album->title) ], - Sec => [ FB::Protocol::Fotki->lj2fb_security($album->get_security, $album->get_mask) ], + Name => [ FB::transform_gal_name($album->album_title) ], + Sec => [ FB::Protocol::Fotki->lj2fb_security($album->security, $album->allowmask) ], Date => [ FB::date_unix_to_mysql($album->timecreate) ], ($album->timeupdate ? (TimeUpdate => [ $album->timeupdate ]) : ()), - URL => [ $album->url ], + URL => [ $album->page_url ], }; # is this the incoming gallery? $album_ret->{incoming} = 1 if $album->is_default; # GalMembers - my $photos = $album->get_all_photos($lj_user); + my $photos = [ $album->photos ]; $album_ret->{GalMembers}->{GalMember} = [ map { { id => $_->photo_id } } @$photos ]; # ParentGals Modified: trunk/lib/FB/Protocol/Fotki/GetGalsTree.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/GetGalsTree.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/GetGalsTree.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -4,7 +4,7 @@ use FB::Protocol::Fotki; use strict; -use LJ::Fotki::Album; +use LJ::Pics; sub handler { my $resp = shift or return undef; @@ -20,7 +20,7 @@ my $lj_userid = FB::get_domain_userid($u); my $lj_user = LJ::load_userid($lj_userid); - my $albums = LJ::Fotki::Album->get_albums($lj_userid, $lj_user); + my $albums = [ LJ::Pics::Album->list( 'userid' => $lj_userid ) ]; return $err->(500) unless ref $albums; @@ -34,17 +34,17 @@ next unless($album); my $album_ret = { id => $album->album_id, - Name => [ $album->title ], - Sec => [ FB::Protocol::Fotki->lj2fb_security($album->get_security, $album->get_mask) ], + Name => [ $album->album_title ], + Sec => [ FB::Protocol::Fotki->lj2fb_security($album->security, $album->allowmask) ], Date => [ FB::date_unix_to_mysql($album->timecreate) ], # gallery creation date in 2004-01-01 01:01:01 format ($album->timeupdate ? (TimeUpdate => [ $album->timeupdate ]) : ()), # update timestamp - URL => [ $album->url ], + URL => [ $album->page_url ], }; # is this the incoming gallery? $album_ret->{incoming} = 1 if $album->is_default; # GalMembers - my $photos = $album->get_all_photos($lj_user); + my $photos = [ $album->photos ]; $album_ret->{GalMembers}->{GalMember} = [ map { { id => $_->photo_id } } @$photos ]; # ChildGals Modified: trunk/lib/FB/Protocol/Fotki/GetPics.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/GetPics.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/GetPics.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -5,7 +5,7 @@ use FB::Protocol::Fotki; use strict; -use LJ::Fotki::Photo; +use LJ::Pics; sub handler { my $resp = shift or return undef; @@ -22,7 +22,7 @@ my $lj_user = LJ::load_userid($lj_userid); # TODO: eval to catch all errors - my $photos = LJ::Fotki::Photo->get_all_photos($lj_userid, $lj_user); + my $photos = [ LJ::Pics::Photo->list( 'userid' => $lj_userid ) ]; my $ret = { Pic => [] }; @@ -32,20 +32,18 @@ push @{$ret->{Pic}}, { id => $photo->photo_id, - Sec => [ FB::Protocol::Fotki->lj2fb_security($photo->get_security, $photo->get_mask) ], # TODO: convert mask to FB format - Width => [ $photo->orig_width ], - Height => [ $pic->orig_height ], - Bytes => [ $pic->orig_size ], + Sec => [ FB::Protocol::Fotki->lj2fb_security($photo->security, $photo->allowmask) ], # TODO: convert mask to FB format + Width => [ $photo->prop('width') ], + Height => [ $photo->prop('height') ], + Bytes => [ $photo->prop('filesize') ], # Format => [ FB::fmtid_to_mime($pic->{fmtid}) ], # TODO: Format of the original photo # MD5 => [ FB::bin_to_hex($gpic_md5->{$pic->{gpicid}}) ], - URL => [ $photo->orig_url ], - Meta => [ map { - { name => $_->[0], - content => $pic->($_->[1])() } - } ( #['filename' => 'filename' ], # TODO: To be done - ['title' => 'title' ], - ['description' => 'desc' ]) - ], + URL => [ $photo->image_url( 'size' => 'original' ) ], + Meta => [ + { 'name' => 'title', 'content' => $photo->prop('title') }, + { 'name' => 'description', 'content' => $photo->prop('description') }, + # TODO: filename + ], }; } Modified: trunk/lib/FB/Protocol/Fotki/Login.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/Login.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/Login.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -4,7 +4,7 @@ use strict; -use LJ::Fotki::UserSpace; +use LJ::Pics; sub handler { my $resp = shift or return undef; @@ -28,16 +28,11 @@ LJ::Request->notes(ProtocolClientVersion => $vars->{ClientVersion}); } - # Get available space for the user - my $spaces = LJ::Fotki::UserSpace->get_spaces($lj_user); - if (ref $spaces eq 'ARRAY') { - my $free_space = $spaces->[3] - $spaces->[0]; - $free_space = 0 if $free_space < 0; $ret->{Quota} = { - Total => [ $spaces->[3] ], # kb -> bytes - Used => [ $spaces->[0] ], - Remaining => [ $free_space ], + Total => [ LJ::Pics->get_available_space($lj_user) ], + Used => [ LJ::Pics->get_occupied_space($lj_user) ], + Remaining => [ LJ::Pics->get_free_space($lj_user) ], }; } Modified: trunk/lib/FB/Protocol/Fotki/UploadPic.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/UploadPic.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/UploadPic.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -5,9 +5,7 @@ use FB::Protocol::Fotki; use strict; -use LJ::Fotki; -use LJ::Fotki::Album; -use LJ::Fotki::UserSpace; +use LJ::Pics; sub handler { my $resp = shift or return undef; @@ -191,9 +189,9 @@ } # call hook to check if user has disk space for picture before uploading - my $spaces = LJ::Fotki::UserSpace->get_spaces($lj_user); - return $err->(401) if $spaces->[3] <= 0; - return $err->(402) if $spaces->[3] < $length; + my $free_space = LJ::Pics->get_free_space($lj_user); + return $err->(401) if $free_space <= 0; + return $err->(402) if $free_space < $length; # TODO: process Galleries: add uploaded photo into specified galleries (albums) @@ -210,7 +208,7 @@ # use default upload album if no albums specified unless (@albums) { - my $a = LJ::Fotki::Album->get_default_album($lj_user) + my $a = LJ::Pics::Album->default_album( $lj_user, 'create' => 1 ) or return $err->(502 => "Cannot load default album"); push @albums, $a; } @@ -268,20 +266,24 @@ # definitely have a $gpic now, either from above or from an existing receipt return $err->(510) unless $content; # should never happen, but be safe - # upload photo to fotki and create - my $upload_res; - eval { - $upload_res = LJ::Fotki->upload_photo($lj_user, $content, debug => 1); - }; - return $err->(510 => $@) if $@; - - my $photo_data = $upload_res->{'photo_data'}; - my $version = $upload_res->{'api_version'}; - # add photo to all necessary albums my $photo; foreach my $album (@albums) { - $photo = LJ::Fotki::Photo->create(userid => $lj_userid, album_id => $album->album_id, photo_data => $photo_data, version => $version, security => $security, allowmask => $allowmask); + $photo = LJ::Pics::Photo->create( + 'userid' => $lj_userid, + 'album_id' => $album->album_id, + 'photo_data' => $photo_data, + 'version' => $version, + 'security' => $security, + 'allowmask' => $allowmask, + ); + + 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 Modified: trunk/lib/FB/Protocol/Fotki/UploadPrepare.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/UploadPrepare.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/UploadPrepare.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -6,7 +6,7 @@ use strict; -use LJ::Fotki::UserSpace; +use LJ::Pics; sub handler { my $resp = shift or return undef; @@ -29,16 +29,13 @@ my $ret = {}; -# Get available space for the user - my $spaces = LJ::Fotki::UserSpace->get_spaces($lj_user); - if (ref $spaces eq 'ARRAY') { my $free_space = $spaces->[3] - $spaces->[0]; $free_space = 0 if $free_space < 0; $ret->{Quota} = { - Total => [ $spaces->[3] ], # kb -> bytes - Used => [ $spaces->[0] ], - Remaining => [ $free_space ], + Total => [ LJ::Pics->get_available_space($lj_user) ], + Used => [ LJ::Pics->get_occupied_space($lj_user) ], + Remaining => [ LJ::Pics->get_free_space($lj_user) ], }; } Modified: trunk/lib/FB/Protocol/Fotki/UploadTempFile.pm =================================================================== --- trunk/lib/FB/Protocol/Fotki/UploadTempFile.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Fotki/UploadTempFile.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -5,7 +5,7 @@ use FB::Protocol::Fotki; use strict; -use LJ::Fotki::UserSpace; +use LJ::Pics; sub handler { my $resp = shift or return undef; @@ -76,9 +76,9 @@ # call hook to check if user has disk space for picture before uploading - my $spaces = LJ::Fotki::UserSpace->get_spaces($lj_user); - return $err->(401) if $spaces->[3] <= 0; - return $err->(402) if $spaces->[3] < $length; + my $free_space = LJ::Pics->get_free_space($lj_user); + return $err->(401) if $free_space <= 0; + return $err->(402) if $free_space < $length; # generate a rcptkey for this receipt my $rcptkey = FB::rand_chars(20); Modified: trunk/lib/FB/Protocol/Response.pm =================================================================== --- trunk/lib/FB/Protocol/Response.pm 2011-11-30 18:37:38 UTC (rev 1456) +++ trunk/lib/FB/Protocol/Response.pm 2011-12-19 14:10:25 UTC (rev 1457) @@ -10,7 +10,7 @@ use Carp; use XML::Simple (); - use LJ::Fotki::Migration; + use LJ::Pics; # methods @@ -164,7 +164,7 @@ if ($vars->{Version}) { $ver = 2 if ($vars->{Version} eq 'fotki'); } else { - $ver = LJ::Fotki::Migration->user_enabled_new_photohosting($lj_user) ? 2 : 1; + $ver = LJ::Pics::Migration->user_enabled_new_photohosting($lj_user) ? 2 : 1; } # run individual methods