瀏覽代碼

image redirect

master
root 5 年之前
父節點
當前提交
9f041b05a7
共有 4 個檔案被更改,包括 34 行新增20 行删除
  1. 26
    16
      cgi/autodoc.fcgi
  2. 1
    1
      etc/autodoc.json.default
  3. 5
    1
      www/css/autodoc.css
  4. 2
    2
      www/index.html

+ 26
- 16
cgi/autodoc.fcgi 查看文件

@@ -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 {

+ 1
- 1
etc/autodoc.json.default 查看文件

@@ -1,7 +1,7 @@
{
"path": {
"global": "/opt/autodoc",
"originals": "var/originals",
"original": "var/original",
"images": "var/images",
"cache": "var/cache",
"error_img": "var/error_img.jpeg"

+ 5
- 1
www/css/autodoc.css 查看文件

@@ -17,4 +17,8 @@ html body {
.autodoc_upload_zone_hover {
background-color: #8C959D;
border-color: #333;
}
}

.autodoc_img {
height: 343px;
}

+ 2
- 2
www/index.html 查看文件

@@ -63,7 +63,7 @@
<div class="col autodoc_template_home_col text-center">
<table class="table table-borderless table-sm small">
<tr>
<td colspan="2" class="text-center">
<td colspan="2" class="text-center autodoc_img">
<img class="autodoc_template_home_img img-thumbnail rounded" src="" />
</td>
</tr>
@@ -158,4 +158,4 @@
<script src="js/autodoc.js"></script>
</body>

</html>
</html>

Loading…
取消
儲存