2015-11-16 14:57:41 -05:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 10:49:16 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
2019-12-03 13:57:53 -05:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
|
|
|
|
* @author fnuesse <felix.nuesse@t-online.de>
|
|
|
|
|
* @author fnuesse <fnuesse@techfak.uni-bielefeld.de>
|
2016-07-21 10:49:16 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2021-06-04 15:52:51 -04:00
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
2019-12-03 13:57:53 -05:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-05-26 13:56:05 -04:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 13:57:53 -05:00
|
|
|
* @author Max Kovalenko <mxss1998@yandex.ru>
|
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2021-06-04 15:52:51 -04:00
|
|
|
* @author Nina Pypchenko <22447785+nina-py@users.noreply.github.com>
|
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 09:02:16 -05:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2020-12-16 08:54:15 -05:00
|
|
|
* @author Vincent Petry <vincent@nextcloud.com>
|
2015-11-16 14:57:41 -05:00
|
|
|
*
|
|
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* 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, version 3,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-11-16 14:57:41 -05:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
namespace OCA\Files\Controller;
|
|
|
|
|
|
2023-06-14 08:43:41 -04:00
|
|
|
use OC\AppFramework\Http;
|
2018-07-12 08:30:39 -04:00
|
|
|
use OCA\Files\Activity\Helper;
|
2022-12-14 10:54:35 -05:00
|
|
|
use OCA\Files\AppInfo\Application;
|
2019-08-02 14:08:54 -04:00
|
|
|
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
2019-10-10 05:26:15 -04:00
|
|
|
use OCA\Files\Event\LoadSidebar;
|
2022-12-14 10:54:35 -05:00
|
|
|
use OCA\Files\Service\UserConfig;
|
2023-04-14 06:40:08 -04:00
|
|
|
use OCA\Files\Service\ViewConfig;
|
2020-03-04 07:51:40 -05:00
|
|
|
use OCA\Viewer\Event\LoadViewer;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\App\IAppManager;
|
2015-11-16 14:57:41 -05:00
|
|
|
use OCP\AppFramework\Controller;
|
2023-06-14 08:43:41 -04:00
|
|
|
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
|
2015-12-02 11:30:40 -05:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2015-11-16 14:57:41 -05:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
2019-03-14 11:28:01 -04:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2015-11-16 14:57:41 -05:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2021-01-12 05:28:04 -05:00
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
2022-08-15 13:18:01 -04:00
|
|
|
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
|
2023-09-22 08:22:04 -04:00
|
|
|
use OCP\Constants;
|
2019-08-02 14:08:54 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2018-07-13 03:57:54 -04:00
|
|
|
use OCP\Files\Folder;
|
2016-08-19 02:15:30 -04:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-06-07 07:51:16 -04:00
|
|
|
use OCP\Files\NotFoundException;
|
2021-01-12 05:28:04 -05:00
|
|
|
use OCP\Files\Template\ITemplateManager;
|
2016-04-12 05:08:26 -04:00
|
|
|
use OCP\IConfig;
|
2015-11-16 14:57:41 -05:00
|
|
|
use OCP\IL10N;
|
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
use OCP\IURLGenerator;
|
2016-04-12 05:08:26 -04:00
|
|
|
use OCP\IUserSession;
|
2021-04-23 11:29:34 -04:00
|
|
|
use OCP\Share\IManager;
|
2015-11-16 14:57:41 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package OCA\Files\Controller
|
|
|
|
|
*/
|
2023-06-14 08:43:41 -04:00
|
|
|
#[IgnoreOpenAPI]
|
2015-11-16 14:57:41 -05:00
|
|
|
class ViewController extends Controller {
|
2022-12-14 10:54:35 -05:00
|
|
|
private IURLGenerator $urlGenerator;
|
|
|
|
|
private IL10N $l10n;
|
|
|
|
|
private IConfig $config;
|
|
|
|
|
private IEventDispatcher $eventDispatcher;
|
|
|
|
|
private IUserSession $userSession;
|
|
|
|
|
private IAppManager $appManager;
|
|
|
|
|
private IRootFolder $rootFolder;
|
|
|
|
|
private Helper $activityHelper;
|
|
|
|
|
private IInitialState $initialState;
|
|
|
|
|
private ITemplateManager $templateManager;
|
|
|
|
|
private IManager $shareManager;
|
|
|
|
|
private UserConfig $userConfig;
|
2023-04-14 06:40:08 -04:00
|
|
|
private ViewConfig $viewConfig;
|
2015-11-16 14:57:41 -05:00
|
|
|
|
2018-07-12 08:30:39 -04:00
|
|
|
public function __construct(string $appName,
|
2018-07-13 03:57:54 -04:00
|
|
|
IRequest $request,
|
|
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
|
IL10N $l10n,
|
|
|
|
|
IConfig $config,
|
2019-08-02 14:08:54 -04:00
|
|
|
IEventDispatcher $eventDispatcher,
|
2018-07-13 03:57:54 -04:00
|
|
|
IUserSession $userSession,
|
|
|
|
|
IAppManager $appManager,
|
|
|
|
|
IRootFolder $rootFolder,
|
2021-01-12 05:28:04 -05:00
|
|
|
Helper $activityHelper,
|
|
|
|
|
IInitialState $initialState,
|
2021-04-23 11:29:34 -04:00
|
|
|
ITemplateManager $templateManager,
|
2022-12-14 10:54:35 -05:00
|
|
|
IManager $shareManager,
|
2023-04-14 06:40:08 -04:00
|
|
|
UserConfig $userConfig,
|
|
|
|
|
ViewConfig $viewConfig
|
2016-05-04 04:28:06 -04:00
|
|
|
) {
|
2015-11-16 14:57:41 -05:00
|
|
|
parent::__construct($appName, $request);
|
2020-10-05 09:12:57 -04:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
|
$this->config = $config;
|
2019-08-02 14:08:54 -04:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
2020-10-05 09:12:57 -04:00
|
|
|
$this->userSession = $userSession;
|
|
|
|
|
$this->appManager = $appManager;
|
|
|
|
|
$this->rootFolder = $rootFolder;
|
|
|
|
|
$this->activityHelper = $activityHelper;
|
2021-01-12 05:28:04 -05:00
|
|
|
$this->initialState = $initialState;
|
|
|
|
|
$this->templateManager = $templateManager;
|
2021-04-23 11:29:34 -04:00
|
|
|
$this->shareManager = $shareManager;
|
2022-12-14 10:54:35 -05:00
|
|
|
$this->userConfig = $userConfig;
|
2023-04-14 06:40:08 -04:00
|
|
|
$this->viewConfig = $viewConfig;
|
2015-11-16 14:57:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $appName
|
|
|
|
|
* @param string $scriptName
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function renderScript($appName, $scriptName) {
|
2020-10-05 09:12:57 -04:00
|
|
|
$content = '';
|
|
|
|
|
$appPath = \OC_App::getAppPath($appName);
|
2015-11-16 14:57:41 -05:00
|
|
|
$scriptPath = $appPath . '/' . $scriptName;
|
|
|
|
|
if (file_exists($scriptPath)) {
|
|
|
|
|
// TODO: sanitize path / script name ?
|
|
|
|
|
ob_start();
|
|
|
|
|
include $scriptPath;
|
|
|
|
|
$content = ob_get_contents();
|
|
|
|
|
@ob_end_clean();
|
|
|
|
|
}
|
2018-07-13 03:57:54 -04:00
|
|
|
|
2015-11-16 14:57:41 -05:00
|
|
|
return $content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* FIXME: Replace with non static code
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
|
*/
|
2023-01-04 13:06:52 -05:00
|
|
|
protected function getStorageInfo(string $dir = '/') {
|
|
|
|
|
$rootInfo = \OC\Files\Filesystem::getFileInfo('/', false);
|
2018-07-13 03:57:54 -04:00
|
|
|
|
2023-01-04 13:06:52 -05:00
|
|
|
return \OC_Helper::getStorageInfo($dir, $rootInfo ?: null);
|
2015-11-16 14:57:41 -05:00
|
|
|
}
|
|
|
|
|
|
2019-03-14 10:12:16 -04:00
|
|
|
/**
|
|
|
|
|
* @NoCSRFRequired
|
|
|
|
|
* @NoAdminRequired
|
|
|
|
|
*
|
|
|
|
|
* @param string $fileid
|
|
|
|
|
* @return TemplateResponse|RedirectResponse
|
|
|
|
|
*/
|
2023-08-17 02:55:30 -04:00
|
|
|
public function showFile(string $fileid = null): Response {
|
|
|
|
|
if (!$fileid) {
|
|
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index'));
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 10:12:16 -04:00
|
|
|
// This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
|
2019-06-18 07:09:38 -04:00
|
|
|
try {
|
2023-08-17 02:55:30 -04:00
|
|
|
return $this->redirectToFile((int) $fileid);
|
2019-06-18 07:09:38 -04:00
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
|
|
|
|
|
}
|
2019-03-14 10:12:16 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 02:55:30 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @NoCSRFRequired
|
|
|
|
|
* @NoAdminRequired
|
|
|
|
|
* @UseSession
|
2023-08-27 08:18:28 -04:00
|
|
|
*
|
2023-08-17 02:55:30 -04:00
|
|
|
* @param string $dir
|
|
|
|
|
* @param string $view
|
|
|
|
|
* @param string $fileid
|
|
|
|
|
* @param bool $fileNotFound
|
|
|
|
|
* @return TemplateResponse|RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function indexView($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
|
|
|
|
|
return $this->index($dir, $view, $fileid, $fileNotFound);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 14:57:41 -05:00
|
|
|
/**
|
|
|
|
|
* @NoCSRFRequired
|
|
|
|
|
* @NoAdminRequired
|
2021-08-04 09:52:10 -04:00
|
|
|
* @UseSession
|
2015-11-16 14:57:41 -05:00
|
|
|
*
|
|
|
|
|
* @param string $dir
|
|
|
|
|
* @param string $view
|
2016-05-04 04:28:06 -04:00
|
|
|
* @param string $fileid
|
2019-05-27 01:54:09 -04:00
|
|
|
* @param bool $fileNotFound
|
2016-08-19 04:10:19 -04:00
|
|
|
* @return TemplateResponse|RedirectResponse
|
2015-11-16 14:57:41 -05:00
|
|
|
*/
|
2023-08-17 02:55:30 -04:00
|
|
|
public function indexViewFileid($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
|
|
|
|
|
return $this->index($dir, $view, $fileid, $fileNotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @NoCSRFRequired
|
|
|
|
|
* @NoAdminRequired
|
|
|
|
|
* @UseSession
|
|
|
|
|
*
|
|
|
|
|
* @param string $dir
|
|
|
|
|
* @param string $view
|
|
|
|
|
* @param string $fileid
|
|
|
|
|
* @param bool $fileNotFound
|
|
|
|
|
* @return TemplateResponse|RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
|
|
|
|
|
if ($fileid !== null && $view !== 'trashbin') {
|
|
|
|
|
try {
|
|
|
|
|
return $this->redirectToFileIfInTrashbin((int) $fileid);
|
|
|
|
|
} catch (NotFoundException $e) {}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 14:57:41 -05:00
|
|
|
// Load the files we need
|
2023-09-21 06:15:11 -04:00
|
|
|
\OCP\Util::addInitScript('files', 'init');
|
2017-03-21 11:35:31 -04:00
|
|
|
\OCP\Util::addStyle('files', 'merged');
|
2021-12-02 12:57:11 -05:00
|
|
|
\OCP\Util::addScript('files', 'main');
|
2015-11-16 14:57:41 -05:00
|
|
|
|
2022-12-01 08:34:23 -05:00
|
|
|
$userId = $this->userSession->getUser()->getUID();
|
2018-06-16 16:44:18 -04:00
|
|
|
|
2018-07-13 03:33:57 -04:00
|
|
|
// Get all the user favorites to create a submenu
|
2018-06-17 16:21:11 -04:00
|
|
|
try {
|
2022-12-01 08:34:23 -05:00
|
|
|
$favElements = $this->activityHelper->getFavoriteFilePaths($userId);
|
2018-06-17 16:21:11 -04:00
|
|
|
} catch (\RuntimeException $e) {
|
2018-07-26 09:14:28 -04:00
|
|
|
$favElements['folders'] = [];
|
2018-06-17 16:21:11 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-04 13:06:52 -05:00
|
|
|
try {
|
|
|
|
|
// If view is files, we use the directory, otherwise we use the root storage
|
|
|
|
|
$storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/');
|
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
|
$storageInfo = $this->getStorageInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->initialState->provideInitialState('storageStats', $storageInfo);
|
2022-12-14 10:54:35 -05:00
|
|
|
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
|
2023-04-14 06:40:08 -04:00
|
|
|
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
|
2023-04-11 05:24:09 -04:00
|
|
|
$this->initialState->provideInitialState('favoriteFolders', $favElements['folders'] ?? []);
|
2022-12-01 08:34:23 -05:00
|
|
|
|
2023-03-21 04:53:31 -04:00
|
|
|
// File sorting user config
|
2023-03-24 04:41:40 -04:00
|
|
|
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
|
|
|
|
|
$this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig);
|
2023-03-21 04:53:31 -04:00
|
|
|
|
2023-09-22 08:22:04 -04:00
|
|
|
// Forbidden file characters
|
|
|
|
|
/** @var string[] */
|
|
|
|
|
$forbiddenCharacters = $this->config->getSystemValue('forbidden_chars', []);
|
|
|
|
|
$this->initialState->provideInitialState('forbiddenCharacters', Constants::FILENAME_INVALID_CHARS . implode('', $forbiddenCharacters));
|
|
|
|
|
|
2019-08-02 14:08:54 -04:00
|
|
|
$event = new LoadAdditionalScriptsEvent();
|
2020-08-10 08:29:21 -04:00
|
|
|
$this->eventDispatcher->dispatchTyped($event);
|
2023-08-09 08:59:35 -04:00
|
|
|
$this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent());
|
2020-08-10 08:29:21 -04:00
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
|
2020-03-04 07:51:40 -05:00
|
|
|
// Load Viewer scripts
|
|
|
|
|
if (class_exists(LoadViewer::class)) {
|
2020-03-06 09:44:42 -05:00
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadViewer());
|
2020-03-04 07:51:40 -05:00
|
|
|
}
|
2022-08-15 13:18:01 -04:00
|
|
|
|
2021-03-15 12:23:30 -04:00
|
|
|
$this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
|
2021-01-12 05:28:04 -05:00
|
|
|
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());
|
2019-10-10 05:26:15 -04:00
|
|
|
|
2023-08-09 08:59:35 -04:00
|
|
|
$params = [
|
|
|
|
|
'fileNotFound' => $fileNotFound ? 1 : 0
|
|
|
|
|
];
|
2015-11-16 14:57:41 -05:00
|
|
|
|
2015-12-02 11:30:40 -05:00
|
|
|
$response = new TemplateResponse(
|
2022-12-14 10:54:35 -05:00
|
|
|
Application::APP_ID,
|
2015-11-16 14:57:41 -05:00
|
|
|
'index',
|
|
|
|
|
$params
|
|
|
|
|
);
|
2015-12-02 11:30:40 -05:00
|
|
|
$policy = new ContentSecurityPolicy();
|
|
|
|
|
$policy->addAllowedFrameDomain('\'self\'');
|
2023-08-11 03:03:21 -04:00
|
|
|
// Allow preview service worker
|
|
|
|
|
$policy->addAllowedWorkerSrcDomain('\'self\'');
|
2015-12-02 11:30:40 -05:00
|
|
|
$response->setContentSecurityPolicy($policy);
|
|
|
|
|
|
2023-08-17 02:55:30 -04:00
|
|
|
$this->provideInitialState($dir, $fileid);
|
2021-05-26 12:21:30 -04:00
|
|
|
|
2015-12-02 11:30:40 -05:00
|
|
|
return $response;
|
2015-11-16 14:57:41 -05:00
|
|
|
}
|
2016-05-04 04:28:06 -04:00
|
|
|
|
2021-05-26 12:21:30 -04:00
|
|
|
/**
|
2023-08-17 02:55:30 -04:00
|
|
|
* Add openFileInfo in initialState.
|
2021-05-26 12:21:30 -04:00
|
|
|
* @param string $dir - the ?dir= URL param
|
2023-08-17 02:55:30 -04:00
|
|
|
* @param string $fileid - the fileid URL param
|
2021-05-26 12:21:30 -04:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2023-08-17 02:55:30 -04:00
|
|
|
private function provideInitialState(string $dir, ?string $fileid): void {
|
|
|
|
|
if ($fileid === null) {
|
2021-05-26 12:21:30 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
|
|
|
|
|
|
if ($user === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$uid = $user->getUID();
|
|
|
|
|
$userFolder = $this->rootFolder->getUserFolder($uid);
|
2023-08-17 02:55:30 -04:00
|
|
|
$nodes = $userFolder->getById((int) $fileid);
|
2021-05-26 12:21:30 -04:00
|
|
|
$node = array_shift($nodes);
|
|
|
|
|
|
|
|
|
|
if ($node === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// properly format full path and make sure
|
|
|
|
|
// we're relative to the user home folder
|
|
|
|
|
$isRoot = $node === $userFolder;
|
|
|
|
|
$path = $userFolder->getRelativePath($node->getPath());
|
|
|
|
|
$directory = $userFolder->getRelativePath($node->getParent()->getPath());
|
|
|
|
|
|
|
|
|
|
// Prevent opening a file from another folder.
|
|
|
|
|
if ($dir !== $directory) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->initialState->provideInitialState(
|
|
|
|
|
'openFileInfo', [
|
|
|
|
|
'id' => $node->getId(),
|
|
|
|
|
'name' => $isRoot ? '' : $node->getName(),
|
|
|
|
|
'path' => $path,
|
|
|
|
|
'directory' => $directory,
|
|
|
|
|
'mime' => $node->getMimetype(),
|
|
|
|
|
'type' => $node->getType(),
|
|
|
|
|
'permissions' => $node->getPermissions(),
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 04:28:06 -04:00
|
|
|
/**
|
2023-08-17 02:55:30 -04:00
|
|
|
* Redirects to the trashbin file list and highlight the given file id
|
2016-05-04 04:28:06 -04:00
|
|
|
*
|
2023-08-17 02:55:30 -04:00
|
|
|
* @param int $fileId file id to show
|
2016-06-07 07:51:16 -04:00
|
|
|
* @return RedirectResponse redirect response or not found response
|
2023-08-17 02:55:30 -04:00
|
|
|
* @throws NotFoundException
|
2016-05-04 04:28:06 -04:00
|
|
|
*/
|
2023-08-17 02:55:30 -04:00
|
|
|
private function redirectToFileIfInTrashbin($fileId): RedirectResponse {
|
2020-10-05 09:12:57 -04:00
|
|
|
$uid = $this->userSession->getUser()->getUID();
|
2016-08-19 02:15:30 -04:00
|
|
|
$baseFolder = $this->rootFolder->getUserFolder($uid);
|
2023-08-17 02:55:30 -04:00
|
|
|
$nodes = $baseFolder->getById($fileId);
|
2020-10-05 09:12:57 -04:00
|
|
|
$params = [];
|
2016-05-11 13:41:36 -04:00
|
|
|
|
2023-08-17 02:55:30 -04:00
|
|
|
if (empty($nodes) && $this->appManager->isEnabledForUser('files_trashbin')) {
|
|
|
|
|
/** @var Folder */
|
2020-10-05 09:12:57 -04:00
|
|
|
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
|
2023-08-17 02:55:30 -04:00
|
|
|
$nodes = $baseFolder->getById($fileId);
|
2016-06-07 07:51:16 -04:00
|
|
|
$params['view'] = 'trashbin';
|
2023-08-17 02:55:30 -04:00
|
|
|
|
|
|
|
|
if (!empty($nodes)) {
|
|
|
|
|
$node = current($nodes);
|
|
|
|
|
$params['fileid'] = $fileId;
|
|
|
|
|
if ($node instanceof Folder) {
|
|
|
|
|
// set the full path to enter the folder
|
|
|
|
|
$params['dir'] = $baseFolder->getRelativePath($node->getPath());
|
|
|
|
|
} else {
|
|
|
|
|
// set parent path as dir
|
|
|
|
|
$params['dir'] = $baseFolder->getRelativePath($node->getParent()->getPath());
|
|
|
|
|
}
|
|
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', $params));
|
|
|
|
|
}
|
2016-06-07 07:51:16 -04:00
|
|
|
}
|
2023-08-17 02:55:30 -04:00
|
|
|
throw new NotFoundException();
|
|
|
|
|
}
|
2016-05-04 04:28:06 -04:00
|
|
|
|
2023-08-17 02:55:30 -04:00
|
|
|
/**
|
|
|
|
|
* Redirects to the file list and highlight the given file id
|
|
|
|
|
*
|
|
|
|
|
* @param int $fileId file id to show
|
|
|
|
|
* @return RedirectResponse redirect response or not found response
|
|
|
|
|
* @throws NotFoundException
|
|
|
|
|
*/
|
|
|
|
|
private function redirectToFile(int $fileId) {
|
|
|
|
|
$uid = $this->userSession->getUser()->getUID();
|
|
|
|
|
$baseFolder = $this->rootFolder->getUserFolder($uid);
|
|
|
|
|
$nodes = $baseFolder->getById($fileId);
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->redirectToFileIfInTrashbin($fileId);
|
|
|
|
|
} catch (NotFoundException $e) {}
|
|
|
|
|
|
|
|
|
|
if (!empty($nodes)) {
|
|
|
|
|
$node = current($nodes);
|
|
|
|
|
$params['fileid'] = $fileId;
|
|
|
|
|
if ($node instanceof Folder) {
|
2016-06-07 07:51:16 -04:00
|
|
|
// set the full path to enter the folder
|
2023-08-17 02:55:30 -04:00
|
|
|
$params['dir'] = $baseFolder->getRelativePath($node->getPath());
|
2016-06-07 07:51:16 -04:00
|
|
|
} else {
|
|
|
|
|
// set parent path as dir
|
2023-08-17 02:55:30 -04:00
|
|
|
$params['dir'] = $baseFolder->getRelativePath($node->getParent()->getPath());
|
2016-05-04 04:28:06 -04:00
|
|
|
}
|
2023-08-17 02:55:30 -04:00
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', $params));
|
2016-05-04 04:28:06 -04:00
|
|
|
}
|
2023-08-27 08:18:28 -04:00
|
|
|
|
2023-08-17 02:55:30 -04:00
|
|
|
throw new NotFoundException();
|
2016-05-04 04:28:06 -04:00
|
|
|
}
|
2015-11-16 14:57:41 -05:00
|
|
|
}
|