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

[ljcom] r9807: LJINT-362 (comments for side projects)

Committer: ailyin
LJINT-362 (comments for side projects)
U   trunk/htdocs/tools/endpoints/comments.bml
Modified: trunk/htdocs/tools/endpoints/comments.bml
===================================================================
--- trunk/htdocs/tools/endpoints/comments.bml	2010-12-07 06:41:19 UTC (rev 9806)
+++ trunk/htdocs/tools/endpoints/comments.bml	2010-12-07 08:39:49 UTC (rev 9807)
@@ -9,13 +9,24 @@
 
     my $url     = $GET{url};
     my $rskey   = $GET{rsk};
-    my $page    = int $GET{page} || 1;
-    my $thread  = int $GET{thread} || undef;
+    my $page    = int $GET{page}    || 0;
+    my $thread  = int $GET{thread}  || undef;
+    my $view    = int $GET{view}    || undef;
 
+    my $format  = $GET{'out'};
+    $format = 'JSONP' unless defined $format
+                         and $format =~ /^(?:JSON|JSONP)$/;
+
     ## wrapper and serialazer.
     my $answer = sub {
         my $data = shift;
-        return 'JSONP(' . LJ::JSON->to_json($data) . ')';
+        my $data_out = LJ::JSON->to_json($data);
+
+        if ( $format eq 'JSON' ) {
+            return $data_out;
+        } elsif ( $format eq 'JSONP' ) {
+            return "JSONP($data_out)";
+        }
     };
 
     ## convert remote-site key to lj.com's community
@@ -40,8 +51,8 @@
     my %user = ();
 
     my $opts = {
-        thread     => $thread,
-        #view       => $view_num,
+        thread     => int ($thread / 256),
+        view       => $view,
         page       => $page,
         userpicref => $userpics,
         userref    => \%user,
@@ -109,11 +120,11 @@
             } @$comments;
     };
 
-
     my @result = $to_export_format->($to_export_format, \@comments);
     return $answer->({ 
-        comments => \@result,
-        pages    => $opts->{out_pages},
-        });
+        'comments' => \@result,
+        'pages'    => $opts->{'out_pages'},
+        'page'     => $opts->{'out_page'},
+    });
 
 } _code?>

Tags: andy, bml, ljcom
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