forked from mikespub-org/seblucas-cops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestapi.php
45 lines (36 loc) · 1.14 KB
/
restapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* COPS (Calibre OPDS PHP Server) REST API endpoint
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <[email protected]>
* @author mikespub
*
*/
use SebLucas\Cops\Input\Config;
use SebLucas\Cops\Input\Request;
use SebLucas\Cops\Output\Format;
use SebLucas\Cops\Output\RestApi;
require_once __DIR__ . '/config.php';
// override splitting authors and books by first letter here?
Config::set('author_split_first_letter', '0');
Config::set('titles_split_first_letter', '0');
//Config::set('titles_split_publication_year', '0');
// try out route urls
Config::set('use_route_urls', true);
$request = new Request();
$path = $request->path();
if (empty($path)) {
header('Content-Type:text/html;charset=utf-8');
$data = ['link' => $request->script() . '/openapi'];
$template = __DIR__ . '/templates/restapi.html';
echo Format::template($data, $template);
return;
}
$apiHandler = new RestApi($request);
header('Content-Type:application/json;charset=utf-8');
try {
echo $apiHandler->getOutput();
} catch (Exception $e) {
echo json_encode(["Exception" => $e->getMessage()]);
}