use EPrints;

use strict;

# Make sure we don't accidentally start another progress for this request
my $session = EPrints::Session->new( 2 );

my $progress = EPrints::DataObj::UploadProgress->new_from_request( $session );

if( !$progress )
{
	$session->not_found( "No such file upload in progress" );
	$session->terminate;
	exit(0);
}

my $content = $progress->export( 'JSON' );

my $r = $session->get_request;

# Based on Apache2::UploadProgress
$r->headers_out->set( 'Vary' => 'Accept' );
$r->headers_out->set( 'Pragma'        => 'no-cache' );
$r->headers_out->set( 'Expires'       => 'Thu, 01 Jan 1970 00:00:00 GMT' );
$r->headers_out->set( 'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0' );

$r->content_type( "application/json" );
$r->set_content_length( length $content );
$r->write( $content );

$session->terminate;
