Permalink
Browse files

Support one-time download

  • Loading branch information...
keedi committed Jul 4, 2011
1 parent aba66e8 commit 37fece2a1cab51af9c173200fb351c52f1e0e64c
View
@@ -1,6 +1,7 @@
CREATE TABLE upload (
- id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- md5 TEXT NOT NULL,
- fname TEXT NOT NULL,
- download INTEGER NOT NULL DEFAULT 0
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ md5 TEXT NOT NULL,
+ fname TEXT NOT NULL,
+ download INTEGER NOT NULL DEFAULT 0,
+ max_download INTEGER NOT NULL DEFAULT 0
);
@@ -54,8 +54,9 @@ sub upload :Local {
# save meta data
$c->model('DB::Upload')->create(
{
- md5 => $uuid,
- fname => $upload->basename,
+ md5 => $uuid,
+ fname => $upload->basename,
+ max_download => $c->req->params->{onetime},
}
);
@@ -89,9 +90,16 @@ sub download :Local :Args(1) {
my $upload
= $c->model('DB::Upload')->search({ md5 => $uuid })->single;
+ # check download count is exceeded
+ if ( $upload->max_download
+ && $upload->max_download <= $upload->download )
+ {
+ Catalyst::Exception->throw( message => "download count is exceeded" );
+ $c->detach('default');
+ }
+
# increase download counter
- my $download = $upload->download;
- $upload->download($download++);
+ $upload->download($upload->download + 1);
$upload->update;
my $full_path = catfile(
@@ -45,6 +45,12 @@ __PACKAGE__->table("upload");
default_value: 0
is_nullable: 0
+=head2 max_download
+
+ data_type: 'integer'
+ default_value: 0
+ is_nullable: 0
+
=cut
__PACKAGE__->add_columns(
@@ -56,12 +62,14 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 0 },
"download",
{ data_type => "integer", default_value => 0, is_nullable => 0 },
+ "max_download",
+ { data_type => "integer", default_value => 0, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-07-04 01:09:29
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YVVte8PEo4S1xgfxKz1xLw
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-07-04 22:48:02
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OoAUMaSX7lJH/7isPmfc7w
# You can replace this text with custom code or comments, and it will be preserved on regeneration
@@ -82,6 +82,7 @@ function uploadStart(file) {
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setStatus("Uploading...");
progress.toggleCancel(true, this);
+ this.addPostParam('onetime', $('#onetime').is(":checked") ? 1 : 0);
}
catch (ex) {}
@@ -3,6 +3,7 @@
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
+ <input id="onetime" name="onetime" type="checkbox" value="onetime" />One-time download
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>

0 comments on commit 37fece2

Please sign in to comment.