43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
require_once '../../includes/config.php';
|
|
require_once '../../includes/auth.php';
|
|
require_once '../../includes/stories.php';
|
|
|
|
// Vérification de l'authentification
|
|
if (!Auth::check()) {
|
|
http_response_code(401);
|
|
exit(json_encode(['error' => 'Non autorisé']));
|
|
}
|
|
|
|
$storyId = $_GET['storyId'] ?? '';
|
|
$chapterId = $_GET['chapterId'] ?? '';
|
|
|
|
if (!$storyId || !$chapterId) {
|
|
http_response_code(400);
|
|
exit(json_encode(['error' => 'Paramètres manquants']));
|
|
}
|
|
|
|
try {
|
|
$story = Stories::get($storyId);
|
|
if (!$story) {
|
|
throw new Exception('Roman non trouvé');
|
|
}
|
|
|
|
$chapter = null;
|
|
foreach ($story['chapters'] as $ch) {
|
|
if ($ch['id'] === $chapterId) {
|
|
$chapter = $ch;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$chapter) {
|
|
throw new Exception('Chapitre non trouvé');
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode($chapter);
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
} |