Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Cache client IPs on file view so views can't be spammed
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReverend403 committed Jul 5, 2016
1 parent 8fef277 commit c4b07d1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/Http/Controllers/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Helpers;
use App\Models\Upload;
use App\Http\Requests;
use Cache;
use DB;
use Illuminate\Http\Request;
use Log;
Expand All @@ -22,7 +23,11 @@ public function get(Request $request, Upload $upload)
}

if (!$request->user() || $request->user()->id !== $upload->user_id) {
DB::table('uploads')->where('id', $upload->id)->increment('views');
$cacheKey = 'cached_view:' . $request->getClientIp();
if (!Cache::has($cacheKey)) {
Cache::put($cacheKey, 1, 60);
DB::table('uploads')->where('id', $upload->id)->increment('views');
}
}

return Helpers::sendFile($upload);
Expand Down

0 comments on commit c4b07d1

Please sign in to comment.