chore(*): remove duplicate cache rule + cleanup cache headers; cleanup + formatting
This commit is contained in:
parent
425fed6ff6
commit
0e565970a5
42 changed files with 223 additions and 217 deletions
|
@ -12,6 +12,7 @@ class BookImportHandler extends ApiHandler
|
|||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->ensureCliAccess();
|
||||
$this->bookImportToken = $_ENV["BOOK_IMPORT_TOKEN"] ?? getenv("BOOK_IMPORT_TOKEN");
|
||||
}
|
||||
|
@ -20,20 +21,13 @@ class BookImportHandler extends ApiHandler
|
|||
{
|
||||
$input = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
if (!$input) {
|
||||
$this->sendErrorResponse("Invalid or missing JSON body", 400);
|
||||
}
|
||||
if (!$input) $this->sendErrorResponse("Invalid or missing JSON body", 400);
|
||||
|
||||
$providedToken = $input["token"] ?? null;
|
||||
$isbn = $input["isbn"] ?? null;
|
||||
|
||||
if ($providedToken !== $this->bookImportToken) {
|
||||
$this->sendErrorResponse("Unauthorized access", 401);
|
||||
}
|
||||
|
||||
if (!$isbn) {
|
||||
$this->sendErrorResponse("isbn parameter is required", 400);
|
||||
}
|
||||
if ($providedToken !== $this->bookImportToken) $this->sendErrorResponse("Unauthorized access", 401);
|
||||
if (!$isbn) $this->sendErrorResponse("isbn parameter is required", 400);
|
||||
|
||||
try {
|
||||
$bookData = $this->fetchBookData($isbn);
|
||||
|
@ -59,9 +53,7 @@ class BookImportHandler extends ApiHandler
|
|||
$data = json_decode($response->getBody(), true);
|
||||
$bookKey = "ISBN:{$isbn}";
|
||||
|
||||
if (empty($data[$bookKey])) {
|
||||
throw new \Exception("Book data not found for ISBN: {$isbn}");
|
||||
}
|
||||
if (empty($data[$bookKey])) throw new \Exception("Book data not found for ISBN: {$isbn}");
|
||||
|
||||
return $data[$bookKey];
|
||||
}
|
||||
|
@ -75,14 +67,11 @@ class BookImportHandler extends ApiHandler
|
|||
$author = $bookData["authors"][0]["name"] ?? null;
|
||||
$description = $bookData["description"] ?? ($bookData["notes"] ?? "");
|
||||
|
||||
if (!$isbn || !$title || !$author) {
|
||||
throw new \Exception("Missing essential book data (title, author, or ISBN).");
|
||||
}
|
||||
if (!$isbn || !$title || !$author) throw new \Exception("Missing essential book data (title, author, or ISBN).");
|
||||
|
||||
$existingBook = $this->getBookByISBN($isbn);
|
||||
if ($existingBook) {
|
||||
throw new \Exception("Book with ISBN {$isbn} already exists.");
|
||||
}
|
||||
|
||||
if ($existingBook) throw new \Exception("Book with ISBN {$isbn} already exists.");
|
||||
|
||||
$bookPayload = [
|
||||
"isbn" => $isbn,
|
||||
|
@ -99,6 +88,7 @@ class BookImportHandler extends ApiHandler
|
|||
private function getBookByISBN(string $isbn): ?array
|
||||
{
|
||||
$response = $this->fetchFromApi("books", "isbn=eq." . urlencode($isbn));
|
||||
|
||||
return $response[0] ?? null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue