diff options
-rw-r--r-- | appinfo/app.php | 2 | ||||
-rw-r--r-- | appinfo/autoload.php | 39 | ||||
-rw-r--r-- | composer.lock | 8 | ||||
-rw-r--r-- | js/fulltextsearch.v1.api.js | 6 | ||||
-rw-r--r-- | js/fulltextsearch.v1.result.js | 2 | ||||
-rw-r--r-- | lib/Controller/ApiController.php | 51 |
6 files changed, 66 insertions, 42 deletions
diff --git a/appinfo/app.php b/appinfo/app.php index 20c5b72..d5c699d 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -34,6 +34,8 @@ namespace OCA\FullTextSearch\AppInfo; use OCP\AppFramework\QueryException; +require_once __DIR__ . '/autoload.php'; + try { $app = new Application(); $app->registerServices(); diff --git a/appinfo/autoload.php b/appinfo/autoload.php new file mode 100644 index 0000000..094b758 --- /dev/null +++ b/appinfo/autoload.php @@ -0,0 +1,39 @@ +<?php +declare(strict_types=1); + + +/** + * FullTextSearch - Full text search framework for Nextcloud + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2018 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\FullTextSearch\AppInfo; + + +$composerDir = __DIR__ . '/../vendor/'; + +if (is_dir($composerDir) && file_exists($composerDir . 'autoload.php')) { + require_once $composerDir . 'autoload.php'; +} + diff --git a/composer.lock b/composer.lock index f0ef7e2..3517998 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/daita/my-small-php-tools.git", - "reference": "e0d7d135d75839419cc9f46b6e0543720234a791" + "reference": "6c2f1f42315ca9f92432f109e2276229eb0da547" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/e0d7d135d75839419cc9f46b6e0543720234a791", - "reference": "e0d7d135d75839419cc9f46b6e0543720234a791", + "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/6c2f1f42315ca9f92432f109e2276229eb0da547", + "reference": "6c2f1f42315ca9f92432f109e2276229eb0da547", "shasum": "" }, "require": { @@ -40,7 +40,7 @@ } ], "description": "My small PHP Tools", - "time": "2018-10-12T13:48:31+00:00" + "time": "2018-10-31T09:39:20+00:00" } ], "packages-dev": [], diff --git a/js/fulltextsearch.v1.api.js b/js/fulltextsearch.v1.api.js index d37fb26..1e64328 100644 --- a/js/fulltextsearch.v1.api.js +++ b/js/fulltextsearch.v1.api.js @@ -49,9 +49,9 @@ var api = { request: JSON.stringify(request) } }).done(function (res) { - if (_.has(res, 'error')) { + if (res.status === -1) { result.displayError(res); - nav.onError(res.error); + nav.onError(res.message); api.onCallback(callbackError, res); return; } @@ -61,7 +61,7 @@ var api = { api.onCallback(callback, res); }).fail(function () { if (!api.onCallback(callbackError, res)) { - nav.onError(res.error); + nav.onError(res.message); } }); }, diff --git a/js/fulltextsearch.v1.result.js b/js/fulltextsearch.v1.result.js index a0bbfed..f724dd4 100644 --- a/js/fulltextsearch.v1.result.js +++ b/js/fulltextsearch.v1.result.js @@ -53,7 +53,7 @@ var result = { displayError: function (res) { - box_elements.searchError.text(res.error).show(); + box_elements.searchError.text(res.message).show(); }, diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 1c3b0e4..f973ea9 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -1,4 +1,7 @@ <?php +declare(strict_types=1); + + /** * FullTextSearch - Full text search framework for Nextcloud * @@ -24,8 +27,11 @@ * */ + namespace OCA\FullTextSearch\Controller; + +use daita\MySmallPhpTools\Traits\TNCDataResponse; use Exception; use OCA\FullTextSearch\AppInfo\Application; use OCA\FullTextSearch\Model\SearchRequest; @@ -33,12 +39,16 @@ use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\SearchService; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; + class ApiController extends Controller { + + use TNCDataResponse; + + /** @var SearchService */ private $searchService; @@ -76,7 +86,7 @@ class ApiController extends Controller { * * @return DataResponse */ - public function search($request) { + public function search(string $request): DataResponse { return $this->searchDocuments(SearchRequest::fromJSON($request)); } @@ -90,7 +100,7 @@ class ApiController extends Controller { * * @return DataResponse */ - public function searchFromRemote($request) { + public function searchFromRemote(string $request): DataResponse { return $this->searchDocuments(SearchRequest::fromJSON($request)); } @@ -100,54 +110,27 @@ class ApiController extends Controller { * * @return DataResponse */ - private function searchDocuments(SearchRequest $request) { + private function searchDocuments(SearchRequest $request): DataResponse { try { $result = $this->searchService->search('', $request); return $this->success( + $result, [ 'request' => $request, - 'result' => $result, 'version' => $this->configService->getAppValue('installed_version') ] ); } catch (Exception $e) { return $this->fail( + $e->getMessage(), [ 'request' => $request, - 'error' => $e->getMessage(), 'version' => $this->configService->getAppValue('installed_version') ] ); } } - - /** - * @param $data - * - * @return DataResponse - */ - protected function fail($data) { - $this->miscService->log(json_encode($data)); - - return new DataResponse( - array_merge($data, array('status' => 0)), - Http::STATUS_NON_AUTHORATIVE_INFORMATION - ); - } - - - /** - * @param $data - * - * @return DataResponse - */ - protected function success($data) { - return new DataResponse( - array_merge($data, array('status' => 1)), - Http::STATUS_CREATED - ); - } - } + |