Skip to content

Commit

Permalink
Improve diagnostics by adding check of temporary file systems (#2251)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Jan 29, 2024
1 parent f71f756 commit 327f899
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Exceptions\Handler;
use App\Exceptions\Internal\InvalidConfigOption;
use App\Facades\Helpers;
use App\Image\Files\ProcessableJobFile;
use App\Livewire\Components\Forms\Add\Upload;
use App\Models\SymLink;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Facades\Storage;
Expand Down Expand Up @@ -106,6 +108,8 @@ function (int $gid): string {
$disks = [
AbstractSizeVariantNamingStrategy::getImageDisk(),
Storage::disk(SymLink::DISK_NAME),
Storage::disk(ProcessableJobFile::DISK_NAME),
Storage::disk(Upload::DISK_NAME),
];

foreach ($disks as $disk) {
Expand Down Expand Up @@ -300,7 +304,7 @@ private function anonymize(string $path): string
$this->realPaths[] = public_path();
$this->anonymizePaths[] = Helpers::censor(public_path(), 0.2);
$this->realPaths[] = storage_path();
$this->anonymizePaths[] = Helpers::censor(storage_path(), 0.2);
$this->anonymizePaths[] = Helpers::censor(storage_path(), 0.4);
$this->realPaths[] = config('filesystems.disks.images.root');
$this->anonymizePaths[] = Helpers::censor(config('filesystems.disks.images.root'), 0.2);
}
Expand Down
4 changes: 3 additions & 1 deletion app/Image/Files/ProcessableJobFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Image\Files;

use App\Exceptions\MediaFileOperationException;
use Illuminate\Support\Facades\Storage;
use function Safe\mkdir;

/**
Expand All @@ -14,6 +15,7 @@
class ProcessableJobFile extends NativeLocalFile
{
use LoadTemporaryFileTrait;
public const DISK_NAME = 'image-jobs';

protected string $fakeBaseName;

Expand All @@ -39,7 +41,7 @@ public function __construct(string $fileExtension, string $fakeBaseName = '')
*/
protected function getFileBasePath(): string
{
$tempDirPath = storage_path() . DIRECTORY_SEPARATOR . 'image-jobs';
$tempDirPath = Storage::disk(self::DISK_NAME)->path('');

if (!file_exists($tempDirPath)) {
mkdir($tempDirPath);
Expand Down
5 changes: 3 additions & 2 deletions app/Livewire/Components/Forms/Add/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Upload extends Component
{
use WithFileUploads;
use InteractWithModal;
public const DISK_NAME = 'livewire-upload';

/**
* @var string|null albumId of where to upload the picture
Expand Down Expand Up @@ -99,7 +100,7 @@ public function updatedUploads($value, string $key): void
$fileDetails = $this->uploads[$index];
/** @var TemporaryUploadedFile $chunkFile */
$chunkFile = $fileDetails['fileChunk'];
$final = new NativeLocalFile(Storage::path('/livewire-tmp/' . $fileDetails['uuidName']));
$final = new NativeLocalFile(Storage::disk(self::DISK_NAME)->path($fileDetails['uuidName']));
$final->append($chunkFile->readStream());
$chunkFile->delete();

Expand All @@ -118,7 +119,7 @@ public function triggerProcessing(): void
{
foreach ($this->uploads as $idx => $fileData) {
if ($fileData['stage'] === FileStatus::READY->value) {
$uploadedFile = new NativeLocalFile(Storage::path('/livewire-tmp/' . $fileData['uuidName']));
$uploadedFile = new NativeLocalFile(Storage::disk(self::DISK_NAME)->path($fileData['uuidName']));
$processableFile = new ProcessableJobFile(
$fileData['extension'],
$fileData['fileName']
Expand Down
23 changes: 23 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ function renv_cond(string $cst): string
'visibility' => 'public',
],

// We use this space to temporarily store images when uploading.
// Mostly chunks and incomplete images are placed here
'livewire-upload' => [
'driver' => 'local',
'root' => env('LYCHEE_TMP_UPLOAD', storage_path('livewire-tmp')),
'visibility' => 'private',
],

// We use this space to process the images,
'image-jobs' => [
'driver' => 'local',
'root' => env('LYCHEE_IMAGE_JOBS', storage_path('image-jobs')),
'visibility' => 'private',
],

// This is where we extract zip files before importing them.
'extract-jobs' => [
'driver' => 'local',
'root' => env('LYCHEE_EXTRACT_JOBS', storage_path('extract-jobs')),
'visibility' => 'private',
],

// For tests purposes
'tmp-for-tests' => [
'driver' => 'local',
'root' => storage_path('image-tmp/'),
Expand Down

0 comments on commit 327f899

Please sign in to comment.