From 4d9a81cc6480cdbb45d5ce2c3ae6a4776495e02e Mon Sep 17 00:00:00 2001 From: Banana Date: Fri, 30 Nov 2012 13:40:11 +0100 Subject: [PATCH] create and delete a screenshot --- lib/Insipid/Main.pm | 39 ++++++++++++++++++++++++++++----------- lib/screen.js | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/Insipid/Main.pm b/lib/Insipid/Main.pm index 73e37b9..78914a0 100755 --- a/lib/Insipid/Main.pm +++ b/lib/Insipid/Main.pm @@ -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 '

creating screenshot...

'; + print '

Creating screenshot... Please wait...

'; - 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 '

Success !

'; } else { - printf "child exited with value %d\n", $? >> 8; + print "

Screenshot creation failed.

"; + 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 "

Screenshot available: see it here. Re-Create to refresh.

"; + } + print <

$title : $url

@@ -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 diff --git a/lib/screen.js b/lib/screen.js index 96a444b..fa76db8 100644 --- a/lib/screen.js +++ b/lib/screen.js @@ -26,7 +26,7 @@ else { page.render(output); phantom.exit(0); - }, 100); + }, 50); } }); } \ No newline at end of file -- 2.39.5