Skip to content

Commit

Permalink
Fix the handling of files without extensions (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil4 authored Feb 15, 2021
1 parent dcad64e commit eb9166f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion app/Actions/Album/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ private function compress_album($photos_sql, $dir_name, &$dirs, $parent_dir, $al
$pos = strrpos($tmp_file, '.');
while (in_array($tmp_file, $files)) {
// Set new title for photo
$tmp_file = substr_replace($file, '-' . $i, $pos, 0);
if ($pos !== false) {
$tmp_file = substr_replace($file, '-' . $i, $pos, 0);
} else {
// No extension.
$tmp_file = $file . '-' . $i;
}
$i++;
}
$file = $tmp_file;
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Photo/Extensions/ImageEditing.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function resizePhoto(Photo $photo, string $type, int $maxWidth, int $maxH

// Add the @2x postfix if we're dealing with an HiDPI type
if (strpos($type, '2x') > 0) {
$filename = preg_replace('/^(.*)\.(.*)$/', '\1@2x.\2', $filename);
$filename = Helpers::ex2x($filename);
}

// Is photo big enough?
Expand Down
4 changes: 3 additions & 1 deletion app/Assets/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ public static function ex2x($url)
{
$thumbUrl2x = explode('.', $url);

return $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
return (count($thumbUrl2x) === 2) ?
$thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1] :
$thumbUrl2x[0] . '@2x';
}

/**
Expand Down
5 changes: 3 additions & 2 deletions app/Console/Commands/Ghostbuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use App\Assets\Helpers;
use App\Console\Commands\Utilities\Colorize;
use App\Models\Photo;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -93,9 +94,9 @@ public function handle()

// for normal pictures
$to_delete[] = 'small/' . $url;
$to_delete[] = 'small/' . $photoName[0] . '@2x.' . $photoName[1];
$to_delete[] = 'small/' . Helpers::ex2x($url);
$to_delete[] = 'medium/' . $url;
$to_delete[] = 'medium/' . $photoName[0] . '@2x.' . $photoName[1];
$to_delete[] = 'medium/' . Helpers::ex2x($url);
$to_delete[] = 'big/' . $url;

foreach ($to_delete as $del) {
Expand Down
7 changes: 3 additions & 4 deletions app/Models/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Assets\Helpers;
use App\Models\Extensions\PhotoBooleans;
use App\Models\Extensions\PhotoCast;
use App\Models\Extensions\PhotoGetters;
Expand Down Expand Up @@ -185,8 +186,7 @@ public function predelete(bool $keep_original = false)
$photoName = $this->url;
}
if ($photoName !== '') {
$photoName2x = explode('.', $photoName);
$photoName2x = $photoName2x[0] . '@2x.' . $photoName2x[1];
$photoName2x = Helpers::ex2x($photoName);

// Delete Live Photo Video file
// TODO: USE STORAGE FOR DELETE
Expand Down Expand Up @@ -230,8 +230,7 @@ public function predelete(bool $keep_original = false)

if ($this->thumbUrl != '') {
// Get retina thumb url
$thumbUrl2x = explode('.', $this->thumbUrl);
$thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
$thumbUrl2x = Helpers::ex2x($this->thumbUrl);
// Delete thumb
// TODO: USE STORAGE FOR DELETE
if (Storage::exists('thumb/' . $this->thumbUrl) && !unlink(Storage::path('thumb/' . $this->thumbUrl))) {
Expand Down

0 comments on commit eb9166f

Please sign in to comment.