|
|
@@ -59,7 +59,9 @@ while($request->Accept() >= 0) { |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
my($code, $type, $data) = process_query($method, $path, $qs, $post, $user); |
|
|
|
my($code, $hdr, $type, $data) = process_query($method, $path, $qs, $post, $user); |
|
|
|
|
|
|
|
$hdr = [ ] if !defined $hdr; |
|
|
|
|
|
|
|
if ( defined $type ) { |
|
|
|
if ( $type eq 'application/json' ) { |
|
|
@@ -67,22 +69,23 @@ while($request->Accept() >= 0) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
send_response($code, $type, $data); |
|
|
|
send_response($code, $hdr, $type, $data); |
|
|
|
} |
|
|
|
|
|
|
|
sub send_response { |
|
|
|
my ($code, $type, $data) = @_; |
|
|
|
my ($code, $hdr, $type, $data) = @_; |
|
|
|
|
|
|
|
printf("Status: %s\r\n", $code); |
|
|
|
printf("Content-type: %s\r\n", $type) if defined $type; |
|
|
|
printf("Content-length: %i\r\n", length($data)) if defined $data; |
|
|
|
foreach ( @{$hdr} ) { printf("%s\r\n",$_); } |
|
|
|
printf("\r\n"); |
|
|
|
print $data if defined $data; |
|
|
|
} |
|
|
|
|
|
|
|
sub fatal_api_error { |
|
|
|
my($code,$type,$body)=api_error(@_); |
|
|
|
send_response($code, $type, $body); |
|
|
|
send_response($code, undef, $type, $body); |
|
|
|
exit; |
|
|
|
} |
|
|
|
|
|
|
@@ -163,7 +166,7 @@ sub db_get_document_object { |
|
|
|
return (200, "application/json", $out); |
|
|
|
} |
|
|
|
|
|
|
|
return (404, "application/json", ""); |
|
|
|
return (404, undef, "application/json", ""); |
|
|
|
} |
|
|
|
|
|
|
|
sub db_get_page_object { |
|
|
@@ -196,7 +199,7 @@ sub db_get_page_object { |
|
|
|
return (200, "application/json", $out); |
|
|
|
} |
|
|
|
|
|
|
|
return (404, "application/json", ""); |
|
|
|
return (404, undef, "application/json", ""); |
|
|
|
} |
|
|
|
|
|
|
|
sub get_page_image { |
|
|
@@ -220,7 +223,7 @@ sub get_page_image { |
|
|
|
$conf->{path}{global}, $conf->{path}{error_img}); |
|
|
|
} |
|
|
|
else { |
|
|
|
$src = sprintf("%s/%s/%s.jpeg", |
|
|
|
$src = sprintf("%s/%s/%s", |
|
|
|
$conf->{path}{global}, $conf->{path}{original}, $id); |
|
|
|
} |
|
|
|
|
|
|
@@ -255,13 +258,17 @@ sub get_page_image { |
|
|
|
$imgfile = $dst; |
|
|
|
} |
|
|
|
|
|
|
|
my $img = ''; |
|
|
|
open(IMG, $imgfile) || fatal_api_error(500,"Failed to generate image"); |
|
|
|
binmode(IMG); |
|
|
|
while(<IMG>) { $img.=$_; } |
|
|
|
close(IMG); |
|
|
|
my $url = $dst; |
|
|
|
$url =~ s/$conf->{path}{global}//; |
|
|
|
return $url; |
|
|
|
|
|
|
|
#my $img = ''; |
|
|
|
#open(IMG, $imgfile) || fatal_api_error(500,"Failed to generate image"); |
|
|
|
#binmode(IMG); |
|
|
|
#while(<IMG>) { $img.=$_; } |
|
|
|
#close(IMG); |
|
|
|
|
|
|
|
return $img; |
|
|
|
#return $img; |
|
|
|
} |
|
|
|
|
|
|
|
# create an empty document object. |
|
|
@@ -307,7 +314,7 @@ sub api_v1_POST_documents_id_data { |
|
|
|
print F $post->{data}; |
|
|
|
close(F); |
|
|
|
|
|
|
|
return (200, "application/json", { }) |
|
|
|
return (200, undef, "application/json", { }) |
|
|
|
} |
|
|
|
|
|
|
|
# get document image/thumbnail |
|
|
@@ -327,7 +334,9 @@ sub api_v1_GET_documents_id_image { |
|
|
|
# get page image/thumbnail |
|
|
|
sub api_v1_GET_pages_id_image { |
|
|
|
my($id, $qs, $post, $user) = @_; |
|
|
|
return (200, "image/jpeg", get_page_image($id, $qs)); |
|
|
|
#return (200, "image/jpeg", get_page_image($id, $qs)); |
|
|
|
my $url = get_page_image($id, $qs); |
|
|
|
return (302, [ "Location: $url" ]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@@ -350,6 +359,7 @@ sub api_v1_GET_documents { |
|
|
|
|
|
|
|
return ( |
|
|
|
200, |
|
|
|
undef, |
|
|
|
"application/json", |
|
|
|
\@out |
|
|
|
); |
|
|
@@ -420,7 +430,7 @@ sub api_error { |
|
|
|
$code = "000" if !defined $code; |
|
|
|
$text = $deftext{$code} if ( !defined $text || $code eq "000" ); |
|
|
|
|
|
|
|
return ( $code, "text/plain", $text . "\r\n" ); |
|
|
|
return ( $code, undef, "text/plain", $text . "\r\n" ); |
|
|
|
} |
|
|
|
|
|
|
|
sub parse_querystring { |