Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stacked 6] Remove hard coded values from naming strategy #2384

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Actions/Photo/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Actions\Photo\Extensions\ArchiveFileInfo;
use App\Contracts\Exceptions\LycheeException;
use App\Contracts\Models\AbstractSizeVariantNamingStrategy;
use App\Enum\DownloadVariantType;
use App\Enum\SizeVariantType;
use App\Exceptions\ConfigurationKeyMissingException;
Expand All @@ -14,6 +13,7 @@
use App\Models\Configs;
use App\Models\Photo;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Storage;
use Safe\Exceptions\InfoException;
use function Safe\fclose;
use function Safe\fopen;
Expand Down Expand Up @@ -284,7 +284,8 @@ protected function extractFileInfo(Photo $photo, DownloadVariantType $downloadVa
$baseFilename = $validFilename !== '' ? $validFilename : 'Untitled';

if ($downloadVariant === DownloadVariantType::LIVEPHOTOVIDEO) {
$sourceFile = new FlysystemFile(AbstractSizeVariantNamingStrategy::getImageDisk(), $photo->live_photo_short_path);
$disk = $photo->size_variants->getSizeVariant(SizeVariantType::ORIGINAL)->storage_disk->value;
$sourceFile = new FlysystemFile(Storage::disk($disk), $photo->live_photo_short_path);
$baseFilenameAddon = '';
} else {
$sv = $photo->size_variants->getSizeVariant($downloadVariant->getSizeVariantType());
Expand Down
10 changes: 8 additions & 2 deletions app/Actions/Photo/Pipes/VideoPartner/PlaceVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
namespace App\Actions\Photo\Pipes\VideoPartner;

use App\Actions\Diagnostics\Pipes\Checks\BasicPermissionCheck;
use App\Contracts\Models\AbstractSizeVariantNamingStrategy;
use App\Assets\Features;
use App\Contracts\PhotoCreate\VideoPartnerPipe;
use App\DTO\PhotoCreate\VideoPartnerDTO;
use App\Enum\StorageDiskType;
use App\Exceptions\ConfigurationException;
use App\Exceptions\Handler;
use App\Exceptions\Internal\LycheeAssertionError;
use App\Exceptions\MediaFileOperationException;
use App\Image\Files\FlysystemFile;
use App\Image\Files\NativeLocalFile;
use App\Image\StreamStat;
use Illuminate\Support\Facades\Storage;

/**
* Puts the video source file into the final position at video target file.
Expand Down Expand Up @@ -47,7 +49,11 @@ class PlaceVideo implements VideoPartnerPipe
{
public function handle(VideoPartnerDTO $state, \Closure $next): VideoPartnerDTO
{
$videoTargetFile = new FlysystemFile(AbstractSizeVariantNamingStrategy::getImageDisk(), $state->videoPath);
$disk = Storage::disk(StorageDiskType::LOCAL->value);
if (Features::active('use-s3')) {
$disk = Storage::disk(StorageDiskType::S3->value);
}
$videoTargetFile = new FlysystemFile($disk, $state->videoPath);

try {
if ($state->videoFile instanceof NativeLocalFile) {
Expand Down
11 changes: 9 additions & 2 deletions app/Console/Commands/Ghostbuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace App\Console\Commands;

use App\Assets\Features;
use App\Console\Commands\Utilities\Colorize;
use App\Contracts\Models\AbstractSizeVariantNamingStrategy;
use App\Enum\SizeVariantType;
use App\Enum\StorageDiskType;
use App\Exceptions\UnexpectedException;
use App\Models\Photo;
use App\Models\SizeVariant;
Expand Down Expand Up @@ -73,11 +74,17 @@ public function handle(): int
$removeDeadSymLinks = filter_var($this->option('removeDeadSymLinks'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === true;
$removeZombiePhotos = filter_var($this->option('removeZombiePhotos'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === true;
$dryrun = filter_var($this->option('dryrun'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== false;
$uploadDisk = AbstractSizeVariantNamingStrategy::getImageDisk();
$uploadDisk = Features::active('use-s3')
? Storage::disk(StorageDiskType::S3->value)
: Storage::disk(StorageDiskType::LOCAL->value);
$symlinkDisk = Storage::disk(SymLink::DISK_NAME);
$isLocalDisk = $uploadDisk->getAdapter() instanceof LocalFilesystemAdapter;

$this->line('');
if (!$isLocalDisk) {
$this->line($this->col->red('Using non-local disk to store images, USE AT YOUR OWN RISKS! This code is not battle tested.'));
$this->line('');
}

if ($removeDeadSymLinks && !$isLocalDisk) {
$this->line($this->col->yellow('Removal of dead symlinks requested, but filesystem does not support symlinks.'));
Expand Down
14 changes: 0 additions & 14 deletions app/Contracts/Models/AbstractSizeVariantNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use App\Enum\SizeVariantType;
use App\Image\Files\FlysystemFile;
use App\Models\Photo;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;

/**
* Interface SizeVariantNamingStrategy.
Expand All @@ -17,21 +15,9 @@ abstract class AbstractSizeVariantNamingStrategy
/**
* The name of the Flysystem disk where images are stored.
ildyria marked this conversation as resolved.
Show resolved Hide resolved
*/
public const IMAGE_DISK_NAME = 'images';

protected string $extension = '';
protected ?Photo $photo = null;

/**
* Returns the disk on which the size variants are put.
*
* @return FilesystemAdapter
*/
public static function getImageDisk(): FilesystemAdapter
{
return Storage::disk(self::IMAGE_DISK_NAME);
}

/**
* Sets the extension to be used for the size variants.
*
Expand Down
Loading