From 75e1de74a14dd456bb2e6ec8b8372947c1d8e7d7 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Sun, 26 Jun 2016 12:30:47 -0400 Subject: [PATCH] Allow ajax calls for eval. --- app.pl | 9 ++++----- lib/Eval/Perlbot.pm | 4 ++-- pastes.db | Bin 12288 -> 12288 bytes templates/editor.html | 43 +++++++++++++++++++++++++++++++++++++----- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/app.pl b/app.pl index 21a484a..0c03b47 100755 --- a/app.pl +++ b/app.pl @@ -106,14 +106,13 @@ get '/pastebin/:pasteid' => sub { }; -get '/eval/:pasteid' => sub { +post '/eval' => sub { my ($c) = @_; - my $pasteid = $c->param('pasteid'); + my $data = $c->req->body_params; - my $row = $dbh->selectrow_hashref("SELECT * FROM posts WHERE id = ? LIMIT 1", {}, $pasteid); - my $code = $row->{paste} // ''; + my $code = $data->param('code') // ''; - my $output = get_eval($pasteid, $code); + my $output = get_eval(undef, $code); $c->render(json => {evalout => $output}); }; diff --git a/lib/Eval/Perlbot.pm b/lib/Eval/Perlbot.pm index a852ddf..302222b 100644 --- a/lib/Eval/Perlbot.pm +++ b/lib/Eval/Perlbot.pm @@ -16,7 +16,7 @@ use App::Memcached; sub get_eval { my ($paste_id, $code) = @_; - if (my $cached = $memd->get($paste_id)) { + if ($paste_id && (my $cached = $memd->get($paste_id))) { return $cached; } else { my $filter = POE::Filter::Reference->new(); @@ -31,7 +31,7 @@ sub get_eval { my $result = $filter->get( [ $output ] ); my $str = eval {decode("utf8", $result->[0]->[0])} // $result->[0]->[0]; $str = eval {decode("utf8", $str)} // $str; # I don't know why i need to decode this twice. shurg. - $memd->set($paste_id, $str); + $memd->set($paste_id, $str) if ($paste_id); return $str; } diff --git a/pastes.db b/pastes.db index bdbb9ffe476eb24cb9c765d1cc42d45f58b56a54..2c3ae0d89d17c0a3472e194325ddbaf6a0da00d2 100644 GIT binary patch delta 228 zcmZojXh@hK&1gMQ#+lK2W5RrHMypLcEDC(AjE@+Yk2Ci%D>F@He6+Ff0%LunffWZs zQz$PlFH2f}k%ESSo}Q(prb0C@mjV#vRw}3@rKT1s*eY0B>Z-(BLxhVHD;1O=5=r?b zB{`|Z3i)XYV1@a43MCn-3gwA8IXX%NmFt&+- XNG!@P%}W6rR~ufyEVOy5UN$2DFt$M5 delta 45 zcmZojXh@hK&1f}I#+lJ-W5RrHM$1h+EDAgF^qSlG(6d8%GEBLFGy B4D$d0 diff --git a/templates/editor.html b/templates/editor.html index fc40a48..7e46ce9 100755 --- a/templates/editor.html +++ b/templates/editor.html @@ -49,15 +49,29 @@
-
- -
-        
+ +
+
+ +
+            
+
+ +
-
+
@@ -85,5 +99,24 @@ $("#paste").text(editor.getValue()); // copy to the textarea }); + $('#evalme').on('click', function () { + $('#eval').text("Evaluating..."); + $('#evalcol').removeClass(); + + if (1) { // Eval, no docs + $('#evalcol').addClass('col-md-6'); + $('#editors').removeClass().addClass('col-md-6'); + $.ajax('/eval', { + method: 'post', + data: {code: editor.getValue()}, + dataType: "json", + success: function(data, status) { + $('#eval').text(data.evalout); + } + }); + } else if (0) { // Eval with docs + } + }); + [% END %]