-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into findLabelShortcut
-Resolve merge conflicts by integrating code changes from both branches.
- Loading branch information
Showing
27 changed files
with
936 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Biigle\Jobs; | ||
|
||
use Biigle\Image; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Storage; | ||
|
||
class CloneImageThumbnails extends Job implements ShouldQueue | ||
{ | ||
use InteractsWithQueue, SerializesModels; | ||
|
||
/** | ||
* Path of original image thumbnails and tiled data | ||
* @var string | ||
*/ | ||
public $prefix; | ||
|
||
/** | ||
* Path of cloned image thumbnails and tiled data | ||
* @var string | ||
*/ | ||
public $copyPrefix; | ||
|
||
/** | ||
* Cloned image of cloned volume | ||
* @var Image | ||
*/ | ||
public $image; | ||
|
||
public function __construct(Image $img, String $prefix) | ||
{ | ||
$this->image = $img; | ||
$this->prefix = $prefix; | ||
$this->copyPrefix = fragment_uuid_path($img->uuid); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$diskThumb = Storage::disk(config('thumbnails.storage_disk')); | ||
$diskTiles = Storage::disk(config('image.tiles.disk')); | ||
$hasTiledImages = $this->hasTiledImages($diskTiles); | ||
|
||
if (!$this->hasThumbnail($diskThumb) || $this->shouldBeTiled() && !$hasTiledImages) { | ||
ProcessNewImage::dispatch($this->image); | ||
return; | ||
} | ||
$format = config('thumbnails.format'); | ||
$diskThumb->copy($this->prefix.".{$format}", $this->copyPrefix.".{$format}"); | ||
|
||
if ($hasTiledImages) { | ||
$files = $diskTiles->allFiles($this->prefix); | ||
foreach ($files as $file) { | ||
$fileName = str_replace("{$this->prefix}/", "", $file); | ||
$diskTiles->copy($file, "{$this->copyPrefix}/{$fileName}"); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Determine if original image has thumbnail. | ||
* | ||
* @param $disk containing original image's thumbnail. | ||
* | ||
* @return bool | ||
*/ | ||
private function hasThumbnail($disk) | ||
{ | ||
$format = config('thumbnails.format'); | ||
return $disk->exists("{$this->prefix}.{$format}"); | ||
} | ||
|
||
/** | ||
* Determine if original image has tiled data. | ||
* | ||
* @param $disk containing original image's tiled images. | ||
* | ||
* @return bool | ||
*/ | ||
private function hasTiledImages($disk) | ||
{ | ||
return $disk->exists("{$this->prefix}/ImageProperties.xml"); | ||
} | ||
|
||
/** | ||
* Determine if an image should be tiled. | ||
* | ||
* @return bool | ||
*/ | ||
protected function shouldBeTiled() | ||
{ | ||
if ($this->image->tiled && $this->image->tilingInProgress) { | ||
return false; | ||
} | ||
|
||
$threshold = config('image.tiles.threshold'); | ||
return $this->image->width > $threshold || $this->image->height > $threshold; | ||
} | ||
} |
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,82 @@ | ||
<?php | ||
|
||
namespace Biigle\Jobs; | ||
|
||
use Biigle\Video; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Storage; | ||
|
||
class CloneVideoThumbnails extends Job implements ShouldQueue | ||
{ | ||
use InteractsWithQueue, SerializesModels; | ||
|
||
/** | ||
* Path of original video thumbnails and sprites | ||
* @var string | ||
*/ | ||
public $prefix; | ||
|
||
/** | ||
* Path of cloned video thumbnails and sprites | ||
* @var string | ||
*/ | ||
public $copyPrefix; | ||
|
||
/** | ||
* Cloned video of cloned volume | ||
* @var Video | ||
*/ | ||
public $video; | ||
|
||
public function __construct(Video $video, String $prefix) | ||
{ | ||
$this->video = $video; | ||
$this->prefix = $prefix; | ||
$this->copyPrefix = fragment_uuid_path($video->uuid); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$disk = Storage::disk(config('videos.thumbnail_storage_disk')); | ||
|
||
if (!$this->hasThumbnails($disk) || !$this->hasSprites($disk)) { | ||
ProcessNewVideo::dispatch($this->video); | ||
return; | ||
} | ||
|
||
$files = $disk->allFiles($this->prefix); | ||
foreach ($files as $file) { | ||
$fileName = str_replace("{$this->prefix}/", "", $file); | ||
$disk->copy($file, "{$this->copyPrefix}/{$fileName}"); | ||
} | ||
} | ||
|
||
/** | ||
* Determine if original video has thumbnails. | ||
* | ||
* @param $disk containing original video's thumbnails. | ||
* | ||
* @return bool | ||
*/ | ||
private function hasThumbnails($disk) | ||
{ | ||
$format = config('thumbnails.format'); | ||
return $disk->exists("{$this->prefix}/0.{$format}"); | ||
} | ||
|
||
/** | ||
* Determine if original video has sprites. | ||
* | ||
* @param $disk containing original video's sprites. | ||
* | ||
* @return bool | ||
*/ | ||
private function hasSprites($disk) | ||
{ | ||
$format = config('videos.sprites_format'); | ||
return $disk->exists("{$this->prefix}/sprite_0.{$format}"); | ||
|
||
} | ||
} |
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,87 @@ | ||
<?php | ||
|
||
namespace Biigle\Jobs; | ||
|
||
use Biigle\Image; | ||
use Biigle\Video; | ||
use Biigle\Volume; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProcessCloneVolumeFiles extends Job implements ShouldQueue | ||
{ | ||
use InteractsWithQueue, SerializesModels; | ||
|
||
/** | ||
* The volume for which the files should be processed. | ||
* | ||
* @var Volume | ||
*/ | ||
protected $volume; | ||
|
||
/** | ||
* Array of image/video IDs to restrict processing to. | ||
* If it is empty, all files of the volume will be taken. | ||
* | ||
* @var array | ||
*/ | ||
protected $only; | ||
|
||
/** | ||
* Array maps uuid of copied file to uuid of original files. | ||
* | ||
* @var array | ||
*/ | ||
protected $uuidMap; | ||
|
||
/** | ||
* Ignore this job if the volume does not exist any more. | ||
* | ||
* @var bool | ||
*/ | ||
protected $deleteWhenMissingModels = true; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @param Volume $volume The volume for which the files should be processed. | ||
* @param array $only (optional) Array of image/video IDs to restrict processing to. | ||
* If it is empty, all files of the volume will be taken. | ||
* @param array $uuidMap Array to map copied file uuid to the original file uuid during cloning process. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Volume $volume, array $uuidMap, array $only = []) | ||
{ | ||
$this->volume = $volume; | ||
$this->only = $only; | ||
$this->uuidMap = $uuidMap; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$query = $this->volume->files() | ||
->when($this->only, fn ($query) => $query->whereIn('id', $this->only)); | ||
|
||
if ($this->volume->isImageVolume()) { | ||
$query->eachById(function (Image $img) { | ||
$prefix = fragment_uuid_path($this->uuidMap[$img->uuid]); | ||
CloneImageThumbnails::dispatch($img, $prefix); | ||
}); | ||
} else { | ||
$queue = config('videos.process_new_video_queue'); | ||
$query->eachById( | ||
function (Video $video) use ($queue) { | ||
$prefix = fragment_uuid_path($this->uuidMap[$video->uuid]); | ||
CloneVideoThumbnails::dispatch($video, $prefix)->onQueue($queue); | ||
} | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.