diff options
author | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2010-08-06 22:12:55 +0200 |
---|---|---|
committer | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2010-08-06 22:12:55 +0200 |
commit | 7cef7c08ebab0374f8dced2f047b5a8bf281c44c (patch) | |
tree | 77e355106206b39d311fab3849239d41e918189b /lib | |
parent | 1f63a948e0b2de15dba55610cd62f31f15e1167b (diff) |
Add save button.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LXRng/Web.pm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/LXRng/Web.pm b/lib/LXRng/Web.pm index 2ae3fa4..20ff899 100644 --- a/lib/LXRng/Web.pm +++ b/lib/LXRng/Web.pm @@ -821,6 +821,28 @@ sub generate_pdf { } +# Generate raw file for download + +sub generate_raw { + my ($query, $context, $template, $path) = @_; + + my $ver = $context->release; + my $rep = $context->config->{'repository'}; + my $node = $rep->node($path, $ver); + + die "No such file" unless $node; + + my $handle = $node->handle(); + print($query->header(-type => 'application/octet-stram', + -content_disposition => + "attachment; filename=$path")); + my $buf = ''; + while (sysread($handle, $buf, 65536) > 0) { + print($buf); + } +} + + sub handle { my ($self, $query) = @_; @@ -843,6 +865,9 @@ sub handle { elsif ($context->path =~ /^[+ ]print=(.*)/) { generate_pdf($query, $context, $template, $1); } + elsif ($context->path =~ /^[+ ]save=(.*)/) { + generate_raw($query, $context, $template, $1); + } else { if ($context->path =~ /^[+ ](search|code|ident|file|text|ambig)(?:=(.*)|)/) |