diff options
author | yude <yudesleepy@gmail.com> | 2021-01-04 18:51:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 18:51:10 +0900 |
commit | e6754f2154a79abd8e5e64bd923f6984aa9ad44b (patch) | |
tree | f074119530bb59ef155938ea367f719f1e4b70f1 /application/api/controllers | |
parent | 5256b4287021342a9f8868967b2a77e481314331 (diff) | |
parent | ed4ee8f0297941ac83300389b7de6a293312d20e (diff) | |
download | Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.gz Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.zst Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.zip |
Merge pull request #2 from shaarli/master
Merge fork source
Diffstat (limited to 'application/api/controllers')
-rw-r--r-- | application/api/controllers/HistoryController.php | 1 | ||||
-rw-r--r-- | application/api/controllers/Info.php | 4 | ||||
-rw-r--r-- | application/api/controllers/Links.php | 20 |
3 files changed, 17 insertions, 8 deletions
diff --git a/application/api/controllers/HistoryController.php b/application/api/controllers/HistoryController.php index 505647a9..d83a3a25 100644 --- a/application/api/controllers/HistoryController.php +++ b/application/api/controllers/HistoryController.php | |||
@@ -1,6 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | |||
4 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
5 | 4 | ||
6 | use Shaarli\Api\Exceptions\ApiBadParametersException; | 5 | use Shaarli\Api\Exceptions\ApiBadParametersException; |
diff --git a/application/api/controllers/Info.php b/application/api/controllers/Info.php index 12f6b2f0..ae7db93e 100644 --- a/application/api/controllers/Info.php +++ b/application/api/controllers/Info.php | |||
@@ -29,13 +29,13 @@ class Info extends ApiController | |||
29 | $info = [ | 29 | $info = [ |
30 | 'global_counter' => $this->bookmarkService->count(), | 30 | 'global_counter' => $this->bookmarkService->count(), |
31 | 'private_counter' => $this->bookmarkService->count(BookmarkFilter::$PRIVATE), | 31 | 'private_counter' => $this->bookmarkService->count(BookmarkFilter::$PRIVATE), |
32 | 'settings' => array( | 32 | 'settings' => [ |
33 | 'title' => $this->conf->get('general.title', 'Shaarli'), | 33 | 'title' => $this->conf->get('general.title', 'Shaarli'), |
34 | 'header_link' => $this->conf->get('general.header_link', '?'), | 34 | 'header_link' => $this->conf->get('general.header_link', '?'), |
35 | 'timezone' => $this->conf->get('general.timezone', 'UTC'), | 35 | 'timezone' => $this->conf->get('general.timezone', 'UTC'), |
36 | 'enabled_plugins' => $this->conf->get('general.enabled_plugins', []), | 36 | 'enabled_plugins' => $this->conf->get('general.enabled_plugins', []), |
37 | 'default_private_links' => $this->conf->get('privacy.default_private_links', false), | 37 | 'default_private_links' => $this->conf->get('privacy.default_private_links', false), |
38 | ), | 38 | ], |
39 | ]; | 39 | ]; |
40 | 40 | ||
41 | return $response->withJson($info, 200, $this->jsonStyle); | 41 | return $response->withJson($info, 200, $this->jsonStyle); |
diff --git a/application/api/controllers/Links.php b/application/api/controllers/Links.php index 73a1b84e..b83b2260 100644 --- a/application/api/controllers/Links.php +++ b/application/api/controllers/Links.php | |||
@@ -117,9 +117,14 @@ class Links extends ApiController | |||
117 | public function postLink($request, $response) | 117 | public function postLink($request, $response) |
118 | { | 118 | { |
119 | $data = (array) ($request->getParsedBody() ?? []); | 119 | $data = (array) ($request->getParsedBody() ?? []); |
120 | $bookmark = ApiUtils::buildBookmarkFromRequest($data, $this->conf->get('privacy.default_private_links')); | 120 | $bookmark = ApiUtils::buildBookmarkFromRequest( |
121 | $data, | ||
122 | $this->conf->get('privacy.default_private_links'), | ||
123 | $this->conf->get('general.tags_separator', ' ') | ||
124 | ); | ||
121 | // duplicate by URL, return 409 Conflict | 125 | // duplicate by URL, return 409 Conflict |
122 | if (! empty($bookmark->getUrl()) | 126 | if ( |
127 | ! empty($bookmark->getUrl()) | ||
123 | && ! empty($dup = $this->bookmarkService->findByUrl($bookmark->getUrl())) | 128 | && ! empty($dup = $this->bookmarkService->findByUrl($bookmark->getUrl())) |
124 | ) { | 129 | ) { |
125 | return $response->withJson( | 130 | return $response->withJson( |
@@ -131,7 +136,7 @@ class Links extends ApiController | |||
131 | 136 | ||
132 | $this->bookmarkService->add($bookmark); | 137 | $this->bookmarkService->add($bookmark); |
133 | $out = ApiUtils::formatLink($bookmark, index_url($this->ci['environment'])); | 138 | $out = ApiUtils::formatLink($bookmark, index_url($this->ci['environment'])); |
134 | $redirect = $this->ci->router->relativePathFor('getLink', ['id' => $bookmark->getId()]); | 139 | $redirect = $this->ci->router->pathFor('getLink', ['id' => $bookmark->getId()]); |
135 | return $response->withAddedHeader('Location', $redirect) | 140 | return $response->withAddedHeader('Location', $redirect) |
136 | ->withJson($out, 201, $this->jsonStyle); | 141 | ->withJson($out, 201, $this->jsonStyle); |
137 | } | 142 | } |
@@ -157,9 +162,14 @@ class Links extends ApiController | |||
157 | $index = index_url($this->ci['environment']); | 162 | $index = index_url($this->ci['environment']); |
158 | $data = $request->getParsedBody(); | 163 | $data = $request->getParsedBody(); |
159 | 164 | ||
160 | $requestBookmark = ApiUtils::buildBookmarkFromRequest($data, $this->conf->get('privacy.default_private_links')); | 165 | $requestBookmark = ApiUtils::buildBookmarkFromRequest( |
166 | $data, | ||
167 | $this->conf->get('privacy.default_private_links'), | ||
168 | $this->conf->get('general.tags_separator', ' ') | ||
169 | ); | ||
161 | // duplicate URL on a different link, return 409 Conflict | 170 | // duplicate URL on a different link, return 409 Conflict |
162 | if (! empty($requestBookmark->getUrl()) | 171 | if ( |
172 | ! empty($requestBookmark->getUrl()) | ||
163 | && ! empty($dup = $this->bookmarkService->findByUrl($requestBookmark->getUrl())) | 173 | && ! empty($dup = $this->bookmarkService->findByUrl($requestBookmark->getUrl())) |
164 | && $dup->getId() != $id | 174 | && $dup->getId() != $id |
165 | ) { | 175 | ) { |