Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/php_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
test-suite:
- Unit
- Feature_v2
- Feature_v3
- Install
- Webshop
- ImageProcessing
Expand All @@ -40,6 +41,8 @@ jobs:
test-suite: Unit
- php-version: 8.4
test-suite: Feature_v2
- php-version: 8.4
test-suite: Feature_v3
- php-version: 8.4
test-suite: Webshop
- php-version: 8.4
Expand Down
1 change: 1 addition & 0 deletions app/Contracts/Http/Requests/RequestAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RequestAttribute

public const PHOTO_ID_ATTRIBUTE = 'photo_id';
public const PHOTO_IDS_ATTRIBUTE = 'photo_ids';
public const SIZE_VARIANT_TOKEN_ATTRIBUTE = 'size_variant';
public const HEADER_ID_ATTRIBUTE = 'header_id';

public const TITLE_ATTRIBUTE = 'title';
Expand Down
37 changes: 37 additions & 0 deletions app/Enum/SizeVariantAssetType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Enum;

/**
* Enum SizeVariantAssetType.
*/
enum SizeVariantAssetType: string
{
case SMALL2X = 'small2x';
case SMALL = 'small';
case THUMB2X = 'thumb2x';
case THUMB = 'thumb';
case PLACEHOLDER = 'placeholder';

/**
* Given a SizeVariantAssetType return the associated SizeVariantType.
*
* @return SizeVariantType
*/
public function toSizeVariantType(): SizeVariantType
{
return match ($this) {
self::SMALL2X => SizeVariantType::SMALL2X,
self::SMALL => SizeVariantType::SMALL,
self::THUMB2X => SizeVariantType::THUMB2X,
self::THUMB => SizeVariantType::THUMB,
self::PLACEHOLDER => SizeVariantType::PLACEHOLDER,
};
}
}
42 changes: 42 additions & 0 deletions app/Http/Controllers/Gallery/PhotoAssetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Controllers\Gallery;

use App\Http\Requests\Photo\GetPhotoAssetRequest;
use App\Image\Files\FlysystemFile;
use App\Image\Watermarker;
use App\Repositories\ConfigManager;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;

/**
* Serves a single photo size-variant asset (Feature 056, API-056-01).
*/
class PhotoAssetController extends Controller
{
public function show(GetPhotoAssetRequest $request, Watermarker $watermarker)
{
$size_variant = $request->sizeVariant();
$path = $watermarker->get_path($size_variant);
$disk = Storage::disk($size_variant->storage_disk->value);

/** @disregard P1013 */
if ($disk->getAdapter() instanceof AwsS3V3Adapter) {
$life_in_seconds = resolve(ConfigManager::class)->getValueAsInt('temporary_image_link_life_in_seconds');

/** @disregard P1013 */
return redirect()->away($disk->temporaryUrl($path, now()->addSeconds($life_in_seconds)));
}

$file = new FlysystemFile($disk, $path);

return response()->file($file->toLocalFile()->getPath());
}
}
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Kernel extends HttpKernel
'migration' => \App\Http\Middleware\MigrationStatus::class,
'content_type' => \App\Http\Middleware\ContentType::class,
'accept_content_type' => \App\Http\Middleware\AcceptContentType::class,
'json_errors' => \App\Http\Middleware\EnsureJsonErrorResponses::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'login_required' => \App\Http\Middleware\LoginRequired::class,
'cache_control' => \App\Http\Middleware\CacheControl::class,
Expand Down
33 changes: 33 additions & 0 deletions app/Http/Middleware/EnsureJsonErrorResponses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Middleware;

use Illuminate\Http\Request;

/**
* Forces the request to report `application/json` as an acceptable content
* type, so that any exception thrown further down the pipeline (validation,
* authorization, model-not-found, etc.) is rendered as Lychee's standard
* JSON error body, regardless of what the actual client sent as its `Accept`
* header.
*
* Needed for endpoints (e.g. Feature 056's binary asset passthrough) which
* intentionally opt out of the `accept_content_type:json` gate because a
* *successful* response is not JSON, but whose *error* responses still must
* be (FR-056-02).
*/
class EnsureJsonErrorResponses
{
public function handle(Request $request, \Closure $next): mixed
{
$request->headers->set('Accept', 'application/json');

return $next($request);
}
}
Loading
Loading