2022-10-29 18:05:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2022 Varun Patil <radialapps@gmail.com>
|
|
|
|
* @author Varun Patil <radialapps@gmail.com>
|
|
|
|
* @license AGPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* 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 OCA\Memories\Controller;
|
|
|
|
|
|
|
|
use OCA\Memories\AppInfo\Application;
|
2023-03-23 20:32:23 +00:00
|
|
|
use OCA\Memories\Exceptions;
|
|
|
|
use OCA\Memories\Util;
|
2022-10-29 18:05:05 +00:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\AppFramework\Http\StreamResponse;
|
|
|
|
|
2023-03-22 18:40:56 +00:00
|
|
|
class OtherController extends GenericApiController
|
2022-10-29 18:05:05 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2023-03-19 03:38:37 +00:00
|
|
|
public function setUserConfig(string $key, string $value): Http\Response
|
2022-10-29 18:05:05 +00:00
|
|
|
{
|
2023-03-23 20:32:23 +00:00
|
|
|
return Util::guardEx(function () use ($key, $value) {
|
|
|
|
// Make sure not running in read-only mode
|
|
|
|
if ($this->config->getSystemValue('memories.readonly', false)) {
|
|
|
|
throw Exceptions::Forbidden('Cannot change settings in readonly mode');
|
|
|
|
}
|
2022-10-29 18:05:05 +00:00
|
|
|
|
2023-03-24 00:56:41 +00:00
|
|
|
$this->config->setUserValue(Util::getUID(), Application::APPNAME, $key, $value);
|
2022-10-29 18:05:05 +00:00
|
|
|
|
2023-03-23 20:32:23 +00:00
|
|
|
return new JSONResponse([], Http::STATUS_OK);
|
|
|
|
});
|
2022-10-29 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 05:52:00 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @PublicPage
|
|
|
|
*/
|
|
|
|
public function getUserConfig(): Http\Response
|
|
|
|
{
|
|
|
|
return Util::guardEx(function () {
|
|
|
|
$appManager = \OC::$server->get(\OCP\App\IAppManager::class);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$uid = Util::getUID();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$uid = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$getAppConfig = function ($key, $default) use ($uid) {
|
|
|
|
return $this->config->getUserValue($uid, Application::APPNAME, $key, $default);
|
|
|
|
};
|
|
|
|
|
|
|
|
return new JSONResponse([
|
2023-05-03 06:38:45 +00:00
|
|
|
'version' => $appManager->getAppInfo('memories')['version'],
|
|
|
|
'vod_disable' => Util::getSystemConfig('memories.vod.disable'),
|
|
|
|
'video_default_quality' => Util::getSystemConfig('memories.video_default_quality'),
|
|
|
|
'places_gis' => Util::getSystemConfig('memories.gis_type'),
|
2023-05-03 05:52:00 +00:00
|
|
|
|
2023-05-03 06:38:45 +00:00
|
|
|
'systemtags_enabled' => Util::tagsIsEnabled(),
|
|
|
|
'recognize_enabled' => Util::recognizeIsEnabled(),
|
|
|
|
'albums_enabled' => Util::albumsIsEnabled(),
|
|
|
|
'facerecognition_installed' => Util::facerecognitionIsInstalled(),
|
|
|
|
'facerecognition_enabled' => Util::facerecognitionIsEnabled(),
|
2023-05-03 05:52:00 +00:00
|
|
|
|
2023-05-03 06:38:45 +00:00
|
|
|
'timeline_path' => $getAppConfig('timelinePath', 'EMPTY'),
|
|
|
|
'folders_path' => $getAppConfig('foldersPath', '/'),
|
|
|
|
'show_hidden_folders' => 'true' === $getAppConfig('showHidden', false),
|
|
|
|
'sort_folder_month' => 'true' === $getAppConfig('sortFolderMonth', false),
|
|
|
|
'sort_album_month' => 'true' === $getAppConfig('sortAlbumMonth', 'true'),
|
|
|
|
'enable_top_memories' => 'true' === $getAppConfig('enableTopMemories', 'true'),
|
2023-05-03 05:52:00 +00:00
|
|
|
], Http::STATUS_OK);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-29 18:05:05 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @PublicPage
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function serviceWorker(): StreamResponse
|
|
|
|
{
|
|
|
|
$response = new StreamResponse(__DIR__.'/../../js/memories-service-worker.js');
|
|
|
|
$response->setHeaders([
|
|
|
|
'Content-Type' => 'application/javascript',
|
|
|
|
'Service-Worker-Allowed' => '/',
|
|
|
|
]);
|
2023-02-09 20:02:11 +00:00
|
|
|
$response->setContentSecurityPolicy(PageController::getCSP());
|
2022-10-29 18:05:05 +00:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|