-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
feat(settings): add Administration Previews page #63796
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
Open
rayvincent2
wants to merge
16
commits into
nextcloud:master
Choose a base branch
from
rayvincent2:feat/63795/previews-admin-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f82ea00
feat(preview): honor MIME priority, cache headers, and record failures
rayvincent2 b764d61
feat(settings): add Previews administration page
rayvincent2 714478a
feat(settings): expose remaining preview settings with detection
rayvincent2 d32b86b
feat(settings): show inactive preview settings with unlock states
rayvincent2 f601416
feat(settings): treat enable previews as a page-level master switch
rayvincent2 e127de1
feat(settings): warn on unsaved Previews changes and duplicate Save
rayvincent2 7167059
feat(settings): drop MIME priority and finish Previews admin UX
rayvincent2 dfd838f
feat(settings): refine Previews admin defaults, filters, and failures
rayvincent2 f6119cb
chore(settings): fix Previews admin lint and Playwright specs
rayvincent2 e6ad2da
feat(settings): lock preview providers that fail requirements
rayvincent2 70c705c
feat(preview): honor enabledPreviewProviders as generation order
rayvincent2 6f5478f
chore(settings): fix Previews admin watch eslint
rayvincent2 725f56b
fix(settings): show Previews icon in admin navigation
rayvincent2 fda7774
test(settings): fix Previews admin Playwright locators
rayvincent2 a109b4b
feat(settings): drop failures UI and align Previews admin with review…
rayvincent2 3933746
fix(settings): wire Previews admin hints to their inputs
rayvincent2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
167 changes: 167 additions & 0 deletions
167
apps/settings/lib/Controller/PreviewAdminController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Settings\Controller; | ||
|
|
||
| use OC\Preview\Failure\PreviewFailureService; | ||
| use OC\Preview\PreviewAdminConfig; | ||
| use OCA\Settings\Settings\Admin\Previews; | ||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Db\DoesNotExistException; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting; | ||
| use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\Files\File; | ||
| use OCP\Files\IRootFolder; | ||
| use OCP\Files\NotFoundException; | ||
| use OCP\Http\Client\IClientService; | ||
| use OCP\IPreview; | ||
| use OCP\IRequest; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| class PreviewAdminController extends Controller { | ||
|
rayvincent2 marked this conversation as resolved.
Outdated
|
||
| public function __construct( | ||
| string $appName, | ||
| IRequest $request, | ||
| private PreviewAdminConfig $previewAdminConfig, | ||
| private PreviewFailureService $failureService, | ||
| private IClientService $clientService, | ||
| private IPreview $preview, | ||
| private IRootFolder $rootFolder, | ||
| private LoggerInterface $logger, | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
| } | ||
|
|
||
| /** | ||
| * @param array $settings | ||
| */ | ||
| #[AuthorizedAdminSetting(settings: Previews::class)] | ||
| #[PasswordConfirmationRequired] | ||
| public function update(array $settings): DataResponse { | ||
| try { | ||
| $this->previewAdminConfig->setSettings($settings); | ||
| } catch (\InvalidArgumentException $e) { | ||
| return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); | ||
| } | ||
|
|
||
| return new DataResponse($this->previewAdminConfig->getSettings()); | ||
| } | ||
|
|
||
| #[AuthorizedAdminSetting(settings: Previews::class)] | ||
| public function testImaginary(?string $url = null, ?string $key = null): DataResponse { | ||
| try { | ||
| $target = $this->previewAdminConfig->validateImaginaryUrl($url ?? ''); | ||
| } catch (\InvalidArgumentException $e) { | ||
| return new DataResponse([ | ||
| 'status' => 'unreachable', | ||
| 'error' => $e->getMessage(), | ||
| ], Http::STATUS_BAD_REQUEST); | ||
| } | ||
|
|
||
| if ($target === '') { | ||
| return new DataResponse([ | ||
| 'status' => 'unconfigured', | ||
| ]); | ||
| } | ||
|
|
||
| try { | ||
| $client = $this->clientService->newClient(); | ||
| $options = [ | ||
| 'timeout' => 3, | ||
| 'connect_timeout' => 3, | ||
| 'nextcloud' => ['allow_local_address' => true], | ||
| ]; | ||
| if (is_string($key) && $key !== '') { | ||
| $options['query'] = ['key' => $key]; | ||
| } | ||
| $response = $client->get($target, $options); | ||
| $statusCode = $response->getStatusCode(); | ||
| $reachable = $statusCode >= 200 && $statusCode < 500; | ||
| return new DataResponse([ | ||
| 'status' => $reachable ? 'reachable' : 'unreachable', | ||
| 'httpCode' => $statusCode, | ||
| ]); | ||
| } catch (\Throwable $e) { | ||
| $this->logger->info('Imaginary connection test failed', [ | ||
| 'exception' => $e, | ||
| ]); | ||
| return new DataResponse([ | ||
| 'status' => 'unreachable', | ||
| 'error' => $e->getMessage(), | ||
| ]); | ||
| } | ||
| } | ||
|
|
||
| #[AuthorizedAdminSetting(settings: Previews::class)] | ||
| public function listFailures(?string $mime = null, ?string $provider = null, ?string $range = null): DataResponse { | ||
| $since = $this->rangeToSince($range); | ||
| return new DataResponse([ | ||
| 'failures' => $this->failureService->listFailures($mime, $provider, $since), | ||
| ]); | ||
| } | ||
|
|
||
| #[AuthorizedAdminSetting(settings: Previews::class)] | ||
| public function retryFailure(int $id): DataResponse { | ||
| try { | ||
| $failure = $this->failureService->get($id); | ||
| } catch (DoesNotExistException) { | ||
| return new DataResponse(['error' => 'Unknown failure'], Http::STATUS_NOT_FOUND); | ||
| } | ||
|
|
||
| $nodes = $this->rootFolder->getById($failure->getFileId()); | ||
| $file = null; | ||
| foreach ($nodes as $node) { | ||
| if ($node instanceof File) { | ||
| $file = $node; | ||
| break; | ||
| } | ||
| } | ||
| if ($file === null) { | ||
| return new DataResponse(['error' => 'File not found'], Http::STATUS_NOT_FOUND); | ||
| } | ||
|
|
||
| try { | ||
| $this->preview->getPreview($file); | ||
| $this->failureService->clearForFile($failure->getFileId()); | ||
| return new DataResponse(['status' => 'ok']); | ||
| } catch (NotFoundException|\InvalidArgumentException $e) { | ||
| return new DataResponse([ | ||
| 'status' => 'failed', | ||
| 'error' => $e->getMessage(), | ||
| ], Http::STATUS_BAD_REQUEST); | ||
| } | ||
| } | ||
|
|
||
| #[AuthorizedAdminSetting(settings: Previews::class)] | ||
| public function deleteFailure(int $id): DataResponse { | ||
| try { | ||
| $this->failureService->delete($id); | ||
| } catch (DoesNotExistException) { | ||
| return new DataResponse(['error' => 'Unknown failure'], Http::STATUS_NOT_FOUND); | ||
| } | ||
| return new DataResponse(['status' => 'ok']); | ||
| } | ||
|
|
||
| #[AuthorizedAdminSetting(settings: Previews::class)] | ||
| public function clearFailures(): DataResponse { | ||
| $this->failureService->clearAll(); | ||
| return new DataResponse(['status' => 'ok']); | ||
| } | ||
|
|
||
| private function rangeToSince(?string $range): ?int { | ||
| return match ($range) { | ||
| '24h' => time() - 86400, | ||
| '7d' => time() - 7 * 86400, | ||
| '30d' => time() - 30 * 86400, | ||
| default => null, | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.