aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Controller/ApiController.php
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-12-14 16:54:35 +0100
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-01-04 16:45:52 +0100
commit5c987a0ff4530cd0951920fcbfaf97411aeec17a (patch)
treecec3ffdd3282cfe2a84f6f2d9251c72bc3922ed8 /apps/files/lib/Controller/ApiController.php
parent887c9e05de88f81ed6f0cb88bd185c05b1a22076 (diff)
downloadnextcloud-server-5c987a0ff4530cd0951920fcbfaf97411aeec17a.tar.gz
nextcloud-server-5c987a0ff4530cd0951920fcbfaf97411aeec17a.zip
Port settings to Modal
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/lib/Controller/ApiController.php')
-rw-r--r--apps/files/lib/Controller/ApiController.php67
1 files changed, 48 insertions, 19 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php
index a87b4f9490a..e9d15018d03 100644
--- a/apps/files/lib/Controller/ApiController.php
+++ b/apps/files/lib/Controller/ApiController.php
@@ -39,6 +39,7 @@ namespace OCA\Files\Controller;
use OC\Files\Node\Node;
use OCA\Files\Service\TagService;
+use OCA\Files\Service\UserConfig;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -61,18 +62,13 @@ use OCP\Share\IShare;
* @package OCA\Files\Controller
*/
class ApiController extends Controller {
- /** @var TagService */
- private $tagService;
- /** @var IManager * */
- private $shareManager;
- /** @var IPreview */
- private $previewManager;
- /** @var IUserSession */
- private $userSession;
- /** @var IConfig */
- private $config;
- /** @var Folder */
- private $userFolder;
+ private TagService $tagService;
+ private IManager $shareManager;
+ private IPreview $previewManager;
+ private IUserSession $userSession;
+ private IConfig $config;
+ private Folder $userFolder;
+ private UserConfig $userConfig;
/**
* @param string $appName
@@ -91,7 +87,8 @@ class ApiController extends Controller {
IPreview $previewManager,
IManager $shareManager,
IConfig $config,
- Folder $userFolder) {
+ Folder $userFolder,
+ UserConfig $userConfig) {
parent::__construct($appName, $request);
$this->userSession = $userSession;
$this->tagService = $tagService;
@@ -99,6 +96,7 @@ class ApiController extends Controller {
$this->shareManager = $shareManager;
$this->config = $config;
$this->userFolder = $userFolder;
+ $this->userConfig = $userConfig;
}
/**
@@ -283,16 +281,47 @@ class ApiController extends Controller {
}
/**
+ * Toggle default files user config
+ *
+ * @NoAdminRequired
+ *
+ * @param bool $key
+ * @param string|bool $value
+ * @return JSONResponse
+ */
+ public function setConfig(string $key, string|bool $value): JSONResponse {
+ try {
+ $this->userConfig->setConfig($key, $value);
+ } catch (\InvalidArgumentException $e) {
+ return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
+ }
+
+ return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]);
+ }
+
+
+ /**
+ * Get the user config
+ *
+ * @NoAdminRequired
+ *
+ * @return JSONResponse
+ */
+ public function getConfigs(): JSONResponse {
+ return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]);
+ }
+
+ /**
* Toggle default for showing/hiding hidden files
*
* @NoAdminRequired
*
- * @param bool $show
+ * @param bool $value
* @return Response
* @throws \OCP\PreConditionNotMetException
*/
- public function showHiddenFiles(bool $show): Response {
- $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $show ? '1' : '0');
+ public function showHiddenFiles(bool $value): Response {
+ $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0');
return new Response();
}
@@ -301,12 +330,12 @@ class ApiController extends Controller {
*
* @NoAdminRequired
*
- * @param bool $crop
+ * @param bool $value
* @return Response
* @throws \OCP\PreConditionNotMetException
*/
- public function cropImagePreviews(bool $crop): Response {
- $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $crop ? '1' : '0');
+ public function cropImagePreviews(bool $value): Response {
+ $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0');
return new Response();
}