Skip to content

Commit

Permalink
Update inc/types/epub.inc
Browse files Browse the repository at this point in the history
  • Loading branch information
dismorfo committed May 14, 2024
1 parent eaabd6d commit e9e8780
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions inc/types/epub.inc
Original file line number Diff line number Diff line change
Expand Up @@ -283,26 +283,32 @@ function dlts_viewer_api_epubs_publisher_list($version, $publisher) {

function dlts_viewer_api_epubs_publisher_create($_version, $publisher, $identifier) {

$identifier = filter_xss($identifier);

$results = db_query('SELECT * FROM dlts_viewer_epubs WHERE identifier = :identifier AND publisher = :publisher', [ ':identifier' => $identifier, ':publisher' => $publisher->code ]);

$record = $results->fetchObject();

if ($record) {
return [
'error' => 'found',
'status' => 'found',
'message' => "ePub $record->label (ISBN13: $identifier) already published.",
'data' => dlts_viewer_epubs_metadata_v0(
dlts_viewer_supafolio_book($identifier, false)
)
];
}
else {
$record = dlts_viewer_supafolio_book($identifier, true);
if (isset($record->status) && $record->status === 'error') {
return [
'status' => 'error',
'error' => $record->status,
'message' => "Supafolio API - " . $record->data['errors'][0]['message'],
];
}
else {
if ($identifier === $record->isbn13) {
if ($identifier == $record->isbn13) {
$metadata = dlts_viewer_epubs_metadata_v1($record);
db_insert('dlts_viewer_epubs')
->fields([
Expand All @@ -314,7 +320,11 @@ function dlts_viewer_api_epubs_publisher_create($_version, $publisher, $identifi
'data' => '',
])
->execute();
return $metadata;
return [
'status' => 'created',
'message' => "Supafolio API - ePub $metadata[title] (ISBN13: $identifier) created.",
'data' => $metadata,
];
}
else {
return [
Expand Down

0 comments on commit e9e8780

Please sign in to comment.