summaryrefslogtreecommitdiff
path: root/cgi-bin
diff options
context:
space:
mode:
authorpepper <peppersclothescult@gmail.com>2014-01-13 18:15:20 -0800
committerpepper <peppersclothescult@gmail.com>2014-01-13 18:15:20 -0800
commitba490b2880eb10b198927c044133b35e02446bc7 (patch)
treee14abf94e94b876524b8497ebb07599e60ce209d /cgi-bin
parente5b7549dbe43872f1cd0d8395186ad8e495720fb (diff)
fixed bugs in thumbnail_upload and added extra db check
Diffstat (limited to 'cgi-bin')
-rw-r--r--[-rwxr-xr-x]cgi-bin/thumbnail_upload28
1 files changed, 23 insertions, 5 deletions
diff --git a/cgi-bin/thumbnail_upload b/cgi-bin/thumbnail_upload
index 96ba550..8ee9866 100755..100644
--- a/cgi-bin/thumbnail_upload
+++ b/cgi-bin/thumbnail_upload
@@ -25,6 +25,7 @@ my $aws_secret_access_key = "Dzlzh77U6n2BgQmOPldlR/dRDiO16DMUrQAXYhYc";
my $sql_username = "asdfus";
my $sql_dbname = "asdfus";
my $sql_passwd = "gTYgT&M6q";
+our $dbh = DBI->connect("DBI:mysql:$sql_dbname", $sql_username, $sql_passwd);
#redis
my $redis = Redis->new;
@@ -87,13 +88,27 @@ sub make_thumbnail_url{
my $filename = shift;
return sprintf("http://i.asdf.us/shader_thumb/%s", $filename);
}
+sub check_db{
+ my $data_id = shift;
+ my $statement = 'select thumbnail_url from shaders where id = ?';
+ my $sth = $dbh->prepare($statement)
+ or die "Couldn't prepare statement: " . $dbh->errstr;
+ $sth->execute($data_id)
+ or die "Couldn't execute statement: " . $sth->errstr;
+ my $data = $sth->fetchrow_hashref();
+ if ($sth->rows == 0) {
+ error( "No ids matched $data_id.");
+ }
+ $sth->finish;
+ return $data->{thumbnail_url};
+}
+
sub add_to_db{
my $thumbnail_url = shift;
my $shader_id = shift;
- our $dbh = DBI->connect("DBI:mysql:$sql_dbname", $sql_username, $sql_passwd);
- unless($dbh){ return undef && print STDERR "Could not connect to database: $DBI::errstr"};
+ unless($dbh){ return undef && error( "Could not connect to database: $DBI::errstr")};
my $execute = $dbh->do(
- "UPDATE shaders set thumbnail_url = ? WHERE id = ?".
+ "UPDATE shaders set thumbnail_url = ? WHERE id = ?",
undef,
$thumbnail_url,
$shader_id
@@ -142,6 +157,8 @@ sub main{
$maxRequestLimit, $ENV{REMOTE_ADDR}, $time_now);
my $filedata = get_postdata() || get_filedata();
unless($filedata){ error("NO DATA RECIEVED") };
+ unless($IN->param('id')){ error("Shader id not specified") };
+ if (check_db($IN->param('id'))){ error("thumbnail already in database") };
my $filesize = length($filedata);
if ($filesize < 1) {
error( "EMPTY FILE");
@@ -152,8 +169,9 @@ sub main{
unless(upload_to_AmazonS3(sprintf("shader_thumb/%s", make_filename()), $filedata)){
error("UNABLE TO UPLOAD TO AMAZONS3");
};
- unless(add_to_db($IN->param('$id'))){
- print STDERR "problem adding value to db";
+ unless(add_to_db($thumbnail_url, $IN->param('id'))){
+ print "can you see anything here???";
+ error( "problem adding value to db");
}
my $resp = {
success => "true",