Adding search files functionality in Paperless from Nextcloud#49
Adding search files functionality in Paperless from Nextcloud#49Jin-Di wants to merge 23 commits intonextcloud:mainfrom
Conversation
e8cab4f to
6ad6b89
Compare
|
Thanks for your PR, I will take a look next week! |
provokateurin
left a comment
There was a problem hiding this comment.
The indentation is very inconsistent, please fix by running composer cs:fix
lib/Service/NetworkService.php
Outdated
There was a problem hiding this comment.
This looks very much like you copied it from another integration app without the appropriate copyright.
I'm not a fan of this code, but you have to at least add the copyright of the original authors.
lib/Controller/SearchController.php
Outdated
There was a problem hiding this comment.
This makes no sense, there is no route to this controller method and the frontend never tries to call any API
There was a problem hiding this comment.
Changing the frontend dependencies is not necessary at all.
You're also adding some new ones that are never used.
lib/Service/ApiService.php
Outdated
| public function request(string $userId, string $endPoint, array $params = [], string $method = 'GET', | ||
| bool $jsonResponse = true, bool $paperlessApiRequest = true) { | ||
| return $this->networkService->request($userId, $endPoint, $params, $method, $jsonResponse, $paperlessApiRequest); | ||
| } |
There was a problem hiding this comment.
Please don't do this and add the NetworkService.
You can just implement the call directly like it is done in sendFile().
lib/Service/ApiService.php
Outdated
| // Sort by most recent | ||
| // $messages = array_reverse($result['document'] ?? []); | ||
| return array_slice($result, $offset, $limit); |
There was a problem hiding this comment.
This endpoint seems to use pagination, so that needs to be implemented for the offset and limit to work properly.
lib/Search/SearchProvider.php
Outdated
| $formattedResults = array_map(function (array $entry) use ($url): SearchResultEntry { | ||
| $finalThumbnailUrl = $this->getThumbnailUrl($entry); | ||
| $title = $entry['title'] ?? 'Untitled'; | ||
| $context = $entry['__search_hit__']['highlights'] ?? ''; |
There was a problem hiding this comment.
I think this can return HTML (see https://docs.paperless-ngx.com/api/#searching-for-documents), so the result will be quite ugly because it will not be rendered.
There was a problem hiding this comment.
May I know which one does you mean?
There was a problem hiding this comment.
The strip_tags function at the return will remove the HTML tag, so it won't return any raw HTML.
There was a problem hiding this comment.
Ah my bad I didn't see that. Can you already call it when initializing the variable? I feel like it is harder to miss then.
lib/Search/SearchProvider.php
Outdated
| $title, | ||
| strip_tags($context), | ||
| $link, | ||
| $finalThumbnailUrl === '' ? 'icon-paperless-search-fallback' : '', |
There was a problem hiding this comment.
This fallback icon doesn't exist
There was a problem hiding this comment.
I think I mislook on this one, will remove it since I don't think thumbnail is required.
lib/Search/SearchProvider.php
Outdated
| * @return string | ||
| */ | ||
| protected function getThumbnailUrl(array $entry): string { | ||
| return ''; |
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
…original authors Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
…in sendFile(). Remove the NetworkService.php Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
a9ad6b1 to
49254f7
Compare
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
|
I have fixed issues above, please check @provokateurin. |
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
provokateurin
left a comment
There was a problem hiding this comment.
Have you tried running this code against a paperless-ngx instance? I doubt that currently works at all because it doesn't even parse the output correctly.
lib/Service/ApiService.php
Outdated
| 'headers' => array_merge( | ||
| $this->getAuthorizationHeaders(), | ||
| [ | ||
| 'Content-Type' => 'application/json', |
There was a problem hiding this comment.
| 'Content-Type' => 'application/json', |
You're not actually sending any data in the body, so this is not correct
lib/Service/ApiService.php
Outdated
| $paperlessURL = rtrim($this->config->url, '/') . '/api/documents/?' . http_build_query($arguments); | ||
| $result = $this->client->get($paperlessURL, |
There was a problem hiding this comment.
| $paperlessURL = rtrim($this->config->url, '/') . '/api/documents/?' . http_build_query($arguments); | |
| $result = $this->client->get($paperlessURL, | |
| $result = $this->client->get($this->config->url . '/api/documents/?' . http_build_query($arguments), |
Just do it like in the sendFile() method. Trimming is not necessary
There was a problem hiding this comment.
Just my two cents here. I think users usually input the URL including a trailing slash, especially when they copy-paste them from documentation or browser address bars. This was also one of the issues I faced when testing the code, as I didn't realize that I have a trailing slash behind the URL entered. So, this approach will reduce the chances of errors caused by duplicate slashes or incorrect URLs. Let me know your final decision on which approach you'd like to go with.
lib/Service/ApiService.php
Outdated
| if (isset($json_body['error'])) { | ||
| return (array)$json_body; | ||
| } |
There was a problem hiding this comment.
I don't see anything like this in the API docs. Please check in the source code of paperless-ngx how an error response will look like and adjust it here.
There was a problem hiding this comment.
I don't find any explicit error key in the API responses. However, I noticed that the API returns an HTML response when the URL is incorrect.
So, I’m checking for an HTML key in the JSON. Let me know if you have different ideas.
| * This file contains code derived from Nextcloud - Zulip | ||
| * @copyright Copyright (c) 2024, Edward Ly | ||
| * | ||
| * @author Edward Ly <contact@edward.ly> |
There was a problem hiding this comment.
Also add yourself to this authors list
lib/Controller/SearchController.php
Outdated
There was a problem hiding this comment.
This Controller is still not used at all, please remove it
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com> Signed-off-by: Jin-Di <jdgoh334@gmail.com>
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com> Signed-off-by: Jin-Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
…m:Jin-Di/integration_paperless into feature/add-search-function-for-nextcloud
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com> Signed-off-by: Jin-Di <jdgoh334@gmail.com>
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com> Signed-off-by: Jin-Di <jdgoh334@gmail.com>
Modify author list
…m:Jin-Di/integration_paperless into feature/add-search-function-for-nextcloud
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
|
I think the pagination is fixed, please check @provokateurin. I believe the Unified Search result is limited to 25 by default. It is hardcoded in the application, the way I exceed it is modifying the code in |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
|
What is this PR waiting for? |

#10. Adding search files functionality in Paperless from Nextcloud. The function is similar from Zulip's integration.