public static function getDiff($ver = '', $lang = 'zh-cn') { if (!$ver) { return ['error' => 'Version not found']; } $latest = self::getLatest(); if ($latest == $ver) { return []; } $key = $lang . $ver . '-' . $latest; return self::remember($key, function () use($ver, $latest, $lang) { $diff = []; $latestSubtitles = SubtitleCache::get('latest', $lang); $targetSubtitles = SubtitleCache::get($ver, $lang); foreach ($latestSubtitles as $shipId => $voices) { if ($shipId == 'version' || !$shipId) { continue; } if (array_key_exists($shipId, $targetSubtitles)) { foreach ($voices as $voiceId => $text) { if (!array_key_exists($voiceId, $targetSubtitles[$shipId]) || $targetSubtitles[$shipId][$voiceId] != $text) { if (!array_key_exists($shipId, $diff)) { $diff[$shipId] = []; } $diff[$shipId][$voiceId] = $text; } } } else { $diff[$shipId] = $voices; } } $diff['version'] = $latest; return $diff; }); }
if ($subtitles) { return $subtitles; } else { return response()->json(['result' => 'error', 'reason' => 'Subtitles not found']); } }); $app->get('/subtitles/jp/{id:\\d{1,4}}', function ($id) { $subtitles = SubtitleCache::getByShip($id, 'jp'); if ($subtitles) { return $subtitles; } else { return response()->json(['result' => 'error', 'reason' => 'Subtitles not found']); } }); $app->get('/subtitles/{id:\\d{1,4}}', function ($id) { $subtitles = SubtitleCache::getByShip($id); if ($subtitles) { return $subtitles; } else { return response()->json(['result' => 'error', 'reason' => 'Subtitles not found']); } }); $app->get('/subtitles/detail', ['middleware' => 'cache', function () { $subtitlesRaw = Util::remember('subtitles/distinct', function () { return json_decode(Storage::disk('local')->get('subtitles/subtitles_distinct.json'), true); }); $subtitles = $subtitlesRaw['zh']; $subtitlesJP = $subtitlesRaw['jp']; $ships = json_decode(Util::getShips(), true); $results = []; foreach ($ships as $ship) {
foreach ($ships as $ship) { if ($ship['sort_no'] == $id) { return response()->json($ship); } } return response()->json(['result' => 'error', 'reason' => 'ship not found']); }]); $app->get('/ship/detail/{name:.{1,100}}', ['middleware' => 'cache', function ($name) { $ships = json_decode(SubtitleCache::remember('ships/detail', function () { return Storage::disk('local')->get('ship/detailed/all.json'); }), true); $name = urldecode($name); foreach ($ships as $i => $ship) { if ($ship['name'] === $name || $ship['chinese_name'] === $name) { return response()->json($ship); } } return response()->json(['result' => 'error', 'reason' => 'ship not found']); }]); $app->get('/ship/{name:.{1,100}}', ['middleware' => 'cache', function ($name) { $ships = json_decode(SubtitleCache::remember('ships', function () { return Storage::disk('local')->get('ship/all.json'); }), true); $name = urldecode($name); foreach ($ships as $i => $ship) { if ($ship['name'] === $name || $ship['chinese_name'] === $name) { return response()->json($ship); } } return response()->json(['result' => 'error', 'reason' => 'ship not found']); }]);