Update api/list.php
This commit is contained in:
+40
-4
@@ -1,30 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../includes/config.php';
|
||||
require_once __DIR__ . '/../includes/jsondb.php';
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/../includes/auth.php';
|
||||
|
||||
requireLogin();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
try {
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
echo json_encode([
|
||||
'error' => 'not_logged_in'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
$lang = $_GET['lang'] ?? '';
|
||||
$list = $_GET['list'] ?? '';
|
||||
|
||||
if ($lang === '' || $list === '') {
|
||||
echo json_encode([
|
||||
'error' => 'missing_params'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$file = listPath($user, $lang, $list);
|
||||
|
||||
if (!file_exists($file)) {
|
||||
echo json_encode([
|
||||
'error' => 'file_not_found',
|
||||
'file' => $file
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = JsonDB::read($file);
|
||||
|
||||
if (!isset($data['words'])) {
|
||||
if (!is_array($data) || !isset($data['words'])) {
|
||||
echo json_encode([
|
||||
'error' => 'list_not_found'
|
||||
'error' => 'invalid_data_structure'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'metadata' => $data['metadata'] ?? null,
|
||||
'words' => $data['words']
|
||||
]);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
|
||||
http_response_code(500);
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'server_exception',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user