66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
<?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';
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
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 (!is_array($data) || !isset($data['words'])) {
|
|
echo json_encode([
|
|
'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()
|
|
]);
|
|
} |