Skip to content

Commit

Permalink
Merge pull request #944 from nextcloud/feat/nomedia
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelklehr authored Mar 17, 2022
2 parents 6f5f392 + 825e01d commit 156f280
Show file tree
Hide file tree
Showing 42 changed files with 147 additions and 205 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

22 changes: 1 addition & 21 deletions js/photos-main.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
*
* 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/>.
*
*/

/**
Expand Down Expand Up @@ -165,27 +166,6 @@
*
*/

/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @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/>.
*/

/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
Expand Down
2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,3 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @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/>.
*/

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* 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/>.
*
*/

/**
Expand All @@ -38,4 +39,5 @@
*
* 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/>.
*
*/

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
*
* 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/>.
*
*/
2 changes: 1 addition & 1 deletion js/photos-src_patchedRequest_js-src_views_Tags_vue.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/photos-src_views_Albums_vue.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
*
* 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/>.
*
*/
2 changes: 1 addition & 1 deletion js/photos-src_views_Albums_vue.js.map

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

69 changes: 63 additions & 6 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@

namespace OCA\Photos\Controller;

use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OC\Files\Search\SearchQuery;
use OC\User\NoUserException;
use OCA\Files\Event\LoadSidebar;
use OCA\Photos\AppInfo\Application;
use OCA\Viewer\Event\LoadViewer;
Expand All @@ -33,11 +39,18 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Util;
use Psr\Log\LoggerInterface;

class PageController extends Controller {
/** @var IAppManager */
Expand All @@ -54,20 +67,43 @@ class PageController extends Controller {

/** @var IUserSession */
private $userSession;
/**
* @var \OCP\Files\IRootFolder
*/
private $rootFolder;
/**
* @var \OCP\ICacheFactory
*/
private $cacheFactory;
/**
* @var \OCP\ICache
*/
private $nomediaPathsCache;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;

public function __construct(IRequest $request,
IAppManager $appManager,
IEventDispatcher $eventDispatcher,
IConfig $config,
public function __construct(IRequest $request,
IAppManager $appManager,
IEventDispatcher $eventDispatcher,
IConfig $config,
IInitialStateService $initialStateService,
IUserSession $userSession) {
IUserSession $userSession,
IRootFolder $rootFolder,
ICacheFactory $cacheFactory,
LoggerInterface $logger) {
parent::__construct(Application::APP_ID, $request);

$this->appManager = $appManager;
$this->eventDispatcher = $eventDispatcher;
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->cacheFactory = $cacheFactory;
$this->nomediaPathsCache = $this->cacheFactory->createLocal('photos:nomedia-paths');
$this->logger = $logger;
}

/**
Expand All @@ -89,6 +125,27 @@ public function index(): TemplateResponse {
$this->initialStateService->provideInitialState($this->appName, 'croppedLayout', $this->config->getUserValue($user->getUid(), Application::APP_ID, 'croppedLayout', 'false'));
$this->initialStateService->provideInitialState($this->appName, 'systemtags', $this->appManager->isEnabledForUser('systemtags') === true);

$paths = [];
try {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$key = $user->getUID() . ':' . $userFolder->getEtag();
$paths = $this->nomediaPathsCache->get($key);
if ($paths === null) {
$search = $userFolder->search(new SearchQuery(new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', '.nomedia'),
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', '.noimage')
]), 0, 0, [], $user));
$paths = array_map(function (Node $node) use ($userFolder) {
return substr(dirname($node->getPath()), strlen($userFolder->getPath()));
}, $search);
$this->nomediaPathsCache->set($key, $paths, 60 * 60 * 24 * 28);
}
} catch (InvalidPathException | NotFoundException | NotPermittedException | NoUserException $e) {
$this->logger->error($e->getMessage());
}

$this->initialStateService->provideInitialState($this->appName, 'nomedia-paths', $paths);

Util::addScript(Application::APP_ID, 'photos-main');
Util::addStyle(Application::APP_ID, 'icons');

Expand All @@ -98,7 +155,7 @@ public function index(): TemplateResponse {
$policy->addAllowedWorkerSrcDomain("'self'");
$policy->addAllowedScriptDomain("'self'");
$response->setContentSecurityPolicy($policy);

return $response;
}
}
6 changes: 5 additions & 1 deletion src/Photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<script>
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'

import Content from '@nextcloud/vue/dist/Components/Content'
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
Expand Down Expand Up @@ -103,7 +104,7 @@ export default {
}
},

beforeMount() {
async beforeMount() {
if ('serviceWorker' in navigator) {
// Use the window load event to keep the page load performant
window.addEventListener('load', () => {
Expand All @@ -119,6 +120,9 @@ export default {
} else {
console.debug('Service Worker is not enabled on this browser.')
}

const files = loadState('photos', 'nomedia-paths', [])
this.$store.dispatch('setNomediaPaths', files)
},

beforeDestroy() {
Expand Down
1 change: 1 addition & 0 deletions src/assets/grid-sizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* 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/>.
*
*/

// for now we want to keep the same gap everywhere
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* 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/>.
*
*/

import { generateFilePath } from '@nextcloud/router'
Expand Down
1 change: 1 addition & 0 deletions src/mixins/GridConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* 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/>.
*
*/

import getGridConfig from '../services/GridConfig'
Expand Down
Loading

0 comments on commit 156f280

Please sign in to comment.