コード例 #1
0
 public function get(Request $request, Upload $upload)
 {
     if (Storage::exists($upload->getPath())) {
         if ($upload->user->banned) {
             Log::info('Refusing to serve file for banned user.', ['user' => $upload->user->name, 'file' => $upload->name]);
             return abort(StatusCode::NOT_FOUND);
         }
         if (!$request->user() || $request->user()->id !== $upload->user_id) {
             $cacheKey = sprintf('cached_view:%s:%s', $request->ip(), $upload->name);
             if (!Cache::has($cacheKey)) {
                 Cache::put($cacheKey, 1, 60);
                 DB::table('uploads')->where('id', $upload->id)->increment('views');
             }
         }
         return Helpers::sendFile($upload);
     }
     return abort(StatusCode::NOT_FOUND);
 }