Speed legacy photo serving and skip tracking on download routes.
Tighten thumbnail/legacy photo handling and exclude download/photo traffic from session visitor tracking so those hot paths stay cheap.
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Artwork;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
final class LegacyArtworkPhotoController extends Controller
|
||||
@@ -26,25 +27,39 @@ final class LegacyArtworkPhotoController extends Controller
|
||||
|
||||
private static ?bool $hasLegacyIdColumn = null;
|
||||
|
||||
public function __invoke(string $encoded, string $size, string $extension): RedirectResponse
|
||||
public function __invoke(string $encoded, string $size, string $extension): RedirectResponse|Response
|
||||
{
|
||||
$artworkId = $this->decodeBase62($encoded);
|
||||
$sizeCode = (int) $size;
|
||||
|
||||
abort_if($artworkId === null || $artworkId < 1, 404);
|
||||
if ($artworkId === null || $artworkId < 1) {
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
$artwork = $this->resolveArtwork($artworkId);
|
||||
abort_unless($artwork !== null, 404);
|
||||
if ($artwork === null) {
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
$targetUrl = $sizeCode === 7
|
||||
? $this->resolveOriginalUrl($artwork)
|
||||
: $artwork->thumbUrl(self::THUMB_SIZE_MAP[$sizeCode] ?? 'md');
|
||||
|
||||
abort_if(empty($targetUrl), 404);
|
||||
if ($targetUrl === null || $targetUrl === '') {
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
return redirect()->away($targetUrl, 301);
|
||||
}
|
||||
|
||||
private function notFound(): Response
|
||||
{
|
||||
return response('', 404, [
|
||||
'Content-Type' => 'text/plain; charset=UTF-8',
|
||||
'Cache-Control' => 'no-store',
|
||||
]);
|
||||
}
|
||||
|
||||
private function decodeBase62(string $value): ?int
|
||||
{
|
||||
if ($value === '') {
|
||||
@@ -86,11 +101,6 @@ final class LegacyArtworkPhotoController extends Controller
|
||||
{
|
||||
$cdn = rtrim((string) config('cdn.files_url', 'https://cdn.skinbase.org'), '/');
|
||||
$filePath = trim((string) ($artwork->file_path ?? ''), '/');
|
||||
|
||||
if ($filePath !== '') {
|
||||
return $cdn . '/' . $filePath;
|
||||
}
|
||||
|
||||
$hash = strtolower((string) preg_replace('/[^a-f0-9]/i', '', (string) ($artwork->hash ?? '')));
|
||||
$ext = ltrim((string) ($artwork->file_ext ?: $artwork->thumb_ext ?: 'webp'), '.');
|
||||
|
||||
@@ -98,6 +108,10 @@ final class LegacyArtworkPhotoController extends Controller
|
||||
return $artwork->thumbUrl('xl') ?? $artwork->thumbUrl('lg') ?? $artwork->thumbUrl('md');
|
||||
}
|
||||
|
||||
if ($filePath !== '') {
|
||||
return $cdn . '/' . $filePath;
|
||||
}
|
||||
|
||||
$prefix = trim((string) config('uploads.object_storage.prefix', 'artworks'), '/');
|
||||
$firstDir = substr($hash, 0, 2);
|
||||
$secondDir = substr($hash, 2, 2);
|
||||
|
||||
Reference in New Issue
Block a user