Skip to content

Conversation

@LiquidPL
Copy link
Contributor

@LiquidPL LiquidPL commented Dec 24, 2025

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:

  • Configure the screenshot s3 bucket in the S3_SCREENSHOT_BUCKET env var
  • Set the screenshot secret in the SCREENSHOTS_SHARED_SECRET env var

Comment on lines 27 to 29
$screenshot = new Screenshot();
$screenshot->user_id = auth()->user()->getKey();
$screenshot->save();
Copy link
Collaborator

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");
Copy link
Collaborator

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),
Copy link
Collaborator

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
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Copy link
Collaborator

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']),
Copy link
Collaborator

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)

'visibility' => 'public',
],

'local-screenshot' => [
Copy link
Collaborator

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',
Copy link
Collaborator

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;
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants