diff --git a/app/Models/Image.php b/app/Models/Image.php index 2fd7cade..3c6cef18 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -164,7 +164,8 @@ class Image extends Model public function pathname(): Attribute { - return new Attribute(fn() => "{$this->path}/{$this->name}"); + $path = $this->path ? "{$this->path}/" : ''; + return new Attribute(fn() => "{$path}{$this->name}"); } public function url(): Attribute diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php index 2d2cbde3..4bd1b6f5 100644 --- a/app/Services/ImageService.php +++ b/app/Services/ImageService.php @@ -160,7 +160,7 @@ class ImageService $image->fill([ 'md5' => md5_file($file->getRealPath()), 'sha1' => sha1_file($file->getRealPath()), - 'path' => dirname($pathname), + 'path' => $configs->get(GroupConfigKey::PathNamingRule) ? dirname($pathname) : '', 'name' => basename($pathname), 'origin_name' => $file->getClientOriginalName(), 'size' => $file->getSize() / 1024, @@ -541,7 +541,6 @@ class ImageService } catch (\Throwable $e) { Utils::e($e, '生成缩略图时出现异常'); - // TODO 直接将原图存下来? } } }