summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjules <jules@okfoc.us>2014-01-14 08:33:37 -0500
committerjules <jules@okfoc.us>2014-01-14 08:33:37 -0500
commit0a57883969405be46126746777f81b1bf2d270e0 (patch)
treee641eeea6ee1d7844b2fa07311d4b0f8e2399147
parent5242f387995b6251ff1bf7902b3ac6428f381fb0 (diff)
parent2263ec93f393c0eaae4df31f0ef3ff2eb99f73e2 (diff)
Merge branch 'pepper' of lmno:dither into pepper
-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",