✨ Introducing new features.
This commit is contained in:
@@ -31,6 +31,9 @@ final class ConfigKey
|
||||
/** @var string 账户是否需要验证 */
|
||||
const IsUserNeedVerify = 'is_user_need_verify';
|
||||
|
||||
/** @var string 是否启用缩略图功能 */
|
||||
const IsEnableThumbnail = 'is_enable_thumbnail';
|
||||
|
||||
/** @var string 邮件配置 */
|
||||
const MailConfigs = 'mail_configs';
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use League\Flysystem\Filesystem;
|
||||
* @property string $filename
|
||||
* @property float $size
|
||||
* @property string $mimetype
|
||||
* @property string $extension
|
||||
* @property string $md5
|
||||
* @property string $sha1
|
||||
* @property integer $width
|
||||
@@ -51,6 +52,7 @@ class Image extends Model
|
||||
'alias_name',
|
||||
'size',
|
||||
'mimetype',
|
||||
'extension',
|
||||
'md5',
|
||||
'sha1',
|
||||
'width',
|
||||
@@ -80,7 +82,7 @@ class Image extends Model
|
||||
static::deleting(function (self $image) {
|
||||
// TODO 检测是否启用了队列,放置队列中异步删除
|
||||
// 在当前图片所属的策略中是否存在其他相同 md5 和 sha1 的记录,没有则可以删除物理文件
|
||||
if (! static::query()
|
||||
if (!static::query()
|
||||
->where('strategy_id', $image->strategy_id)
|
||||
->where('id', '<>', $image->id)
|
||||
->where('md5', $image->md5)
|
||||
@@ -95,18 +97,18 @@ class Image extends Model
|
||||
|
||||
public function filename(): Attribute
|
||||
{
|
||||
return new Attribute(fn () => $this->alias_name ?: $this->origin_name);
|
||||
return new Attribute(fn() => $this->alias_name ?: $this->origin_name);
|
||||
}
|
||||
|
||||
public function pathname(): Attribute
|
||||
{
|
||||
return new Attribute(fn () => "{$this->path}/{$this->name}");
|
||||
return new Attribute(fn() => "{$this->path}/{$this->name}");
|
||||
}
|
||||
|
||||
public function url(): Attribute
|
||||
{
|
||||
return new Attribute(function () {
|
||||
if (! $this->strategy) {
|
||||
if (!$this->strategy) {
|
||||
return Storage::disk('uploads')->url($this->pathname);
|
||||
}
|
||||
$domain = rtrim($this->strategy->configs->get('domain'), '/');
|
||||
@@ -116,7 +118,7 @@ class Image extends Model
|
||||
|
||||
public function links(): Attribute
|
||||
{
|
||||
return new Attribute(fn () => collect([
|
||||
return new Attribute(fn() => collect([
|
||||
'url' => $this->url,
|
||||
'html' => "<img src=\"{$this->url}\" alt=\"{$this->origin_name}\" title=\"{$this->origin_name}\" />",
|
||||
'bbcode' => "[img]{$this->url}[/img]",
|
||||
|
||||
@@ -127,9 +127,10 @@ class ImageService
|
||||
}
|
||||
}
|
||||
|
||||
$pathname = $this->replacePathname(
|
||||
$filename = $this->replacePathname(
|
||||
$configs->get(GroupConfigKey::PathNamingRule).'/'.$configs->get(GroupConfigKey::FileNamingRule), $file,
|
||||
).".{$file->extension()}";
|
||||
);
|
||||
$pathname = $filename.".{$file->extension()}";
|
||||
|
||||
$image->fill([
|
||||
'md5' => md5_file($file->getRealPath()),
|
||||
@@ -139,6 +140,7 @@ class ImageService
|
||||
'origin_name' => $file->getClientOriginalName(),
|
||||
'size' => $file->getSize() / 1024,
|
||||
'mimetype' => $file->getMimeType(),
|
||||
'extension' => $file->extension(),
|
||||
'width' => $img->width(),
|
||||
'height' => $img->height(),
|
||||
'permission' => ImagePermission::Private,
|
||||
|
||||
@@ -27,6 +27,7 @@ class Utils
|
||||
case ConfigKey::IsEnableGallery:
|
||||
case ConfigKey::IsEnableRegistration:
|
||||
case ConfigKey::IsUserNeedVerify:
|
||||
case ConfigKey::IsEnableThumbnail:
|
||||
$value = (bool) $value;
|
||||
break;
|
||||
case ConfigKey::MailConfigs:
|
||||
|
||||
@@ -35,13 +35,6 @@ return [
|
||||
'root' => storage_path('app'),
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
],
|
||||
|
||||
'uploads' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/uploads'),
|
||||
@@ -62,8 +55,6 @@ return [
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
// public_path('storage') => storage_path('app/public'),
|
||||
public_path('uploads') => storage_path('app/uploads'),
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@@ -23,11 +23,12 @@ class CreateImagesTable extends Migration
|
||||
$table->foreignId('album_id')->nullable()->comment('相册')->constrained('albums')->onDelete('set null');
|
||||
$table->foreignId('strategy_id')->nullable()->comment('策略')->constrained('strategies')->onDelete('set null');
|
||||
$table->string('path')->comment('保存路径');
|
||||
$table->string('name')->comment('保存路径');
|
||||
$table->string('name')->comment('保存名称');
|
||||
$table->string('origin_name')->default('')->comment('原始名称');
|
||||
$table->string('alias_name')->default('')->comment('别名');
|
||||
$table->decimal('size')->default(0)->comment('图片大小(kb)');
|
||||
$table->string('mimetype', 32)->comment('文件类型');
|
||||
$table->string('extension', 32)->comment('文件后缀');
|
||||
$table->string('md5', 32)->comment('文件MD5');
|
||||
$table->string('sha1')->comment('文件SHA1');
|
||||
$table->unsignedInteger('width')->default(0)->comment('宽');
|
||||
|
||||
@@ -29,6 +29,7 @@ class DatabaseSeeder extends Seeder
|
||||
ConfigKey::IsAllowGuestUpload => 1,
|
||||
ConfigKey::UserInitialCapacity => 512000,
|
||||
ConfigKey::IsUserNeedVerify => 1,
|
||||
ConfigKey::IsEnableThumbnail => 1,
|
||||
ConfigKey::MailConfigs => json_encode([
|
||||
'default' => 'smtp',
|
||||
'mailers' => [
|
||||
@@ -41,7 +42,7 @@ class DatabaseSeeder extends Seeder
|
||||
SmtpOption::AuthMode => null,
|
||||
],
|
||||
]),
|
||||
ConfigKey::GuestGroupConfigs => Group::getDefaultConfig()->toJson(),
|
||||
ConfigKey::GuestGroupConfigs => Group::getDefaultConfigs()->toJson(),
|
||||
])->transform(function ($value, $key) use ($date) {
|
||||
return ['name' => $key, 'value' => $value, 'updated_at' => $date, 'created_at' => $date];
|
||||
})->values()->toArray();
|
||||
|
||||
Reference in New Issue
Block a user