Browse Source

store uploaded file and create page database entry

master
root 5 years ago
parent
commit
df9479442c
1 changed files with 34 additions and 13 deletions
  1. 34
    13
      cgi/autodoc.fcgi

+ 34
- 13
cgi/autodoc.fcgi View File

my $method = $ENV{REQUEST_METHOD}; my $method = $ENV{REQUEST_METHOD};


# QS sanity check # QS sanity check
if ( exists $qs->{id} && $qs->{id} !~ /^\d+$/ ) { fatal_api_error(400,"invalid id"); }
if ( exists $qs->{maxWidth} && $qs->{maxWidth} !~ /^\d+$/ ) { fatal_api_error(400,"invalid maxWidth"); }
if ( exists $qs->{maxHeight} && $qs->{maxHeight} !~ /^\d+$/ ) { fatal_api_error(400,"invalid maxHeight"); }
if ( exists $qs->{pageSize} && $qs->{pageSize} !~ /^\d+$/ ) { fatal_api_error(400,"invalid pageSize"); }
if ( exists $qs->{pageIndex} && $qs->{pageIndex} !~ /^\d+$/ ) { fatal_api_error(400,"invalid pageIndex"); }
if ( exists $qs->{id} && $qs->{id} !~ /^\d+$/ ) {
fatal_api_error(400,"invalid id");
}
if ( exists $qs->{maxWidth} && $qs->{maxWidth} !~ /^\d+$/ ) {
fatal_api_error(400,"invalid maxWidth");
}
if ( exists $qs->{maxHeight} && $qs->{maxHeight} !~ /^\d+$/ ) {
fatal_api_error(400,"invalid maxHeight");
}
if ( exists $qs->{pageSize} && $qs->{pageSize} !~ /^\d+$/ ) {
fatal_api_error(400,"invalid pageSize");
}
if ( exists $qs->{pageIndex} && $qs->{pageIndex} !~ /^\d+$/ ) {
fatal_api_error(400,"invalid pageIndex");
}


my $path = [ split(/\//,$ENV{SCRIPT_NAME}) ] if exists $ENV{SCRIPT_NAME}; my $path = [ split(/\//,$ENV{SCRIPT_NAME}) ] if exists $ENV{SCRIPT_NAME};
shift(@{$path}); shift(@{$path});
sub api_v1_POST_documents_id_data { sub api_v1_POST_documents_id_data {
my($id, $qs, $post, $user) = @_; my($id, $qs, $post, $user) = @_;


open(TMP,">/tmp/upload.meta");
print TMP $post->{ctype} . "\n";
print TMP $post->{len} . "\n";
print TMP Dumper(\%ENV);
close(TMP);
my $pageid;


open(TMP,">/tmp/upload.data");
print TMP $post->{data} . "\n";
close(TMP);
sqlquery($dbh, "
INSERT INTO
pages
SET
owner = ?,
documentId = ?,
contenttype = ?,
created = NOW(),
status = 'inprogress'",
$user, $id, $post->{ctype});
my $q = sqlquery($dbh, "SELECT LAST_INSERT_ID()");
while(my($last) = $q->fetchrow_array()) {
$pageid = $last;
}


my $file = $conf->{path}{global} . '/' . $conf->{path}{originals} . '/' . $pageid;
open(F,'>'.$file);
print F $post->{body};
close(F);


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

Loading…
Cancel
Save