From 798e72f634bda93cdb1f98c5ce00535543a418b3 Mon Sep 17 00:00:00 2001 From: Wisp X <1591788658@qq.com> Date: Fri, 1 Apr 2022 16:20:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E8=B7=AF=E5=BE=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=AE=BE=E7=BD=AE=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Image.php | 3 ++- app/Services/ImageService.php | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 直接将原图存下来? } } }