]> 91.132.146.200 Git - insipid.git/commitdiff
create and delete a screenshot
authorBanana <banana@starscream.de>
Fri, 30 Nov 2012 12:40:11 +0000 (13:40 +0100)
committerBanana <banana@starscream.de>
Fri, 30 Nov 2012 12:40:11 +0000 (13:40 +0100)
lib/Insipid/Main.pm
lib/screen.js

index 73e37b95d0477da2a8f15a5c4e8cb6e784455011..78914a00c8575c6f8ac2976a0a3584b3b796a4f1 100755 (executable)
@@ -425,28 +425,37 @@ FORM
                 }
             }
             my ($url, $title, $description, $access_level, $md5) = get_bookmark($id);
+            my $screnshotNameFile = "./screenshots/".$md5.".png";
 
             if (defined(param('create_screenshot')) && param('create_screenshot') eq '1') {
 
-                print '<p>creating screenshot...</p>';
+                print '<p>Creating screenshot... Please wait...</p>';
 
-                my $output = `$phantomjsPath --proxy=10.0.1.11:80 ./lib/screen.js $url ./screenshots/$md5.png`;
-
-                if ($? == -1) {
-                    print "failed to execute: $!\n";
-                }
-                elsif ($? & 127) {
-                    printf "child died with signal %d, %s coredump\n",
-                        ($? & 127),  ($? & 128) ? 'with' : 'without';
+                my $output = `$phantomjsPath --proxy=10.0.1.11:80 ./lib/screen.js $url $screnshotNameFile`;
+                if($? == 0) {
+                    print '<p style="color: green;">Success !</p>';
                 }
                 else {
-                    printf "child exited with value %d\n", $? >> 8;
+                    print "<p>Screenshot creation failed.<p>";
+                    if ($? == -1) {
+                        print "failed to execute: $!\n";
+                    }
+                    elsif ($? & 127) {
+                        printf "child died with signal %d, %s coredump\n",
+                            ($? & 127),  ($? & 128) ? 'with' : 'without';
+                    }
+                    else {
+                        printf "child exited with value %d\n", $? >> 8;
+                    }
                 }
             }
             else {
 
+                 if(-e $screnshotNameFile) {
+                    print "<p>Screenshot available: <a href='$screnshotNameFile'>see it here.</a> Re-Create to refresh.<p>";
+                 }
+
              print <<FORM;
-          <br />
           <p>$title : $url</p>
           <form method="post">
             <input type="hidden" name="op" value="screenshot" />
@@ -905,6 +914,14 @@ sub delete_bookmark {
 
     check_access();
 
+    # delete screenshot
+    my ($url, $title, $description, $access_level, $md5) = get_bookmark($id);
+    if(-e './screenshots/'.$md5.".png") {
+        unlink('./screenshots/'.$md5.".png");
+    }
+
+    $md5 = '';
+
     # Check for cached version to delete.
     $sql = "select $tbl_pagecache.md5 from $tbl_pagecache
                inner join $tbl_bookmarks on
index 96a444b9af17cc44d49a3585ea8b98fb38dd7b27..fa76db88fa08816c7923ee64a484d7f3ac03cee9 100644 (file)
@@ -26,7 +26,7 @@ else {
                                page.render(output);
 
                                phantom.exit(0);
-                       }, 100);
+                       }, 50);
            }
        });
 }
\ No newline at end of file