Skip to content

A self-hosted media server and file management system

fix: image resource needs user_id and replaced_at for frontend

aminnausin80e1c82d6222
diff --git a/app/Http/Resources/ImageResource.php b/app/Http/Resources/ImageResource.php
index 406aa9c0..62fb82c9 100644
--- a/app/Http/Resources/ImageResource.php
+++ b/app/Http/Resources/ImageResource.php
@@ -2,8 +2,11 @@
namespace App\Http\Resources;
+use App\Enums\ImageSource;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Gate;
class ImageResource extends JsonResource {
/**
@@ -16,8 +19,10 @@ class ImageResource extends JsonResource {
'id' => $this->id,
'path' => asset("/storage/{$this->path}"),
'type' => $this->image_type,
- 'source' => $this->image_source,
- 'blurHash' => $this->blur_hash,
+ 'source' => $this->user_id && $this->image_source === ImageSource::DOWNLOADED ? ImageSource::UPLOADED : $this->image_source,
+ 'blur_hash' => $this->blur_hash,
+ 'user_id' => $this->user_id === Auth::id() || Gate::allows('admin') ? $this->user_id : null,
+ 'replaced_at' => $this->replaced_at,
];
}
}
diff --git a/resources/js/contracts/media.ts b/resources/js/contracts/media.ts
index 44f45270..b1ee5583 100644
--- a/resources/js/contracts/media.ts
+++ b/resources/js/contracts/media.ts
@@ -172,7 +172,9 @@ export interface ImageResource {
path: string;
type: ImageType;
source: ImageSource;
- blurHash?: string;
+ blur_hash?: string;
+ user_id?: number;
+ replaced_at?: string;
}
export type ImageType = 'poster' | 'banner' | 'preview' | 'avatar';