This commit is contained in:
Čarodej
2021-11-03 17:34:46 +01:00
parent 98823504ba
commit cdaad931bb
40 changed files with 69 additions and 112 deletions
@@ -2,7 +2,6 @@
namespace Domain\Files\Actions;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\ImageManagerStatic as Image;
class CreateImageThumbnailAction
@@ -23,20 +22,16 @@ class CreateImageThumbnailAction
$file,
string $user_id
): void {
// Create thumbnail from image
if (in_array($file->getClientMimeType(), $this->availableFormats)) {
// Create intervention image
$intervention = Image::make($file)->orientate();
// Generate avatar sizes
collect(config('vuefilemanager.image_sizes'))
->each(function ($size) use ($intervention, $file_name, $user_id) {
// Create thumbnail only if image is larger than predefined image sizes
if ($intervention->getWidth() > $size['size']) {
// Generate thumbnail
$intervention->resize($size['size'], null, fn ($constraint) => $constraint->aspectRatio())->stream();
@@ -19,7 +19,6 @@ class DownloadThumbnailAction
// Check if file exist
if (! Storage::exists($path)) {
// Get original file path
$substituteFilePath = "/files/$file->user_id/$file->basename";
@@ -1,6 +1,7 @@
<?php
namespace Domain\Files\Actions;
use Illuminate\Support\Str;
use Domain\Sharing\Models\Share;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
@@ -9,7 +10,6 @@ use Domain\Files\Requests\UploadRequest;
use Domain\Files\Models\File as UserFile;
use Domain\Traffic\Actions\RecordUploadAction;
use App\Users\Actions\CheckStorageCapacityAction;
use Illuminate\Support\Str;
class UploadFileAction
{
@@ -13,12 +13,12 @@ class GetFileController extends Controller
public function __construct(
private RecordDownloadAction $recordDownload,
private DownloadFileAction $downloadFile,
) {}
) {
}
public function __invoke(
string $filename,
): BinaryFileResponse {
$file = UserFile::withTrashed()
->where('basename', $filename)
->firstOrFail();
@@ -13,13 +13,13 @@ class GetThumbnailController extends Controller
{
public function __construct(
private DownloadThumbnailAction $downloadThumbnail,
) {}
) {
}
public function __invoke(
Request $request,
string $filename,
): FileNotFoundException | StreamedResponse {
$originalFileName = substr($filename, 3);
$file = File::withTrashed()
@@ -1,12 +1,11 @@
<?php
namespace Domain\Files\Controllers;
use Domain\Files\Models\File;
use Gate;
use Domain\Files\Models\File;
use Illuminate\Http\Response;
use Domain\Sharing\Models\Share;
use Domain\Files\Resources\FileResource;
use Domain\Sharing\Actions\ProtectShareRecordAction;
/**
* Get shared file record
@@ -16,7 +15,6 @@ class VisitorShowFileController
public function __invoke(
Share $shared
): Response {
$file = File::whereUserId($shared->user_id)
->whereId($shared->item_id)
->firstOrFail();
-4
View File
@@ -94,9 +94,7 @@ class File extends Model
// Generate thumbnail link for external storage service
if ($this->type === 'image' && ! is_storage_driver(['local'])) {
foreach (config('vuefilemanager.image_sizes') as $item) {
$filePath = "files/{$this->user_id}/{$item['name']}-{$this->basename}";
$links[$item['name']] = Storage::temporaryUrl($filePath, now()->addHour());
@@ -107,9 +105,7 @@ class File extends Model
// Generate thumbnail link for local storage
if ($this->type === 'image') {
foreach (config('vuefilemanager.image_sizes') as $item) {
$route = route('thumbnail', ['name' => $item['name'] . '-' . $this->basename]);
if ($this->public_access) {
+3 -4
View File
@@ -1,5 +1,4 @@
<?php
namespace Domain\Files\Resources;
use Carbon\Carbon;
@@ -45,10 +44,10 @@ class FileResource extends JsonResource
),*/
],
'relationships' => [
$this->mergeWhen($this->shared, fn() => [
$this->mergeWhen($this->shared, fn () => [
'shared' => new ShareResource($this->shared),
]),
$this->mergeWhen($this->parent, fn() => [
$this->mergeWhen($this->parent, fn () => [
'parent' => [
'data' => [
'type' => 'folder',
@@ -59,7 +58,7 @@ class FileResource extends JsonResource
],
],
]),
$this->mergeWhen($this->owner, fn() => [
$this->mergeWhen($this->owner, fn () => [
'user' => [
'data' => [
'type' => 'user',