Merge pull request #975 from catamphetamine/boardsApi

JSON API: Boards List
This commit is contained in:
Lorenzo Yario 2025-10-26 03:36:04 -05:00 committed by GitHub
commit 5e472bafac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -208,4 +208,24 @@ class Api {
return $apiCatalog;
}
public function translateBoard(Board $board) {
$apiBoard = [];
foreach ($boards as $board) {
$apiBoard['uri'] = $board['uri'];
$apiBoard['title'] = $board['title'];
$apiBoard['subtitle'] = $board['subtitle'];
}
return $apiBoard;
}
public function translateBoards($boards) {
$apiBoards = [];
foreach ($boards as $board) {
$apiBoards[] = $this->translateBoard($board);
}
return $apiBoards;
}
}

View File

@ -432,6 +432,18 @@ function setupBoard($array) {
if (!file_exists($board['dir'] . $config['dir']['res']))
@mkdir($board['dir'] . $config['dir']['res'], 0777)
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
// json api
if ($config['api']['enabled'] && !$mod) {
$api = new Api(
$config['show_filename'],
$config['hide_email'],
$config['country_flags']
);
$json = json_encode($api->translateBoards(listBoards()));
$jsonFilename = 'boards.json';
file_write($jsonFilename, $json);
}
}
function openBoard($uri) {