-
Notifications
You must be signed in to change notification settings - Fork 407
Add API endpoint for uploading screenshots on lazer #12618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
642fcf6 to
c52a595
Compare
| $screenshot = new Screenshot(); | ||
| $screenshot->user_id = auth()->user()->getKey(); | ||
| $screenshot->save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be done in one step with ::create. And use \Auth::user() instead of auth()->user()
| $screenshot->user_id = auth()->user()->getKey(); | ||
| $screenshot->save(); | ||
|
|
||
| $this->storage()->putFileAs('/', $validated['screenshot'], "{$screenshot->getKey()}.jpg"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be done in the model
| return response()->json([ | ||
| 'url' => route('screenshots.show', [ | ||
| 'screenshot' => $screenshot->getKey(), | ||
| 'hash' => substr(md5($screenshot->getKey().config('osu.screenshots.shared_secret')), 0, 4), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be done in the model. And use $GLOBALS['cfg'][...] instead of config(...)
|
|
||
| public function definition(): array | ||
| { | ||
| return []; // nothing in this model to fake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user_id field?
| 'screenshot' => $screenshot->getKey(), | ||
| 'hash' => substr(md5($screenshot->getKey().config('osu.screenshots.shared_secret')), 0, 4), | ||
| ]), | ||
| ], 201); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
201 requires returning location: header when it's not the same url as the post request.
Or just return 200.
|
|
||
| // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. | ||
| // See the LICENCE file in the repository root for full licence text. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use declare strict (also for all other files)
| $validated = $request->validate([ | ||
| 'screenshot' => [ | ||
| 'required', | ||
| File::types(['jpeg']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a size limit of maybe 10MB (or App\Libraries\Uploader::DEFAULT_MAX_FILESIZE)
config/filesystems.php
Outdated
| 'visibility' => 'public', | ||
| ], | ||
|
|
||
| 'local-screenshot' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before solo-replay (also for the other one)
|
|
||
| 's3-screenshot' => [ | ||
| ...$s3Default, | ||
| 'bucket' => presence(env('S3_SCREENSHOT_BUCKET')) ?? 'screenshots', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add to .env.example (also for the other one)
| use Illuminate\Contracts\Filesystem\Filesystem; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Validation\Rules\File; | ||
| use Storage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use directly with \Storage instead of adding more lines
Web side PR for ppy/osu#10718.
This implementation matches the behaviour of the respective endpoint in legacy web, since the screenshot retrieval endpoint is currently being handled by that. Ability to retrieve said screenshots using osu-web will come in a separate PR.
Steps to deploy:
S3_SCREENSHOT_BUCKETenv varSCREENSHOTS_SHARED_SECRETenv var