feat: app

This commit is contained in:
hashbro
2026-09-28 06:12:47 +08:00
parent ad09fdff88
commit e0b06e0d24
14 changed files with 1609 additions and 275 deletions
+29 -1
View File
@@ -14,6 +14,8 @@ class Channel extends Model
public const BUILDER_NEW = 'new';
public const BUILDER_APP = 'app';
/** New-builder channel id / core ver·sdkv patch string: exactly 6 chars like 2.2.66 (alnum + dots). */
public const NEW_CHANNEL_ID_PATTERN = '/^[0-9A-Z]\.[0-9A-Z]\.[0-9A-Z]{2}$/';
@@ -34,6 +36,7 @@ class Channel extends Model
protected $fillable = [
'channel_id', 'builder_type', 'user_id', 'domains', 'status', 'remark',
'app_name', 'bundle_id',
];
protected $attributes = [
@@ -88,11 +91,23 @@ class Channel extends Model
return $this->builderType() === self::BUILDER_NEW;
}
public function isAppBuilder(): bool
{
return $this->builderType() === self::BUILDER_APP;
}
public function builderType(): string
{
$type = strtolower(trim((string) ($this->builder_type ?? '')));
return $type === self::BUILDER_NEW ? self::BUILDER_NEW : self::BUILDER_OLD;
if ($type === self::BUILDER_NEW) {
return self::BUILDER_NEW;
}
if ($type === self::BUILDER_APP) {
return self::BUILDER_APP;
}
return self::BUILDER_OLD;
}
public function agentLabel(): string
@@ -194,6 +209,19 @@ class Channel extends Model
return bin2hex(random_bytes(16));
}
/** UUID v4 channel id for app builder channels (e.g. a13b4f76-d901-46f5-b447-36b7e856ea31). */
public static function randomAppChannelId(): string
{
for ($i = 0; $i < 64; $i++) {
$uuid = \Illuminate\Support\Str::uuid()->toString();
if (! self::query()->where('channel_id', $uuid)->exists()) {
return $uuid;
}
}
throw new RuntimeException('无法生成唯一渠道 ID');
}
public static function normalizeNewChannelId(string $channelId): ?string
{
$channelId = strtoupper(trim($channelId));