Skip to content

Commit

Permalink
Create photos sidebar tab
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Nov 8, 2023
1 parent 766d95d commit 0a42ed4
Show file tree
Hide file tree
Showing 10 changed files with 626 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\Files\Event\LoadSidebar;
use OCA\Photos\Listener\AlbumsManagementEventListener;
use OCA\Photos\Listener\CSPListener;
use OCA\Photos\Listener\LoadSidebarScripts;
use OCA\Photos\Listener\SabrePluginAuthInitListener;
use OCA\Photos\Listener\TagListener;
use OCA\Photos\MetadataProvider\ExifMetadataProvider;
Expand All @@ -43,6 +46,7 @@
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\SystemTag\MapperEvent;
use OCP\User\Events\UserDeletedEvent;
Expand Down Expand Up @@ -79,6 +83,10 @@ public function register(IRegistrationContext $context): void {
/** Register $principalBackend for the DAV collection */
$context->registerServiceAlias('principalBackend', Principal::class);

$context->registerEventListener(LoadSidebar::class, LoadSidebarScripts::class);

$context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class);

// Metadata
$context->registerEventListener(MetadataLiveEvent::class, ExifMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, SizeMetadataProvider::class);
Expand Down
51 changes: 51 additions & 0 deletions lib/Listener/CSPListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2023, Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license GNU AGPL version 3 or any later version
*
* 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\Photos\Listener;

use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Security\CSP\AddContentSecurityPolicyEvent;

/**
* @template-implements IEventListener<Event>
*/
class CSPListener implements IEventListener {

public function __construct(
) {
}

public function handle(Event $event): void {
if (!($event instanceof AddContentSecurityPolicyEvent)) {
return;
}

$csp = new ContentSecurityPolicy();
$csp->addAllowedImageDomain('https://*.tile.openstreetmap.org');
$event->addPolicy($csp);
}
}
57 changes: 57 additions & 0 deletions lib/Listener/LoadSidebarScripts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2023, Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license GNU AGPL version 3 or any later version
*
* 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\Photos\Listener;

use OCA\Files\Event\LoadSidebar;
use OCA\Photos\AppInfo\Application;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IRequest;
use OCP\Util;

/**
* @template-implements IEventListener<Event>
*/
class LoadSidebarScripts implements IEventListener {

public function __construct(
private IRequest $request,
) {
}

public function handle(Event $event): void {
if (!($event instanceof LoadSidebar)) {
return;
}

// Only load sidebar tab in the photos app.
if (!preg_match('/^photos\.page\..+/', $this->request->getParams()['_route'])) {
return;
}

Util::addScript(Application::APP_ID, 'photos-sidebar');
}
}
9 changes: 8 additions & 1 deletion lib/MetadataProvider/ExifMetadataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,18 @@ private function parseGPSData(string $rawData): float {
/**
* Exif data can contain anything.
* This method will base 64 encode any non UTF-8 string in an array.
* This will also remove control characters from UTF-8 strings.
*/
private function base64Encode(array $data): array {
foreach ($data as $key => $value) {
if (is_string($value) && !mb_check_encoding($value, 'UTF-8')) {
if (!is_string($value)) {
continue;
}

if (!mb_check_encoding($value, 'UTF-8')) {
$data[$key] = 'base64:'.base64_encode($value);
} else {
$data[$key] = preg_replace('/[[:cntrl:]]/u', '', $value);
}
}

Expand Down
45 changes: 42 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@essentials/request-timeout": "^1.3.0",
"@mdi/svg": "^7.1.96",
"@mdi/svg": "^7.3.67",
"@nextcloud/auth": "^2.1.0",
"@nextcloud/axios": "^2.1.0",
"@nextcloud/dialogs": "^4.1.0",
Expand All @@ -57,6 +57,7 @@
"camelcase": "^7.0.0",
"debounce": "^1.2.1",
"he": "^1.2.0",
"leaflet-defaulticon-compatibility": "^0.1.2",
"path-posix": "^1.0.0",
"qs": "^6.11.2",
"url-parse": "^1.5.10",
Expand All @@ -65,6 +66,7 @@
"vue-router": "^3.6.5",
"vue-template-compiler": "^2.7.14",
"vue-virtual-grid": "^2.5.0",
"vue2-leaflet": "^2.7.1",
"vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0",
"webdav": "^4.11.0"
Expand Down
Loading

0 comments on commit 0a42ed4

Please sign in to comment.