-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add placeholder uri to thumb resource Add placeholder image rendering Update types Add maintenance placeholder generation Add encoding to placeholder generation remove phpstan ignore with type indication fixes add soft transition effect
- Loading branch information
1 parent
b156ec4
commit 6d39ae5
Showing
53 changed files
with
604 additions
and
25 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
74 changes: 74 additions & 0 deletions
74
app/Actions/Diagnostics/Pipes/Checks/PlaceholderExistsCheck.php
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,74 @@ | ||
<?php | ||
|
||
namespace App\Actions\Diagnostics\Pipes\Checks; | ||
|
||
use App\Contracts\DiagnosticPipe; | ||
use App\Enum\SizeVariantType; | ||
use App\Image\SizeVariantDimensionHelpers; | ||
use App\Models\SizeVariant; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
/** | ||
* Check if there are placeholders that can be generated or encoded. | ||
*/ | ||
class PlaceholderExistsCheck implements DiagnosticPipe | ||
{ | ||
public const INFO_MSG_MISSING = 'Info: Found %d placeholders that could be generated.'; | ||
public const INFO_LINE_MISSING = ' You can use `php artisan lychee:generate_thumbs placeholder %d` to generate them.'; | ||
public const INFO_MSG_UNENCODED = 'Info: Found %d placeholder images that have not been encoded.'; | ||
public const INFO_LINE_UNENCODED = ' You can use `php artisan lychee:encode_placeholders %d` to encode them.'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle(array &$data, \Closure $next): array | ||
{ | ||
if (!Schema::hasTable('configs') || !Schema::hasTable('size_variants')) { | ||
// @codeCoverageIgnoreStart | ||
return $next($data); | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
$svHelpers = new SizeVariantDimensionHelpers(); | ||
if (!$svHelpers->isEnabledByConfiguration(SizeVariantType::PLACEHOLDER)) { | ||
return $next($data); | ||
} | ||
|
||
/** @var object{num_placeholder:int,max_num_placeholder:int,num_unencoded_placeholder:int}> $result */ | ||
$result = DB::query() | ||
->selectSub( | ||
SizeVariant::query() | ||
->selectRaw('COUNT(*)') | ||
->where('type', '=', SizeVariantType::PLACEHOLDER), | ||
'num_placeholder' | ||
) | ||
->selectSub( | ||
SizeVariant::query() | ||
->selectRaw('COUNT(*)') | ||
->where('type', '=', SizeVariantType::ORIGINAL), | ||
'max_num_placeholder' | ||
) | ||
->selectSub( | ||
SizeVariant::query() | ||
->selectRaw('COUNT(*)') | ||
->where('short_path', 'LIKE', '%placeholder/%'), | ||
'num_unencoded_placeholder' | ||
) | ||
->first(); | ||
|
||
$num = $result->num_unencoded_placeholder; | ||
if ($num > 0) { | ||
$data[] = sprintf(self::INFO_MSG_UNENCODED, $num); | ||
$data[] = sprintf(self::INFO_LINE_UNENCODED, $num); | ||
} | ||
|
||
$num = $result->max_num_placeholder - $result->num_placeholder; | ||
if ($num > 0) { | ||
$data[] = sprintf(self::INFO_MSG_MISSING, $num); | ||
$data[] = sprintf(self::INFO_LINE_MISSING, $num); | ||
} | ||
|
||
return $next($data); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace App\Actions\Photo\Pipes\Standalone; | ||
|
||
use App\Contracts\PhotoCreate\StandalonePipe; | ||
use App\DTO\PhotoCreate\StandaloneDTO; | ||
use App\Exceptions\MediaFileOperationException; | ||
use App\Image\PlaceholderEncoder; | ||
|
||
class EncodePlaceholder implements StandalonePipe | ||
{ | ||
public function handle(StandaloneDTO $state, \Closure $next): StandaloneDTO | ||
{ | ||
try { | ||
$placeholderEncoder = new PlaceholderEncoder(); | ||
$placeholder = $state->getPhoto()->size_variants->getPlaceholder(); | ||
if ($placeholder !== null) { | ||
$placeholderEncoder->do($placeholder); | ||
} | ||
|
||
return $next($state); | ||
} catch (\ErrorException $e) { | ||
throw new MediaFileOperationException('Failed to encode placeholder to base64', $e); | ||
} | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
app/Console/Commands/ImageProcessing/EncodePlaceholders.php
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,63 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\ImageProcessing; | ||
|
||
use App\Exceptions\UnexpectedException; | ||
use App\Image\PlaceholderEncoder; | ||
use App\Models\SizeVariant; | ||
use Illuminate\Console\Command; | ||
use Safe\Exceptions\InfoException; | ||
use function Safe\set_time_limit; | ||
|
||
class EncodePlaceholders extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'lychee:encode_placeholders {limit=5 : number of photos to encode placeholders for} {tm=600 : timeout time requirement}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Encode placeholders if size variant exists and image has not been encoded'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
try { | ||
$limit = (int) $this->argument('limit'); | ||
$timeout = (int) $this->argument('tm'); | ||
|
||
try { | ||
set_time_limit($timeout); | ||
} catch (InfoException) { | ||
// Silently do nothing, if `set_time_limit` is denied. | ||
} | ||
|
||
$placeholders = SizeVariant::query() | ||
->where('short_path', 'LIKE', '%placeholder/%') | ||
->limit($limit) | ||
->get(); | ||
if (count($placeholders) === 0) { | ||
$this->line('No placeholders require encoding.'); | ||
|
||
return 0; | ||
} | ||
|
||
$placeholderEncoder = new PlaceholderEncoder(); | ||
foreach ($placeholders as $placeholder) { | ||
$placeholderEncoder->do($placeholder); | ||
} | ||
|
||
return 0; | ||
} catch (\Throwable $e) { | ||
throw new UnexpectedException($e); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.