|
@@ -4,10 +4,10 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace App\Services\Config;
|
|
|
|
|
|
-class ClientConfig
|
|
|
+final class ClientConfig
|
|
|
{
|
|
|
private static ?array $config = null;
|
|
|
-
|
|
|
+
|
|
|
public static function getClients(string $sub, string $name, bool $r2): array
|
|
|
{
|
|
|
if (self::$config === null) {
|
|
@@ -15,19 +15,19 @@ class ClientConfig
|
|
|
if (!is_readable($file)) {
|
|
|
throw new \RuntimeException("Client config file not found: {$file}");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$content = file_get_contents($file);
|
|
|
if ($content === false) {
|
|
|
throw new \RuntimeException("Failed to read client config file: {$file}");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
self::$config = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
|
|
|
} catch (\JsonException $e) {
|
|
|
- throw new \RuntimeException("Invalid JSON in client config file: " . $e->getMessage());
|
|
|
+ throw new \RuntimeException('Invalid JSON in client config file: ' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$result = [];
|
|
|
foreach (self::$config['clients'] as $client) {
|
|
|
foreach ($client['platforms'] as $platform => $data) {
|
|
@@ -36,17 +36,17 @@ class ClientConfig
|
|
|
'description' => $data['desc'] ?? $client['description'],
|
|
|
'format' => $client['format'],
|
|
|
'importUrl' => str_replace(
|
|
|
- ['{sub}', '{name}'],
|
|
|
- [$sub, rawurlencode($name)],
|
|
|
+ ['{sub}', '{name}'],
|
|
|
+ [$sub, rawurlencode($name)],
|
|
|
$data['importUrl'] ?? $client['importUrl']
|
|
|
),
|
|
|
- 'downloadUrl' => isset($data['storeUrl']) ? $data['storeUrl'] :
|
|
|
- (isset($data['ext']) ? ($r2 ? '/user' : '') . "/clients/" . ($data['file'] ?? str_replace(' ', '.', $client['name'])) . ".{$data['ext']}" : ''),
|
|
|
- 'isAppStore' => isset($data['storeUrl'])
|
|
|
+ 'downloadUrl' => $data['storeUrl'] ??
|
|
|
+ (isset($data['ext']) ? ($r2 ? '/user' : '') . '/clients/' . ($data['file'] ?? str_replace(' ', '.', $client['name'])) . ".{$data['ext']}" : ''),
|
|
|
+ 'isAppStore' => isset($data['storeUrl']),
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return ['clients' => $result, 'icons' => self::$config['icons']];
|
|
|
}
|
|
|
}
|