示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $user = auth()->check() ? auth()->user() : null;
     if (is_null($user)) {
         return redirect('/')->with('error', 'You need to be logged in');
     }
     if (!$user->can('break_upload_limit') && $user->videos()->newlyups()->count() >= 20) {
         return redirect()->back()->with('error', 'Uploadlimit reached')->withInput();
     }
     if (!$request->hasFile('file')) {
         return redirect()->back()->with('error', 'No file')->withInput();
     }
     $file = $request->file('file');
     if (!$file->isValid() || $file->getClientOriginalExtension() != 'webm' || $file->getMimeType() != 'video/webm') {
         return redirect()->back()->with('error', 'Invalid file');
     }
     if (!$user->can('break_max_filesize') && $file->getSize() > 30000000.0) {
         return redirect()->back()->with('error', 'File to big. Max 30MB')->withInput();
     }
     if (($v = Video::withTrashed()->where('hash', '=', sha1_file($file->getRealPath()))->first()) !== null) {
         return redirect($v->id)->with('error', 'Video already exists');
     }
     $file = $file->move(public_path() . '/b/', time() . '.webm');
     $hash = sha1_file($file->getRealPath());
     $video = new Video();
     $video->file = basename($file->getRealPath());
     $video->interpret = $request->get('interpret', null);
     $video->songtitle = $request->get('songtitle', null);
     $video->imgsource = $request->get('imgsource', null);
     $video->user()->associate($user);
     $video->category()->associate(Category::findOrFail($request->get('category')));
     $video->hash = $hash;
     $video->save();
     return redirect($video->id)->with('success', 'Upload successful');
 }
示例#2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     if (!$request->hasFile('file') || !$request->has('category') || !$request->has('tags')) {
         return new JsonResponse(['error' => 'invalid_request']);
     }
     $tags = $request->get('tags');
     if (mb_strpos($tags, 'sfw') === false && mb_strpos($tags, 'nsfw') === false) {
         return new JsonResponse(['error' => 'invalid_request']);
     }
     $user = auth()->check() ? auth()->user() : null;
     if (is_null($user)) {
         return new JsonResponse(['error' => 'not_logged_in']);
     }
     if (!$user->can('break_upload_limit') && $user->videos()->newlyups()->count() >= 10) {
         return new JsonResponse(['error' => 'uploadlimit_reached']);
     }
     $file = $request->file('file');
     if (!$file->isValid() || mb_strtolower($file->getClientOriginalExtension()) !== 'webm' || mb_strtolower($file->getMimeType()) !== 'video/webm') {
         return new JsonResponse(['error' => 'invalid_file']);
     }
     if (!$user->can('break_max_filesize') && $file->getSize() > 31457280) {
         return new JsonResponse(['error' => 'file_too_big']);
     }
     if (($v = Video::withTrashed()->where('hash', '=', sha1_file($file->getRealPath()))->first()) !== null) {
         if ($v->trashed()) {
             return new JsonResponse(['error' => 'already_exists']);
         }
         return new JsonResponse(['error' => 'already_exists', 'video_id' => $v->id]);
     }
     $file = $file->move(public_path() . '/b/', time() . '.webm');
     if (!$this->checkFileEncoding(basename($file->getRealPath()))) {
         unlink($file->getRealPath());
         return new JsonResponse(['error' => 'erroneous_file_encoding']);
     }
     $hash = sha1_file($file->getRealPath());
     $video = new Video();
     $video->file = basename($file->getRealPath());
     $video->interpret = $request->get('interpret', null);
     $video->songtitle = $request->get('songtitle', null);
     $video->imgsource = $request->get('imgsource', null);
     $video->user()->associate($user);
     $video->category()->associate(Category::findOrFail($request->get('category')));
     $video->hash = $hash;
     $video->save();
     $video->tag($tags);
     $video->tag($video->interpret);
     $video->tag($video->songtitle);
     $video->tag($video->imgsource);
     $video->tag($video->category->shortname);
     $video->tag($video->category->name);
     $this->createThumbnail(basename($file->getRealPath()));
     return new JsonResponse(['error' => 'null', 'video_id' => $video->id]);
 }
示例#3
0
文件: AddTags.php 项目: sirx/w0bm.com
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Videos
     echo 'UPDATING VIDEOS', PHP_EOL, '===============', PHP_EOL;
     $count = 0;
     Video::withTrashed()->with('category')->chunk(200, function ($videos) use($count) {
         foreach ($videos as $v) {
             echo 'Updating Video with ID: ', $v->id, PHP_EOL;
             $v->detag();
             // quick and dirty. not 100% correct though.
             if ($v->category->shortname === 'pr0n') {
                 $v->tag('nsfw');
             } else {
                 $v->tag('sfw');
             }
             $v->tag(array_filter([$v->category->shortname, $v->category->name, $v->interpret, $v->songtitle, $v->imgsource], function ($elem) {
                 return !empty(trim($elem));
             }));
             $count++;
         }
     });
     echo PHP_EOL, PHP_EOL, 'Updated ', $count, ' Videos.', PHP_EOL, PHP_EOL, PHP_EOL;
     // User filters
     echo 'UPDATING USERS', PHP_EOL, '==============', PHP_EOL;
     $count = 0;
     $categories = Category::withTrashed()->get()->keyBy('id');
     User::withTrashed()->chunk(200, function ($users) use(&$count, $categories) {
         foreach ($users as $u) {
             echo 'Updating User: '******'Updated ', $count, ' Users.', PHP_EOL, PHP_EOL, PHP_EOL;
 }