mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 00:01:04 +03:30
fix media
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Media;
|
||||
|
||||
use Spatie\MediaLibrary\Models\Media;
|
||||
use Spatie\MediaLibrary\PathGenerator\PathGenerator as BasePathGenerator;
|
||||
|
||||
class PathGenerator implements BasePathGenerator
|
||||
{
|
||||
|
||||
/*
|
||||
* Get the path for the given media, relative to the root storage path.
|
||||
*/
|
||||
public function getPath(Media $media): string
|
||||
{
|
||||
return md5($media->id).'/';
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the path for conversions of the given media, relative to the root storage path.
|
||||
*/
|
||||
public function getPathForConversions(Media $media): string
|
||||
{
|
||||
return $this->getPath($media).'conversions/';
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the path for responsive images of the given media, relative to the root storage path.
|
||||
*/
|
||||
public function getPathForResponsiveImages(Media $media): string
|
||||
{
|
||||
return $this->getPath($media).'responsive-images/';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services\Media\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MediaResource extends JsonResource
|
||||
@@ -9,7 +10,7 @@ class MediaResource extends JsonResource
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Media\UrlGenerator;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator;
|
||||
use Spatie\MediaLibrary\Exceptions\UrlCannotBeDetermined;
|
||||
|
||||
class FtpUrlGenerator extends BaseUrlGenerator
|
||||
{
|
||||
/**
|
||||
* Get the url for the profile of a media item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl() : string
|
||||
{
|
||||
return config('media-library.wm-cdn').'/'.$this->getPathRelativeToRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface $expiration
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws UrlCannotBeDetermined
|
||||
*/
|
||||
public function getTemporaryUrl(DateTimeInterface $expiration, array $options = []): string
|
||||
{
|
||||
throw UrlCannotBeDetermined::filesystemDoesNotSupportTemporaryUrls();
|
||||
return 'done';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relative path for the profile of a media item.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->getPathRelativeToRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url to the directory containing responsive images.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponsiveImagesDirectoryUrl(): string
|
||||
{
|
||||
return config('media-library.wm-cdn').'/'.$this->pathGenerator->getPathForResponsiveImages($this->media);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Media\UrlGenerator;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator;
|
||||
|
||||
|
||||
class S3UrlGenerator extends BaseUrlGenerator
|
||||
{
|
||||
/**
|
||||
* Get the url for the profile of a media item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl() : string
|
||||
{
|
||||
return config('media-library.s3.domain').'/'.$this->getPathRelativeToRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface $expiration
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function getTemporaryUrl(DateTimeInterface $expiration, array $options = []): string
|
||||
{
|
||||
|
||||
return 'done';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relative path for the profile of a media item.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->getPathRelativeToRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url to the directory containing responsive images.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponsiveImagesDirectoryUrl(): string
|
||||
{
|
||||
return config('media-library.s3.domain').'/'.$this->pathGenerator->getPathForResponsiveImages($this->media);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user