Browse Source

image redirect

master
root 6 years ago
parent
commit
9f041b05a7
4 changed files with 34 additions and 20 deletions
  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 View File

); );




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 ( defined $type ) {
if ( $type eq 'application/json' ) { if ( $type eq 'application/json' ) {
} }
} }


send_response($code, $type, $data);
send_response($code, $hdr, $type, $data);
} }


sub send_response { sub send_response {
my ($code, $type, $data) = @_;
my ($code, $hdr, $type, $data) = @_;


printf("Status: %s\r\n", $code); printf("Status: %s\r\n", $code);
printf("Content-type: %s\r\n", $type) if defined $type; printf("Content-type: %s\r\n", $type) if defined $type;
printf("Content-length: %i\r\n", length($data)) if defined $data; printf("Content-length: %i\r\n", length($data)) if defined $data;
foreach ( @{$hdr} ) { printf("%s\r\n",$_); }
printf("\r\n"); printf("\r\n");
print $data if defined $data; print $data if defined $data;
} }


sub fatal_api_error { sub fatal_api_error {
my($code,$type,$body)=api_error(@_); my($code,$type,$body)=api_error(@_);
send_response($code, $type, $body);
send_response($code, undef, $type, $body);
exit; exit;
} }


return (200, "application/json", $out); return (200, "application/json", $out);
} }


return (404, "application/json", "");
return (404, undef, "application/json", "");
} }


sub db_get_page_object { sub db_get_page_object {
return (200, "application/json", $out); return (200, "application/json", $out);
} }


return (404, "application/json", "");
return (404, undef, "application/json", "");
} }


sub get_page_image { sub get_page_image {
$conf->{path}{global}, $conf->{path}{error_img}); $conf->{path}{global}, $conf->{path}{error_img});
} }
else { else {
$src = sprintf("%s/%s/%s.jpeg",
$src = sprintf("%s/%s/%s",
$conf->{path}{global}, $conf->{path}{original}, $id); $conf->{path}{global}, $conf->{path}{original}, $id);
} }


$imgfile = $dst; $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. # create an empty document object.
print F $post->{data}; print F $post->{data};
close(F); close(F);


return (200, "application/json", { })
return (200, undef, "application/json", { })
} }


# get document image/thumbnail # get document image/thumbnail
# get page image/thumbnail # get page image/thumbnail
sub api_v1_GET_pages_id_image { sub api_v1_GET_pages_id_image {
my($id, $qs, $post, $user) = @_; 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" ]);


} }




return ( return (
200, 200,
undef,
"application/json", "application/json",
\@out \@out
); );
$code = "000" if !defined $code; $code = "000" if !defined $code;
$text = $deftext{$code} if ( !defined $text || $code eq "000" ); $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 { sub parse_querystring {

+ 1
- 1
etc/autodoc.json.default View File

{ {
"path": { "path": {
"global": "/opt/autodoc", "global": "/opt/autodoc",
"originals": "var/originals",
"original": "var/original",
"images": "var/images", "images": "var/images",
"cache": "var/cache", "cache": "var/cache",
"error_img": "var/error_img.jpeg" "error_img": "var/error_img.jpeg"

+ 5
- 1
www/css/autodoc.css View File

.autodoc_upload_zone_hover { .autodoc_upload_zone_hover {
background-color: #8C959D; background-color: #8C959D;
border-color: #333; border-color: #333;
}
}

.autodoc_img {
height: 343px;
}

+ 2
- 2
www/index.html View File

<div class="col autodoc_template_home_col text-center"> <div class="col autodoc_template_home_col text-center">
<table class="table table-borderless table-sm small"> <table class="table table-borderless table-sm small">
<tr> <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="" /> <img class="autodoc_template_home_img img-thumbnail rounded" src="" />
</td> </td>
</tr> </tr>
<script src="js/autodoc.js"></script> <script src="js/autodoc.js"></script>
</body> </body>


</html>
</html>

Loading…
Cancel
Save