2022-08-13 01:58:37 +00:00
|
|
|
<?php
|
2022-10-19 17:10:36 +00:00
|
|
|
|
2023-10-15 02:20:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-08-18 18:27:25 +00:00
|
|
|
namespace OCA\Memories\Controller;
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-08-20 00:18:04 +00:00
|
|
|
use OCA\Files\Event\LoadSidebar;
|
2023-10-15 01:51:17 +00:00
|
|
|
use OCA\Memories\AppInfo\Application;
|
2023-05-18 06:16:11 +00:00
|
|
|
use OCA\Memories\Service\BinExt;
|
2023-03-23 20:49:26 +00:00
|
|
|
use OCA\Memories\Util;
|
2022-10-19 17:10:36 +00:00
|
|
|
use OCP\AppFramework\Controller;
|
2022-10-17 02:52:44 +00:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2023-05-18 06:16:11 +00:00
|
|
|
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
|
2022-10-19 17:10:36 +00:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
|
|
|
use OCP\IRequest;
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-10-19 17:10:36 +00:00
|
|
|
class PageController extends Controller
|
|
|
|
{
|
2022-09-09 07:31:42 +00:00
|
|
|
public function __construct(
|
|
|
|
IRequest $request,
|
2023-10-15 01:59:00 +00:00
|
|
|
protected IEventDispatcher $eventDispatcher,
|
2022-10-19 17:15:14 +00:00
|
|
|
) {
|
2023-10-15 01:51:17 +00:00
|
|
|
parent::__construct(Application::APPNAME, $request);
|
2022-09-09 07:31:42 +00:00
|
|
|
}
|
2022-08-13 01:58:37 +00:00
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-09 07:31:42 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function main()
|
|
|
|
{
|
2023-05-18 06:16:11 +00:00
|
|
|
// Check native version if available
|
|
|
|
$nativeVer = Util::callerNativeVersion();
|
|
|
|
if (null !== $nativeVer && version_compare($nativeVer, BinExt::NX_VER_MIN, '<')) {
|
2023-10-15 01:51:17 +00:00
|
|
|
return new PublicTemplateResponse(Application::APPNAME, 'native-old');
|
2022-09-09 07:31:42 +00:00
|
|
|
}
|
2022-08-20 00:18:04 +00:00
|
|
|
|
2022-10-07 17:46:09 +00:00
|
|
|
// Scripts
|
2023-10-15 01:51:17 +00:00
|
|
|
\OCP\Util::addScript(Application::APPNAME, 'memories-main');
|
2022-08-15 21:41:05 +00:00
|
|
|
|
2023-02-14 17:51:52 +00:00
|
|
|
// Extra translations
|
2023-03-23 20:49:26 +00:00
|
|
|
if (Util::recognizeIsEnabled()) {
|
2023-02-14 18:33:32 +00:00
|
|
|
// Auto translation for tags
|
2023-05-26 16:26:45 +00:00
|
|
|
\OCP\Util::addTranslations('recognize');
|
2023-02-14 18:33:32 +00:00
|
|
|
}
|
2023-02-14 17:51:52 +00:00
|
|
|
|
2023-10-15 01:51:17 +00:00
|
|
|
$response = new TemplateResponse(Application::APPNAME, 'main', self::getMainParams());
|
2023-01-18 03:09:02 +00:00
|
|
|
$response->setContentSecurityPolicy(self::getCSP());
|
2023-02-09 08:57:37 +00:00
|
|
|
$response->cacheFor(0);
|
2023-01-18 03:09:02 +00:00
|
|
|
|
2023-05-03 07:37:25 +00:00
|
|
|
// Check if requested from native app
|
2023-05-04 02:59:23 +00:00
|
|
|
if (!Util::callerIsNative()) {
|
2023-05-03 07:37:25 +00:00
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
|
|
|
|
}
|
|
|
|
|
2023-01-18 03:09:02 +00:00
|
|
|
return $response;
|
|
|
|
}
|
2022-11-09 10:42:42 +00:00
|
|
|
|
2023-01-18 03:09:02 +00:00
|
|
|
/** Get the common content security policy */
|
|
|
|
public static function getCSP()
|
|
|
|
{
|
2023-02-09 20:02:11 +00:00
|
|
|
// Image domains MUST be added to the connect domain list
|
|
|
|
// because of the service worker fetch() call
|
2023-10-14 08:25:50 +00:00
|
|
|
$addImageDomain = static function ($url) use (&$policy): void {
|
2023-02-09 20:02:11 +00:00
|
|
|
$policy->addAllowedImageDomain($url);
|
|
|
|
$policy->addAllowedConnectDomain($url);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create base policy
|
2022-10-17 02:52:44 +00:00
|
|
|
$policy = new ContentSecurityPolicy();
|
2022-10-19 17:10:36 +00:00
|
|
|
$policy->addAllowedWorkerSrcDomain("'self'");
|
|
|
|
$policy->addAllowedScriptDomain("'self'");
|
2023-02-09 20:02:11 +00:00
|
|
|
$policy->addAllowedFrameDomain("'self'");
|
|
|
|
$policy->addAllowedImageDomain("'self'");
|
|
|
|
$policy->addAllowedMediaDomain("'self'");
|
|
|
|
$policy->addAllowedConnectDomain("'self'");
|
2022-10-17 02:52:44 +00:00
|
|
|
|
2022-11-09 04:08:30 +00:00
|
|
|
// Video player
|
|
|
|
$policy->addAllowedWorkerSrcDomain('blob:');
|
|
|
|
$policy->addAllowedScriptDomain('blob:');
|
|
|
|
$policy->addAllowedMediaDomain('blob:');
|
|
|
|
|
2022-11-10 05:55:14 +00:00
|
|
|
// Image editor
|
|
|
|
$policy->addAllowedConnectDomain('data:');
|
|
|
|
|
2023-02-06 03:46:44 +00:00
|
|
|
// Allow OSM
|
2022-11-08 00:26:56 +00:00
|
|
|
$policy->addAllowedFrameDomain('www.openstreetmap.org');
|
2023-02-09 20:02:11 +00:00
|
|
|
$addImageDomain('https://*.tile.openstreetmap.org');
|
|
|
|
$addImageDomain('https://*.a.ssl.fastly.net');
|
2022-11-07 23:49:50 +00:00
|
|
|
|
2023-05-08 20:25:13 +00:00
|
|
|
// Native communication
|
|
|
|
$addImageDomain('http://127.0.0.1');
|
|
|
|
|
2023-03-08 18:22:36 +00:00
|
|
|
// Allow Nominatim
|
|
|
|
$policy->addAllowedConnectDomain('nominatim.openstreetmap.org');
|
|
|
|
|
2023-01-18 03:09:02 +00:00
|
|
|
return $policy;
|
|
|
|
}
|
2022-10-19 17:10:36 +00:00
|
|
|
|
2023-05-21 04:53:05 +00:00
|
|
|
/**
|
|
|
|
* Get params for main.php template.
|
|
|
|
*/
|
2023-10-14 08:25:50 +00:00
|
|
|
public static function getMainParams(): array
|
2023-05-21 04:53:05 +00:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'native' => Util::callerIsNative(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-09 07:31:42 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function folder()
|
|
|
|
{
|
2022-09-09 07:31:42 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-09-12 03:06:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-12 03:06:28 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function favorites()
|
|
|
|
{
|
2022-09-12 03:06:28 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-09-13 07:55:32 +00:00
|
|
|
|
2022-10-26 22:12:46 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function albums()
|
|
|
|
{
|
|
|
|
return $this->main();
|
|
|
|
}
|
|
|
|
|
2022-09-13 07:55:32 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-13 07:55:32 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function videos()
|
|
|
|
{
|
2022-09-13 07:55:32 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-09-25 23:02:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-09-25 23:02:26 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function archive()
|
|
|
|
{
|
2022-09-25 23:02:26 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-10-06 20:20:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-10-06 20:20:29 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function thisday()
|
|
|
|
{
|
2022-10-06 20:20:29 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2022-10-06 23:28:35 +00:00
|
|
|
|
2022-10-07 19:28:39 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-10-07 19:28:39 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-12-08 21:00:53 +00:00
|
|
|
public function recognize()
|
|
|
|
{
|
|
|
|
return $this->main();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function facerecognition()
|
2022-10-19 17:10:36 +00:00
|
|
|
{
|
2022-10-07 19:28:39 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
|
|
|
|
2023-02-05 21:43:25 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function places()
|
|
|
|
{
|
|
|
|
return $this->main();
|
|
|
|
}
|
|
|
|
|
2022-10-06 23:28:35 +00:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
2022-10-19 17:10:36 +00:00
|
|
|
*
|
2022-10-06 23:28:35 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2022-10-19 17:10:36 +00:00
|
|
|
public function tags()
|
|
|
|
{
|
2022-10-06 23:28:35 +00:00
|
|
|
return $this->main();
|
|
|
|
}
|
2023-01-25 18:41:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2023-02-08 22:13:13 +00:00
|
|
|
public function map()
|
2023-01-25 18:41:55 +00:00
|
|
|
{
|
|
|
|
return $this->main();
|
|
|
|
}
|
2023-05-03 11:10:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function explore()
|
|
|
|
{
|
|
|
|
return $this->main();
|
|
|
|
}
|
2023-10-02 17:03:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function nxsetup()
|
|
|
|
{
|
|
|
|
return $this->main();
|
|
|
|
}
|
2022-08-13 01:58:37 +00:00
|
|
|
}
|