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

@@ -33,11 +33,21 @@ while($request->Accept() >= 0) {
my $method = $ENV{REQUEST_METHOD};

# 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};
shift(@{$path});
@@ -275,16 +285,27 @@ sub api_v1_POST_documents {
sub api_v1_POST_documents_id_data {
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", { })
}

Loading…
Cancel
Save