Пример #1
0
 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;
     });
 }
Пример #2
0
    }
    return response()->json($diff);
});
$app->get('/subtitles/jp/diff/{version:\\d{8}[\\dA-Z]{0,2}}', function ($version) {
    if (Cache::has('maintenance') and Cache::get("maintenance") == 'true') {
        return response()->json([]);
    }
    try {
        $diff = SubtitleCache::getDiff($version, 'jp');
    } catch (FileNotFoundException $e) {
        return response()->json(['result' => 'error', 'reason' => 'Version not found']);
    }
    return response()->json($diff);
});
$app->get('/subtitles/jp', function () {
    $subtitles = SubtitleCache::get('latest', 'jp');
    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) {