From: Christian Weiske Date: Tue, 6 Jun 2023 15:11:03 +0000 (+0200) Subject: Inject translation strings into connect response X-Git-Url: https://git.cweiske.de/gamestick-pjgsapi.git/commitdiff_plain/1ce800eca374430843d66b37ff23d01a31b235dd Inject translation strings into connect response --- diff --git a/www/api/rest/connect.php b/www/api/rest/connect.php index 71d8273..ba45c8a 100644 --- a/www/api/rest/connect.php +++ b/www/api/rest/connect.php @@ -3,6 +3,8 @@ * Generate the apps list + other information available at * http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json */ +#readfile(dirname(__FILE__, 4) . '/alex.json');die(); + header('HTTP/1.0 500 Internal Server Error'); $rootDir = dirname(__FILE__, 4); @@ -69,26 +71,24 @@ $data = [ 'lastaccessed' => $nowMilli, 'x-forwarded-for' => null, 'created' => $nowMilli, - 'accessCount' => 0, + 'accessCount' => 1, 'addr' => '1.2.3.4', 'remoteaddr' => '1.2.3.4', 'body' => [ 'status' => 'CONNECTED', + 'verificationCode' => 'd7d987', 'config' => [ - 'apps' => 'FIXME_APPS', + 'apps' => 'PLACEHOLDER_APPS', 'global' => [ 'defaults' => [ 'images' => [], 'currency' => null, 'social' => [], ], - 'uitranslation' => [ - 'version' => 0, - 'country' => [], - ], + 'uitranslation' => 'PLACEHOLDER_UITRANSLATION', 'newfeatured' => [ - 'ages' => 'FIXME_AGES', + 'ages' => 'PLACEHOLDER_AGES', ], ], ] @@ -98,25 +98,24 @@ $data = [ $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); -//inject apps -$appsCacheFile = $cacheDir . 'connect-apps.min.json'; -if (!file_exists($appsCacheFile)) { - header('Content-Type: text/plain'); - echo "Cache file missing: connect-apps.min.json\n"; - exit(1); -} -$json = str_replace('"FIXME_APPS"', file_get_contents($appsCacheFile), $json); - - -//inject featured apps -$featuredAgesCacheFile = $cacheDir . 'connect-featured-ages.min.json'; -if (!file_exists($featuredAgesCacheFile)) { - header('Content-Type: text/plain'); - echo "Cache file missing: connect-featured-ages.min.json\n"; - exit(1); +$placeholderFiles = [ + 'PLACEHOLDER_APPS' => $cacheDir . 'connect-apps.min.json', + 'PLACEHOLDER_AGES' => $cacheDir . 'connect-featured-ages.min.json', + 'PLACEHOLDER_UITRANSLATION' => $cacheDir . 'connect-uitranslation.min.json', +]; +foreach ($placeholderFiles as $placeholder => $cacheFile) { + //inject apps + if (!file_exists($cacheFile)) { + header('Content-Type: text/plain'); + echo "Cache file missing: $cacheFile\n"; + exit(1); + } + $json = str_replace( + '"' . $placeholder . '"', + trim(file_get_contents($cacheFile)), + $json + ); } -$json = str_replace('"FIXME_AGES"', file_get_contents($featuredAgesCacheFile), $json); - header('HTTP/1.0 200 OK'); header('Content-Type: application/json');