-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added media library
- Loading branch information
Showing
27 changed files
with
1,074 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Storage; | ||
use App\Models\GalleryAlbum; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProcessUploadedImage implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
protected $file; | ||
protected $album; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(GalleryAlbum $album, $file) | ||
{ | ||
$this->album = $album; | ||
$this->file = $file; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
if (in_array(Storage::disk('gallery-ingest')->mimeType($this->file), ['image/jpeg','image/png'])) { | ||
$this->album->addMediaFromDisk($this->file, 'gallery-ingest')->toMediaCollection('images'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Storage; | ||
use App\Models\GalleryAlbum; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProcessUploadedImages implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
protected $album; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(GalleryAlbum $album) | ||
{ | ||
$this->album = $album; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$files = Storage::disk('gallery-ingest')->allFiles(); | ||
foreach($files as $file) { | ||
if (in_array(Storage::disk('gallery-ingest')->mimeType($file), ['image/jpeg','image/png'])) { | ||
ProcessUploadedImage::dispatch($this->album, $file); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Libraries\PathGenerators; | ||
|
||
use Spatie\MediaLibrary\Support\PathGenerator\PathGenerator; | ||
use Spatie\MediaLibrary\MediaCollections\Models\Media; | ||
|
||
class GalleryPathGenerator implements PathGenerator | ||
{ | ||
/* | ||
* Get the path for the given media, relative to the root storage path. | ||
*/ | ||
public function getPath(Media $media): string | ||
{ | ||
return $this->getBasePath($media).'/'; | ||
} | ||
|
||
/* | ||
* Get the path for conversions of the given media, relative to the root storage path. | ||
*/ | ||
public function getPathForConversions(Media $media): string | ||
{ | ||
return $this->getBasePath($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->getBasePath($media).'/responsive/'; | ||
} | ||
|
||
/* | ||
* Get a unique base path for the given media. | ||
*/ | ||
protected function getBasePath(Media $media): string | ||
{ | ||
return "images/galleries/" . $media->model_id . "/" . $media->getKey(); | ||
} | ||
} |
Oops, something went wrong.