the browser-facing portion of osu!
at master 1.6 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Http\Controllers; 7 8use App\Exceptions\InvariantException; 9use App\Http\Controllers\Controller as BaseController; 10use App\Libraries\ClientCheck; 11use App\Models\Beatmap; 12use App\Models\ScoreToken; 13use App\Transformers\ScoreTokenTransformer; 14use PDOException; 15 16class ScoreTokensController extends BaseController 17{ 18 public function __construct() 19 { 20 $this->middleware('auth'); 21 } 22 23 public function store($beatmapId) 24 { 25 if (!$GLOBALS['cfg']['osu']['scores']['submission_enabled']) { 26 abort(422, 'score submission is disabled'); 27 } 28 29 $beatmap = Beatmap::increasesStatistics()->findOrFail($beatmapId); 30 $user = auth()->user(); 31 $request = \Request::instance(); 32 33 $scoreToken = new ScoreToken([ 34 'beatmap_id' => $beatmap->getKey(), 35 'build_id' => ClientCheck::parseToken($request)['buildId'], 36 'user_id' => $user->getKey(), 37 ...get_params($request->all(), null, [ 38 'beatmap_hash', 39 'ruleset_id:int', 40 ]), 41 ]); 42 $scoreToken->setRelation('beatmap', $beatmap); 43 44 try { 45 $scoreToken->saveOrExplode(); 46 } catch (PDOException $e) { 47 // TODO: move this to be a validation inside Score model 48 throw new InvariantException('failed creating score token'); 49 } 50 51 return json_item($scoreToken, new ScoreTokenTransformer()); 52 } 53}