Commit e2e20265 authored by eskumon's avatar eskumon
Browse files

fix(frontend): save screenshot in database

The screenshot is now storaged in the database and included as a JSON field

fixes #1180
parent 7821c005
......@@ -13,6 +13,8 @@ use Hash::Util qw(lock_keys);
use IPC::Run3 qw(run3);
use Moose;
use YAML qw(Load Dump LoadFile DumpFile);
use Image::Magick;
use MIME::Base64;
use Ravada::Volume;
......@@ -474,13 +476,13 @@ sub list_volumes_info($self, $attribute=undef, $value=undef) {
sub screenshot {
my $self = shift;
my $file = (shift or $self->_file_screenshot);
my @cmd =($CONVERT,'-size', '400x300', 'xc:white'
,$file
);
my ($in,$out,$err);
run3(\@cmd, \$in, \$out, \$err);
my $DPI = 300; # 600;
my $image = Image::Magick->new(density => $DPI,width=>100, height=>100);
$image = Image::Magick->new;
$image->Set(size=>'100x100');
$image->ReadImage('canvas:white');
$image->Set('pixel[49,49]'=>'red');
$self->_data(screenshot => encode_base64($image));
}
sub _file_screenshot {
......
......@@ -21,6 +21,7 @@ CREATE TABLE `domains` (
, `info` varchar(255) default NULL
, `internal_id` varchar(64) DEFAULT NULL
, `needs_resetart`int not null default 0
, `screenshot` BLOB
, UNIQUE (`id_base`,`name`)
, UNIQUE (`name`)
);
......@@ -360,37 +360,19 @@ sub test_json {
}
sub test_screenshot {
sub test_screenshot_db {
my $vm_name = shift;
my $domain= shift;
return if !$domain->can_screenshot;
my $file = "/var/tmp/screenshot.$$.png";
# diag("[$vm_name] testing screenshot");
$domain->start($USER) if !$domain->is_active;
sleep 2;
eval { $domain->screenshot($file) };
ok(!$@,"[$vm_name] $@");
$domain->screenshot();
$domain->shutdown(user => $USER, timeout => 1);
ok(-e $file,"[$vm_name] Checking screenshot $file");
ok(-e $file && -s $file,"[$vm_name] Checking screenshot $file should not be empty")
and do {
unlink $file or die "$! unlinking $file";
};
}
sub test_screenshot_file {
my $vm_name = shift;
my $domain= shift;
return if !$domain->can_screenshot;
my $file = $domain->_file_screenshot();
ok($file,"Expecting a screnshot filename, got '".($file or '<UNDEF>'));
my $sth = connector->dbh->prepare("SELECT screenshot FROM domains WHERE id=?");
$sth->execute($domain->id);
my @fields = $sth->fetchrow;
#ok($fields[0],"Expecting child node listen , got :'".substr( $fields[0], 0, 10 ) or ''));
ok($fields[0]);
}
sub test_change_interface {
......@@ -587,14 +569,13 @@ for my $vm_name ( vm_names() ) {
test_json($vm_name, $domain->name);
test_search_domain($domain);
test_screenshot_file($vm_name, $domain);
test_remove_domain($vm_name, $clone1);
test_remove_domain($vm_name, $clone2);
$domain->remove_base($USER);
test_manage_domain($vm_name, $domain);
test_screenshot($vm_name, $domain);
test_screenshot_db($vm_name, $domain);
test_shutdown_suspended_domain($vm_name, $domain);
test_pause_domain($vm_name, $domain);
......
......@@ -23,9 +23,9 @@
role="button">{{machine.name}}</a>
<i ng-show="!machine.is_public"><i class="far fa-eye-slash fa-xs" title="<%=l 'not public' %>"></i></i>
</h3>
<a ng-show="machine.screenshot" href="/machine/clone/{{machine.id}}.html"><img
ng-src="data:image/png;base64,{{machine.screenshot}}" alt="{{machine.description}}" class="img-thumbnail" width="260"
></a>
<a ng-show="machine.screenshot" href="/machine/clone/{{machine.id}}.html"><img
ng-src="data:image/png;base64,{{machine.screenshot}}" alt="{{machine.description}}" class="img-thumbnail" width="260"
></a>
<a ng-show="!machine.screenshot" href="/machine/clone/{{machine.id}}.html"><img
src="/img/default_screenshot.png" class="screenshot-default img-thumbnail"
alt="{{machine.description}}"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment