1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-29 09:44:28 +01:00

json api: fix building of catalog.json (NB: this puts extra load on server; we can try to make it lighter)

This commit is contained in:
czaks 2013-12-28 18:03:49 +01:00
parent 0c31674f1b
commit 3b65bcb0f8

View File

@ -1365,13 +1365,27 @@ function buildIndex() {
for ($page = 1; $page <= $config['max_pages']; $page++) {
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page));
if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages)
if (!$config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages)
&& !in_array($page, $build_pages) && is_file($filename))
continue;
$content = index($page);
if (!$content)
break;
// json api
if ($config['api']['enabled']) {
$threads = $content['threads'];
$json = json_encode($api->translatePage($threads));
$jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
file_write($jsonFilename, $json);
$catalog[$page-1] = $threads;
}
if ($config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages)
&& !in_array($page, $build_pages) && is_file($filename))
continue;
if ($config['try_smarter']) {
$antibot = create_antibot($board['uri'], 0 - $page);
$content['current_page'] = $page;
@ -1383,16 +1397,6 @@ function buildIndex() {
$content['antibot'] = $antibot;
file_write($filename, Element('index.html', $content));
// json api
if ($config['api']['enabled']) {
$threads = $content['threads'];
$json = json_encode($api->translatePage($threads));
$jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
file_write($jsonFilename, $json);
$catalog[$page-1] = $threads;
}
}
if ($page < $config['max_pages']) {