From bdc5152d486ca75372c271f94623b248bc127800 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sun, 2 Dec 2018 23:24:58 +0100 Subject: namespacing: \Shaarli\History Signed-off-by: VirtualTam --- application/api/controllers/ApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/api') diff --git a/application/api/controllers/ApiController.php b/application/api/controllers/ApiController.php index 9edefcf6..47e0e178 100644 --- a/application/api/controllers/ApiController.php +++ b/application/api/controllers/ApiController.php @@ -30,7 +30,7 @@ abstract class ApiController protected $linkDb; /** - * @var \History + * @var \Shaarli\History */ protected $history; -- cgit v1.2.3 From 00af48d9d20af1ce51c8ad42fe354fafc9ceb8a3 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Mon, 3 Dec 2018 00:16:10 +0100 Subject: namespacing: \Shaarli\Http\Base64Url Signed-off-by: VirtualTam --- application/api/ApiUtils.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'application/api') diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index fc5ecaf1..e51b73e1 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php @@ -1,7 +1,7 @@ Date: Mon, 3 Dec 2018 01:10:39 +0100 Subject: namespacing: \Shaarli\Bookmark\LinkDB Signed-off-by: VirtualTam --- application/api/ApiMiddleware.php | 2 +- application/api/controllers/ApiController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'application/api') diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php index 66eac133..a2101f29 100644 --- a/application/api/ApiMiddleware.php +++ b/application/api/ApiMiddleware.php @@ -127,7 +127,7 @@ class ApiMiddleware */ protected function setLinkDb($conf) { - $linkDb = new \LinkDB( + $linkDb = new \Shaarli\Bookmark\LinkDB( $conf->get('resource.datastore'), true, $conf->get('privacy.hide_public_links'), diff --git a/application/api/controllers/ApiController.php b/application/api/controllers/ApiController.php index 47e0e178..cab97dc4 100644 --- a/application/api/controllers/ApiController.php +++ b/application/api/controllers/ApiController.php @@ -25,7 +25,7 @@ abstract class ApiController protected $conf; /** - * @var \LinkDB + * @var \Shaarli\Bookmark\LinkDB */ protected $linkDb; -- cgit v1.2.3 From dea72c711ff740b3b829d238fcf85648465143a0 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 12 Jan 2019 23:55:38 +0100 Subject: Optimize and cleanup imports Signed-off-by: VirtualTam --- application/api/ApiMiddleware.php | 3 +- application/api/ApiUtils.php | 2 +- application/api/controllers/ApiController.php | 7 ++- application/api/controllers/History.php | 69 ---------------------- application/api/controllers/HistoryController.php | 69 ++++++++++++++++++++++ application/api/controllers/Tags.php | 1 - .../api/exceptions/ApiLinkNotFoundException.php | 2 - .../api/exceptions/ApiTagNotFoundException.php | 2 - 8 files changed, 75 insertions(+), 80 deletions(-) delete mode 100644 application/api/controllers/History.php create mode 100644 application/api/controllers/HistoryController.php (limited to 'application/api') diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php index a2101f29..5ffb8c6d 100644 --- a/application/api/ApiMiddleware.php +++ b/application/api/ApiMiddleware.php @@ -1,9 +1,8 @@ history->getHistory(); - - // Return history operations from the {offset}th, starting from {since}. - $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); - $offset = $request->getParam('offset'); - if (empty($offset)) { - $offset = 0; - } elseif (ctype_digit($offset)) { - $offset = (int) $offset; - } else { - throw new ApiBadParametersException('Invalid offset'); - } - - // limit parameter is either a number of links or 'all' for everything. - $limit = $request->getParam('limit'); - if (empty($limit)) { - $limit = count($history); - } elseif (ctype_digit($limit)) { - $limit = (int) $limit; - } else { - throw new ApiBadParametersException('Invalid limit'); - } - - $out = []; - $i = 0; - foreach ($history as $entry) { - if ((! empty($since) && $entry['datetime'] <= $since) || count($out) >= $limit) { - break; - } - if (++$i > $offset) { - $out[$i] = $entry; - $out[$i]['datetime'] = $out[$i]['datetime']->format(\DateTime::ATOM); - } - } - $out = array_values($out); - - return $response->withJson($out, 200, $this->jsonStyle); - } -} diff --git a/application/api/controllers/HistoryController.php b/application/api/controllers/HistoryController.php new file mode 100644 index 00000000..9afcfa26 --- /dev/null +++ b/application/api/controllers/HistoryController.php @@ -0,0 +1,69 @@ +history->getHistory(); + + // Return history operations from the {offset}th, starting from {since}. + $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); + $offset = $request->getParam('offset'); + if (empty($offset)) { + $offset = 0; + } elseif (ctype_digit($offset)) { + $offset = (int) $offset; + } else { + throw new ApiBadParametersException('Invalid offset'); + } + + // limit parameter is either a number of links or 'all' for everything. + $limit = $request->getParam('limit'); + if (empty($limit)) { + $limit = count($history); + } elseif (ctype_digit($limit)) { + $limit = (int) $limit; + } else { + throw new ApiBadParametersException('Invalid limit'); + } + + $out = []; + $i = 0; + foreach ($history as $entry) { + if ((! empty($since) && $entry['datetime'] <= $since) || count($out) >= $limit) { + break; + } + if (++$i > $offset) { + $out[$i] = $entry; + $out[$i]['datetime'] = $out[$i]['datetime']->format(\DateTime::ATOM); + } + } + $out = array_values($out); + + return $response->withJson($out, 200, $this->jsonStyle); + } +} diff --git a/application/api/controllers/Tags.php b/application/api/controllers/Tags.php index 6dd78750..82f3ef74 100644 --- a/application/api/controllers/Tags.php +++ b/application/api/controllers/Tags.php @@ -4,7 +4,6 @@ namespace Shaarli\Api\Controllers; use Shaarli\Api\ApiUtils; use Shaarli\Api\Exceptions\ApiBadParametersException; -use Shaarli\Api\Exceptions\ApiLinkNotFoundException; use Shaarli\Api\Exceptions\ApiTagNotFoundException; use Slim\Http\Request; use Slim\Http\Response; diff --git a/application/api/exceptions/ApiLinkNotFoundException.php b/application/api/exceptions/ApiLinkNotFoundException.php index c727f4f0..7c2bb56e 100644 --- a/application/api/exceptions/ApiLinkNotFoundException.php +++ b/application/api/exceptions/ApiLinkNotFoundException.php @@ -2,8 +2,6 @@ namespace Shaarli\Api\Exceptions; -use Slim\Http\Response; - /** * Class ApiLinkNotFoundException * diff --git a/application/api/exceptions/ApiTagNotFoundException.php b/application/api/exceptions/ApiTagNotFoundException.php index eee152fe..66ace8bf 100644 --- a/application/api/exceptions/ApiTagNotFoundException.php +++ b/application/api/exceptions/ApiTagNotFoundException.php @@ -2,8 +2,6 @@ namespace Shaarli\Api\Exceptions; -use Slim\Http\Response; - /** * Class ApiTagNotFoundException * -- cgit v1.2.3 From 520d29578c57e476ece3bdd20c286d196b7b61b4 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 9 Feb 2019 13:52:12 +0100 Subject: Remove the redirector setting Fixes #1239 --- application/api/ApiMiddleware.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'application/api') diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php index 5ffb8c6d..2d55bda6 100644 --- a/application/api/ApiMiddleware.php +++ b/application/api/ApiMiddleware.php @@ -129,9 +129,7 @@ class ApiMiddleware $linkDb = new \Shaarli\Bookmark\LinkDB( $conf->get('resource.datastore'), true, - $conf->get('privacy.hide_public_links'), - $conf->get('redirector.url'), - $conf->get('redirector.encode_url') + $conf->get('privacy.hide_public_links') ); $this->container['db'] = $linkDb; } -- cgit v1.2.3 From a8e7da01146455f13ef06b151a7dafedd3acf769 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 9 Feb 2019 14:13:08 +0100 Subject: Do not try to retrieve thumbnails for internal link Also adds a helper function to determine if a link is a note and apply it across multiple files. --- application/api/ApiUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/api') diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index 1824b5d0..1e3ac02e 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php @@ -59,7 +59,7 @@ class ApiUtils { $out['id'] = $link['id']; // Not an internal link - if ($link['url'][0] != '?') { + if (! is_note($link['url'])) { $out['url'] = $link['url']; } else { $out['url'] = $indexUrl . $link['url']; -- cgit v1.2.3