-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Backend for reference metadata fetching #33494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
650b809
de3e541
9d9c7f4
31be855
f58218d
0ce0d37
eaef568
68d0038
bee8fd2
a392235
80f6a58
1ab6698
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * @copyright Copyright (c) 2022 Julius Härtl <[email protected]> | ||
| * | ||
| * @author Julius Härtl <[email protected]> | ||
| * | ||
| * @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 OC\Core\Controller; | ||
|
|
||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\Collaboration\Reference\IReferenceManager; | ||
| use OCP\IRequest; | ||
|
|
||
| class ReferenceApiController extends \OCP\AppFramework\OCSController { | ||
| private IReferenceManager $referenceManager; | ||
|
|
||
| public function __construct(string $appName, IRequest $request, IReferenceManager $referenceManager) { | ||
| parent::__construct($appName, $request); | ||
| $this->referenceManager = $referenceManager; | ||
| } | ||
|
|
||
| /** | ||
| * @NoAdminRequired | ||
| */ | ||
| public function extract(string $text, bool $resolve = false, int $limit = 1): DataResponse { | ||
| $references = $this->referenceManager->extractReferences($text); | ||
|
|
||
| $result = []; | ||
| $index = 0; | ||
| foreach ($references as $reference) { | ||
| if ($index++ >= $limit) { | ||
| break; | ||
| } | ||
|
|
||
| $result[$reference] = $resolve ? $this->referenceManager->resolveReference($reference) : null; | ||
| } | ||
|
|
||
| return new DataResponse([ | ||
| 'references' => $result | ||
| ]); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @NoAdminRequired | ||
| * | ||
| * @param string[] $references | ||
| */ | ||
| public function resolve(array $references, int $limit = 1): DataResponse { | ||
| $result = []; | ||
| $index = 0; | ||
| foreach ($references as $reference) { | ||
| if ($index++ >= $limit) { | ||
| break; | ||
| } | ||
|
|
||
| $result[$reference] = $this->referenceManager->resolveReference($reference); | ||
| } | ||
|
|
||
| return new DataResponse([ | ||
| 'references' => array_filter($result) | ||
| ]); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * @copyright Copyright (c) 2022 Julius Härtl <[email protected]> | ||
| * | ||
| * @author Julius Härtl <[email protected]> | ||
| * | ||
| * @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 OC\Core\Controller; | ||
|
|
||
| use OCP\AppFramework\Http\Response; | ||
| use OCP\Collaboration\Reference\IReferenceManager; | ||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\DataDownloadResponse; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\Files\AppData\IAppDataFactory; | ||
| use OCP\Files\NotFoundException; | ||
| use OCP\Files\NotPermittedException; | ||
| use OCP\IRequest; | ||
|
|
||
| class ReferenceController extends Controller { | ||
| private IReferenceManager $referenceManager; | ||
| private IAppDataFactory $appDataFactory; | ||
|
|
||
| public function __construct(string $appName, IRequest $request, IReferenceManager $referenceManager, IAppDataFactory $appDataFactory) { | ||
| parent::__construct($appName, $request); | ||
| $this->referenceManager = $referenceManager; | ||
| $this->appDataFactory = $appDataFactory; | ||
| } | ||
|
|
||
| /** | ||
| * @PublicPage | ||
| * @NoCSRFRequired | ||
| */ | ||
| public function preview(string $referenceId): Response { | ||
| $reference = $this->referenceManager->getReferenceByCacheKey($referenceId); | ||
juliusknorr marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get a hit here locally so I don't have any previews. Is there something else needed to configure? Is a Redis required? Or is the method not loading the providers or something?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, would require redis/apcu in its current state. I'd need to think how we can make this work without, as currently we have no reference from the hashed reference that is used for the preview to the original one. |
||
| if ($reference === null) { | ||
| return new DataResponse('', Http::STATUS_NOT_FOUND); | ||
| } | ||
|
|
||
| try { | ||
| $appData = $this->appDataFactory->get('core'); | ||
|
||
| $folder = $appData->getFolder('opengraph'); | ||
| $file = $folder->getFile($referenceId); | ||
| return new DataDownloadResponse($file->getContent(), $referenceId, $reference->getImageContentType()); | ||
| } catch (NotFoundException|NotPermittedException $e) { | ||
| return new DataResponse('', Http::STATUS_NOT_FOUND); | ||
| } | ||
| } | ||
| } | ||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.