Update api/list.php

This commit is contained in:
2026-06-16 10:57:53 +02:00
parent 939de60914
commit b3400ac4a1
+51 -15
View File
@@ -1,30 +1,66 @@
<?php <?php
declare(strict_types=1);
require_once __DIR__ . '/../includes/config.php'; require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/jsondb.php'; require_once __DIR__ . '/../includes/jsondb.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/auth.php'; require_once __DIR__ . '/../includes/auth.php';
requireLogin(); header('Content-Type: application/json; charset=utf-8');
header('Content-Type: application/json'); try {
$user = $_SESSION['user']; if (!isset($_SESSION['user'])) {
echo json_encode([
'error' => 'not_logged_in'
]);
exit;
}
$lang = $_GET['lang'] ?? ''; $user = $_SESSION['user'];
$list = $_GET['list'] ?? '';
$file = listPath($user, $lang, $list); $lang = $_GET['lang'] ?? '';
$list = $_GET['list'] ?? '';
$data = JsonDB::read($file); 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 (!is_array($data) || !isset($data['words'])) {
echo json_encode([
'error' => 'invalid_data_structure'
]);
exit;
}
if (!isset($data['words'])) {
echo json_encode([ echo json_encode([
'error' => 'list_not_found' 'ok' => true,
'metadata' => $data['metadata'] ?? null,
'words' => $data['words']
]); ]);
exit;
}
echo json_encode([ } catch (Throwable $e) {
'metadata' => $data['metadata'] ?? null,
'words' => $data['words'] http_response_code(500);
]);
echo json_encode([
'error' => 'server_exception',
'message' => $e->getMessage()
]);
}