Files
John Molakvoæ fd43a6243d feat(viewer): keep the user's viewer settings
apps/viewer becomes a minimal, always enabled app again, the server side
of the viewer. It keeps the user's viewer settings the way the Files app
keeps its own: a config lexicon declaring them, a UserConfig service
holding what the lexicon cannot say, an OCS endpoint to change one, and the settings handed to the viewer as initial
state. They are the slideshow delay, and the volume of videos and audio
and whether they start muted. Core keeps loading the viewer itself.

It is no longer an abandoned app to clean up after, and continues the
old app's versions at 9.0.0-dev.0, after 8.0.0 in 35.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
2026-10-14 11:22:36 +02:00

51 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Viewer\Controller;
use OCA\Viewer\Service\UserConfig;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class ConfigController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private UserConfig $userConfig,
) {
parent::__construct($appName, $request);
}
/**
* Set one of the user's viewer settings
*
* @param string $key The setting to change
* @param int|bool $value Its new value: a number for a setting with a range, true or false for a toggle
* @return DataResponse<Http::STATUS_OK, array{key: string, value: int|bool}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{message: string}, array{}>
*
* 200: Setting saved
* 400: Unknown setting, or a value it does not accept
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'PUT', url: '/api/v1/config/{key}')]
public function setConfig(string $key, int|bool $value): DataResponse {
try {
$this->userConfig->setConfig($key, $value);
} catch (\InvalidArgumentException $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
}
return new DataResponse(['key' => $key, 'value' => $value]);
}
}