|
|
@@ -432,24 +432,27 @@ class Egame extends Controller
|
|
|
'sort' => 0,
|
|
|
] : [];
|
|
|
|
|
|
- foreach (['name', 'description', 'ingress', 'network', 'logo_h5'] as $field) {
|
|
|
+ foreach (['name', 'description', 'ingress', 'network'] as $field) {
|
|
|
if (array_key_exists($field, $input)) {
|
|
|
$data[$field] = trim((string) $input[$field]);
|
|
|
}
|
|
|
}
|
|
|
+ if (array_key_exists('logo_h5', $input)) {
|
|
|
+ $data['logo_h5'] = $this->logoPathForStorage((string) $input['logo_h5']);
|
|
|
+ }
|
|
|
|
|
|
// logo_pc 是新版后台使用的 PC Logo 字段,数据库仍统一保存到 logo。
|
|
|
// 两个字段同时出现时以 logo_pc 为准,避免列表整行回传的旧 logo
|
|
|
// 覆盖用户刚上传的新 logo_pc;同时修复新增记录只传 logo_pc 无法保存。
|
|
|
if (array_key_exists('logo', $input)) {
|
|
|
- $data['logo'] = trim((string) $input['logo']);
|
|
|
+ $data['logo'] = $this->logoPathForStorage((string) $input['logo']);
|
|
|
}
|
|
|
if (array_key_exists('logo_pc', $input)) {
|
|
|
- $data['logo'] = trim((string) $input['logo_pc']);
|
|
|
+ $data['logo'] = $this->logoPathForStorage((string) $input['logo_pc']);
|
|
|
}
|
|
|
if (array_key_exists('logo_langs', $input)) {
|
|
|
$data['logo_langs'] = $item->item_type === EgameItem::TYPE_GAME
|
|
|
- ? $input['logo_langs']
|
|
|
+ ? $this->logoLangsForStorage($input['logo_langs'])
|
|
|
: null;
|
|
|
}
|
|
|
if (array_key_exists('status', $input)) {
|
|
|
@@ -567,8 +570,16 @@ class Egame extends Controller
|
|
|
$item->setAttribute('effective_status', $disabledBy === null ? 1 : 0);
|
|
|
$item->setAttribute('disabled_by', $disabledBy);
|
|
|
$item->setAttribute('description', (string) ($item->description ?? ''));
|
|
|
- $item->setAttribute('logo_pc', (string) ($item->logo ?? ''));
|
|
|
- $item->setAttribute('logo_h5', (string) ($item->logo_h5 ?? ''));
|
|
|
+ $logo = $this->absoluteLogoUrl((string) ($item->logo ?? ''));
|
|
|
+ $item->setAttribute('logo', $logo);
|
|
|
+ $item->setAttribute('logo_pc', $logo);
|
|
|
+ $item->setAttribute('logo_h5', $this->absoluteLogoUrl((string) ($item->logo_h5 ?? '')));
|
|
|
+ if (is_array($item->logo_langs)) {
|
|
|
+ $item->setAttribute('logo_langs', array_map(
|
|
|
+ fn ($path): string => $this->absoluteLogoUrl((string) $path),
|
|
|
+ $item->logo_langs
|
|
|
+ ));
|
|
|
+ }
|
|
|
$this->decorateNetwork($item, $globalPlatform, $platformRelation);
|
|
|
$item->setAttribute('ingress_name', EgameItem::ingressName($item->ingress ?? ''));
|
|
|
$item->setAttribute('status_name', EgameItem::STATUS_LABELS[(int) $item->status] ?? '');
|
|
|
@@ -585,6 +596,64 @@ class Egame extends Controller
|
|
|
return $item;
|
|
|
}
|
|
|
|
|
|
+ private function absoluteLogoUrl(string $path): string
|
|
|
+ {
|
|
|
+ $path = trim($path);
|
|
|
+ if ($path === '' || preg_match('/^(?:https?:)?\/\//i', $path) || preg_match('/^(?:data|blob):/i', $path)) {
|
|
|
+ return $path;
|
|
|
+ }
|
|
|
+
|
|
|
+ $relativePath = '/' . ltrim($path, '/');
|
|
|
+ $baseUrl = $this->normalizedLogoBaseUrl((string) config('app.url', ''));
|
|
|
+ if ($baseUrl === '') {
|
|
|
+ $baseUrl = $this->normalizedLogoBaseUrl(request()->getSchemeAndHttpHost());
|
|
|
+ }
|
|
|
+
|
|
|
+ return $baseUrl . $relativePath;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function logoPathForStorage(string $path): string
|
|
|
+ {
|
|
|
+ $path = trim($path);
|
|
|
+ if ($path === '' || !preg_match('/^https?:\/\//i', $path)) {
|
|
|
+ return $path;
|
|
|
+ }
|
|
|
+
|
|
|
+ $baseUrls = array_filter(array_unique([
|
|
|
+ $this->normalizedLogoBaseUrl((string) config('app.url', '')),
|
|
|
+ $this->normalizedLogoBaseUrl(request()->getSchemeAndHttpHost()),
|
|
|
+ ]));
|
|
|
+ foreach ($baseUrls as $baseUrl) {
|
|
|
+ if (str_starts_with($path, $baseUrl . '/')) {
|
|
|
+ return '/' . ltrim(substr($path, strlen($baseUrl)), '/');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $path;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function normalizedLogoBaseUrl(string $baseUrl): string
|
|
|
+ {
|
|
|
+ $baseUrl = rtrim(trim($baseUrl), '/');
|
|
|
+ if ($baseUrl !== '' && !preg_match('/^https?:\/\//i', $baseUrl)) {
|
|
|
+ $baseUrl = 'https://' . $baseUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $baseUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function logoLangsForStorage($logos): array
|
|
|
+ {
|
|
|
+ if (!is_array($logos)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ return array_map(
|
|
|
+ fn ($path): string => $this->logoPathForStorage((string) $path),
|
|
|
+ $logos
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
private function gameCountsByPlat(): array
|
|
|
{
|
|
|
$counts = [];
|