Browse Source

refactor(backend): 优化扩展版本信息处理

- 移除了对版本号的必填验证,改为可选字段
- 在扩展信息中添加默认版本号和核心版本号
  - 版本号默认为 1.0.0
  - 核心版本号默认为 ^1.0- 保持了其他字段的验证规则不变
runphp 7 months ago
parent
commit
d08b095268
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/ExtensionManager.php

+ 8 - 2
src/ExtensionManager.php

@@ -210,8 +210,8 @@ class ExtensionManager extends Service
                 'is_core' => 'in:0,1',
                 'category' => 'in:' . implode(',', array_keys($categoryMap)),
                 'description' => 'max:65535',
-                'version' => 'require|max:20',
-                'core_version' => 'require|max:20',
+                'version' => 'max:20',
+                'core_version' => 'max:20',
                 'author' => 'require|max:100',
                 'email' => 'email|max:100',
                 'website' => 'url|max:255',
@@ -224,6 +224,12 @@ class ExtensionManager extends Service
         if (!isset($extensionInfo['id']) || $extensionInfo['id'] !== $name) {
             throw new RuntimeException("{$name}扩展id({$extensionInfo['id']})与目录名不一致");
         }
+        if (!isset($extensionInfo['version'])) {
+            $extensionInfo['version'] = '1.0.0';
+        }
+        if (!isset($extensionInfo['core_version'])) {
+            $extensionInfo['core_version'] = '^1.0';
+        }
         $extension = ExtensionModel::where(['id' => $name])->append(['status_text'])->findOrEmpty();
         if ($extension->isEmpty()) {
             $extensionInfo['status'] = 1; // 下载的扩展默认未安装