diff --git a/app/Http/Controllers/Api/ArtworkDownloadController.php b/app/Http/Controllers/Api/ArtworkDownloadController.php
index 5748a09a..08d247cc 100644
--- a/app/Http/Controllers/Api/ArtworkDownloadController.php
+++ b/app/Http/Controllers/Api/ArtworkDownloadController.php
@@ -11,6 +11,7 @@ use App\Services\ThumbnailPresenter;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Str;
/**
* POST /api/art/{id}/download
@@ -48,12 +49,26 @@ final class ArtworkDownloadController extends Controller
$this->recordDownload($request, $artwork);
// Increment counters — deferred via Redis when available.
- $this->stats->incrementDownloads((int) $artwork->id, 1, defer: true);
+ try {
+ $this->stats->incrementDownloads((int) $artwork->id, 1, defer: true);
+ } catch (\Throwable) {
+ // Stats failure must never interrupt the download.
+ }
// Resolve the highest-resolution download URL available.
$url = $this->resolveDownloadUrl($artwork);
- return response()->json(['ok' => true, 'url' => $url]);
+ // Build a user-friendly download filename: "title-slug.file_ext"
+ $ext = $artwork->file_ext ?: $artwork->thumb_ext ?: 'webp';
+ $slug = Str::slug((string) ($artwork->slug ?: $artwork->title)) ?: (string) $artwork->id;
+ $filename = $slug . '.' . $ext;
+
+ return response()->json([
+ 'ok' => true,
+ 'url' => $url,
+ 'filename' => $filename,
+ 'size' => (int) ($artwork->file_size ?? 0),
+ ]);
}
/**
@@ -80,17 +95,34 @@ final class ArtworkDownloadController extends Controller
}
/**
- * Resolve the best available download URL: XL → LG → MD.
- * Returns an empty string if no thumbnail can be resolved.
+ * Resolve the original full-resolution CDN URL.
+ *
+ * Originals are stored at: {cdn}/original/{h1}/{h2}/{hash}.{file_ext}
+ * h1 = first 2 chars of hash, h2 = next 2 chars, filename = full hash + file_ext.
+ * Falls back to XL → LG → MD thumbnail when hash is unavailable.
*/
private function resolveDownloadUrl(Artwork $artwork): string
{
+ $hash = $artwork->hash ?? null;
+ $ext = ltrim((string) ($artwork->file_ext ?: $artwork->thumb_ext ?: 'webp'), '.');
+
+ if (!empty($hash)) {
+ $h = strtolower(preg_replace('/[^a-f0-9]/', '', $hash));
+ $h1 = substr($h, 0, 2);
+ $h2 = substr($h, 2, 2);
+ $cdn = rtrim((string) config('cdn.files_url', 'https://files.skinbase.org'), '/');
+
+ return sprintf('%s/original/%s/%s/%s.%s', $cdn, $h1, $h2, $h, $ext);
+ }
+
+ // Fallback: best available thumbnail size
foreach (['xl', 'lg', 'md'] as $size) {
$thumb = ThumbnailPresenter::present($artwork, $size);
- if (! empty($thumb['url'])) {
+ if (!empty($thumb['url'])) {
return (string) $thumb['url'];
}
}
+
return '';
}
}
diff --git a/resources/js/Pages/ArtworkPage.jsx b/resources/js/Pages/ArtworkPage.jsx
index e6a80ad0..71f23760 100644
--- a/resources/js/Pages/ArtworkPage.jsx
+++ b/resources/js/Pages/ArtworkPage.jsx
@@ -67,17 +67,15 @@ function ArtworkPage({ artwork: initialArtwork, related: initialRelated, present
onNext={navState.navigateNext}
/>
-
+
-
@@ -91,11 +89,10 @@ function ArtworkPage({ artwork: initialArtwork, related: initialRelated, present