config = $config; $this->userSession = $userSession; } /** * @NoAdminRequired * * update preferences (user setting) * * @param string key the identifier to change * @param string value the value to set * * @return JSONResponse an empty JSONResponse with respective http status code */ public function setUserConfig(string $key, string $value): JSONResponse { $user = $this->userSession->getUser(); if (is_null($user)) { return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); } if (!in_array($key, array_keys(UserConfigService::DEFAULT_CONFIGS))) { return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); } $this->config->setUserValue($user->getUid(), Application::APP_ID, $key, $value); return new JSONResponse([], Http::STATUS_OK); } /** * @NoAdminRequired * @NoCSRFRequired */ public function serviceWorker(): StreamResponse { $response = new StreamResponse(__DIR__ . '/../../js/photos-service-worker.js'); $response->setHeaders([ 'Content-Type' => 'application/javascript', 'Service-Worker-Allowed' => '/' ]); $policy = new ContentSecurityPolicy(); $policy->addAllowedWorkerSrcDomain("'self'"); $policy->addAllowedScriptDomain("'self'"); $policy->addAllowedConnectDomain("'self'"); $response->setContentSecurityPolicy($policy); return $response; } }