2015-11-16 22:57:41 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2019-12-03 21:57:53 +03: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 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Max Kovalenko <mxss1998@yandex.ru>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2020-12-16 16:54:15 +03:00
|
|
|
* @author Vincent Petry <vincent@nextcloud.com>
|
2015-11-16 22:57:41 +03: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 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-11-16 22:57:41 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files\Controller;
|
|
|
|
|
2018-07-12 15:30:39 +03:00
|
|
|
use OCA\Files\Activity\Helper;
|
2019-08-02 21:08:54 +03:00
|
|
|
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
2019-10-10 12:26:15 +03:00
|
|
|
use OCA\Files\Event\LoadSidebar;
|
2020-03-04 15:51:40 +03:00
|
|
|
use OCA\Viewer\Event\LoadViewer;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\App\IAppManager;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\AppFramework\Controller;
|
2015-12-02 19:30:40 +03:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
2019-03-14 18:28:01 +03:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2021-01-12 13:28:04 +03:00
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
2019-08-02 21:08:54 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2018-07-13 10:57:54 +03:00
|
|
|
use OCP\Files\Folder;
|
2016-08-19 09:15:30 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-06-07 14:51:16 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
2021-01-12 13:28:04 +03:00
|
|
|
use OCP\Files\Template\ITemplateManager;
|
2016-04-12 12:08:26 +03:00
|
|
|
use OCP\IConfig;
|
2015-11-16 22:57:41 +03:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IURLGenerator;
|
2016-04-12 12:08:26 +03:00
|
|
|
use OCP\IUserSession;
|
2021-04-23 18:29:34 +03:00
|
|
|
use OCP\Share\IManager;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ViewController
|
|
|
|
*
|
|
|
|
* @package OCA\Files\Controller
|
|
|
|
*/
|
|
|
|
class ViewController extends Controller {
|
|
|
|
/** @var string */
|
|
|
|
protected $appName;
|
|
|
|
/** @var IRequest */
|
|
|
|
protected $request;
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
protected $urlGenerator;
|
|
|
|
/** @var IL10N */
|
|
|
|
protected $l10n;
|
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
2019-08-02 21:08:54 +03:00
|
|
|
/** @var IEventDispatcher */
|
2015-11-16 22:57:41 +03:00
|
|
|
protected $eventDispatcher;
|
2016-04-12 12:08:26 +03:00
|
|
|
/** @var IUserSession */
|
|
|
|
protected $userSession;
|
2016-05-11 20:41:36 +03:00
|
|
|
/** @var IAppManager */
|
|
|
|
protected $appManager;
|
2016-08-19 09:15:30 +03:00
|
|
|
/** @var IRootFolder */
|
2016-05-11 20:41:36 +03:00
|
|
|
protected $rootFolder;
|
2018-07-12 15:30:39 +03:00
|
|
|
/** @var Helper */
|
|
|
|
protected $activityHelper;
|
2021-01-12 13:28:04 +03:00
|
|
|
/** @var IInitialState */
|
|
|
|
private $initialState;
|
|
|
|
/** @var ITemplateManager */
|
|
|
|
private $templateManager;
|
2021-04-23 18:29:34 +03:00
|
|
|
/** @var IManager */
|
|
|
|
private $shareManager;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
2018-07-12 15:30:39 +03:00
|
|
|
public function __construct(string $appName,
|
2018-07-13 10:57:54 +03:00
|
|
|
IRequest $request,
|
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
IL10N $l10n,
|
|
|
|
IConfig $config,
|
2019-08-02 21:08:54 +03:00
|
|
|
IEventDispatcher $eventDispatcher,
|
2018-07-13 10:57:54 +03:00
|
|
|
IUserSession $userSession,
|
|
|
|
IAppManager $appManager,
|
|
|
|
IRootFolder $rootFolder,
|
2021-01-12 13:28:04 +03:00
|
|
|
Helper $activityHelper,
|
|
|
|
IInitialState $initialState,
|
2021-04-23 18:29:34 +03:00
|
|
|
ITemplateManager $templateManager,
|
|
|
|
IManager $shareManager
|
2016-05-04 11:28:06 +03:00
|
|
|
) {
|
2015-11-16 22:57:41 +03:00
|
|
|
parent::__construct($appName, $request);
|
2020-10-05 16:12:57 +03:00
|
|
|
$this->appName = $appName;
|
|
|
|
$this->request = $request;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
$this->config = $config;
|
2019-08-02 21:08:54 +03:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
2020-10-05 16:12:57 +03:00
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->appManager = $appManager;
|
|
|
|
$this->rootFolder = $rootFolder;
|
|
|
|
$this->activityHelper = $activityHelper;
|
2021-01-12 13:28:04 +03:00
|
|
|
$this->initialState = $initialState;
|
|
|
|
$this->templateManager = $templateManager;
|
2021-04-23 18:29:34 +03:00
|
|
|
$this->shareManager = $shareManager;
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param string $scriptName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function renderScript($appName, $scriptName) {
|
2020-10-05 16:12:57 +03:00
|
|
|
$content = '';
|
|
|
|
$appPath = \OC_App::getAppPath($appName);
|
2015-11-16 22:57:41 +03: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 10:57:54 +03:00
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FIXME: Replace with non static code
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
*/
|
|
|
|
protected function getStorageInfo() {
|
2020-10-31 17:10:48 +03:00
|
|
|
\OC_Util::setupFS();
|
2015-11-16 22:57:41 +03:00
|
|
|
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
|
2018-07-13 10:57:54 +03:00
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
return \OC_Helper::getStorageInfo('/', $dirInfo);
|
|
|
|
}
|
|
|
|
|
2019-03-14 17:12:16 +03:00
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $fileid
|
|
|
|
* @return TemplateResponse|RedirectResponse
|
2019-05-27 08:54:09 +03:00
|
|
|
* @throws NotFoundException
|
2019-03-14 17:12:16 +03:00
|
|
|
*/
|
|
|
|
public function showFile(string $fileid = null): Response {
|
|
|
|
// This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
|
2019-06-18 14:09:38 +03:00
|
|
|
try {
|
|
|
|
return $this->redirectToFile($fileid);
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
|
|
|
|
}
|
2019-03-14 17:12:16 +03:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $dir
|
|
|
|
* @param string $view
|
2016-05-04 11:28:06 +03:00
|
|
|
* @param string $fileid
|
2019-05-27 08:54:09 +03:00
|
|
|
* @param bool $fileNotFound
|
2016-08-19 11:10:19 +03:00
|
|
|
* @return TemplateResponse|RedirectResponse
|
2019-05-27 08:54:09 +03:00
|
|
|
* @throws NotFoundException
|
2015-11-16 22:57:41 +03:00
|
|
|
*/
|
2016-08-19 11:10:19 +03:00
|
|
|
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
|
2016-05-04 11:28:06 +03:00
|
|
|
if ($fileid !== null) {
|
2016-06-07 14:51:16 +03:00
|
|
|
try {
|
2019-03-14 17:12:16 +03:00
|
|
|
return $this->redirectToFile($fileid);
|
2016-06-07 14:51:16 +03:00
|
|
|
} catch (NotFoundException $e) {
|
2016-08-19 11:10:19 +03:00
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
|
2016-06-07 14:51:16 +03:00
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
|
|
|
|
2015-11-17 15:36:40 +03:00
|
|
|
$nav = new \OCP\Template('files', 'appnavigation', '');
|
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
// Load the files we need
|
2017-03-21 18:35:31 +03:00
|
|
|
\OCP\Util::addStyle('files', 'merged');
|
2017-03-24 21:41:49 +03:00
|
|
|
\OCP\Util::addScript('files', 'merged-index');
|
2021-01-14 15:31:15 +03:00
|
|
|
\OCP\Util::addScript('files', 'dist/templates');
|
2015-11-16 22:57:41 +03:00
|
|
|
|
|
|
|
// mostly for the home storage's free space
|
|
|
|
// FIXME: Make non static
|
|
|
|
$storageInfo = $this->getStorageInfo();
|
|
|
|
|
2018-06-16 23:44:18 +03:00
|
|
|
$user = $this->userSession->getUser()->getUID();
|
|
|
|
|
2018-07-13 10:33:57 +03:00
|
|
|
// Get all the user favorites to create a submenu
|
2018-06-17 23:21:11 +03:00
|
|
|
try {
|
2018-07-12 15:30:39 +03:00
|
|
|
$favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
|
2018-06-17 23:21:11 +03:00
|
|
|
} catch (\RuntimeException $e) {
|
2018-07-26 16:14:28 +03:00
|
|
|
$favElements['folders'] = [];
|
2018-06-17 23:21:11 +03:00
|
|
|
}
|
|
|
|
|
2018-06-18 13:42:43 +03:00
|
|
|
$collapseClasses = '';
|
2018-07-12 15:30:39 +03:00
|
|
|
if (count($favElements['folders']) > 0) {
|
2018-06-18 13:42:43 +03:00
|
|
|
$collapseClasses = 'collapsible';
|
2018-06-18 13:35:20 +03:00
|
|
|
}
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$favoritesSublistArray = [];
|
2018-06-20 23:40:10 +03:00
|
|
|
|
|
|
|
$navBarPositionPosition = 6;
|
2020-10-05 16:12:57 +03:00
|
|
|
$currentCount = 0;
|
2018-07-12 10:56:46 +03:00
|
|
|
foreach ($favElements['folders'] as $dir) {
|
2020-10-05 16:12:57 +03:00
|
|
|
$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
|
2018-06-20 23:40:10 +03:00
|
|
|
$sortingValue = ++$currentCount;
|
2020-10-05 16:12:57 +03:00
|
|
|
$element = [
|
|
|
|
'id' => str_replace('/', '-', $dir),
|
|
|
|
'view' => 'files',
|
|
|
|
'href' => $link,
|
|
|
|
'dir' => $dir,
|
|
|
|
'order' => $navBarPositionPosition,
|
|
|
|
'folderPosition' => $sortingValue,
|
|
|
|
'name' => basename($dir),
|
|
|
|
'icon' => 'files',
|
2018-06-20 23:40:10 +03:00
|
|
|
'quickaccesselement' => 'true'
|
|
|
|
];
|
|
|
|
|
|
|
|
array_push($favoritesSublistArray, $element);
|
|
|
|
$navBarPositionPosition++;
|
|
|
|
}
|
|
|
|
|
2018-07-13 10:33:57 +03:00
|
|
|
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
|
2018-06-20 23:40:10 +03:00
|
|
|
|
2018-07-13 10:57:54 +03:00
|
|
|
// add the favorites entry in menu
|
2018-07-13 10:33:57 +03:00
|
|
|
$navItems['favorites']['sublist'] = $favoritesSublistArray;
|
|
|
|
$navItems['favorites']['classes'] = $collapseClasses;
|
2015-11-16 22:57:41 +03:00
|
|
|
|
2018-07-13 10:33:57 +03:00
|
|
|
// parse every menu and add the expandedState user value
|
|
|
|
foreach ($navItems as $key => $item) {
|
|
|
|
if (isset($item['expandedState'])) {
|
2018-07-13 10:57:54 +03:00
|
|
|
$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
|
2018-07-13 10:33:57 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-16 22:57:41 +03:00
|
|
|
|
2018-06-01 21:29:43 +03:00
|
|
|
$nav->assign('navigationItems', $navItems);
|
2017-06-08 17:42:43 +03:00
|
|
|
|
2019-07-02 20:45:14 +03:00
|
|
|
$nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used']));
|
2017-06-08 17:42:43 +03:00
|
|
|
if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
|
|
|
|
$totalSpace = $this->l10n->t('Unlimited');
|
|
|
|
} else {
|
|
|
|
$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
|
|
|
|
}
|
|
|
|
$nav->assign('total_space', $totalSpace);
|
|
|
|
$nav->assign('quota', $storageInfo['quota']);
|
|
|
|
$nav->assign('usage_relative', $storageInfo['relative']);
|
|
|
|
|
2020-01-10 14:11:26 +03:00
|
|
|
$nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user));
|
|
|
|
|
2015-11-16 22:57:41 +03:00
|
|
|
$contentItems = [];
|
|
|
|
|
|
|
|
// render the container content for every navigation item
|
|
|
|
foreach ($navItems as $item) {
|
|
|
|
$content = '';
|
|
|
|
if (isset($item['script'])) {
|
|
|
|
$content = $this->renderScript($item['appname'], $item['script']);
|
|
|
|
}
|
2018-07-13 10:33:57 +03:00
|
|
|
// parse submenus
|
|
|
|
if (isset($item['sublist'])) {
|
|
|
|
foreach ($item['sublist'] as $subitem) {
|
|
|
|
$subcontent = '';
|
|
|
|
if (isset($subitem['script'])) {
|
|
|
|
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
|
|
|
|
}
|
|
|
|
$contentItems[$subitem['id']] = [
|
2020-10-05 16:12:57 +03:00
|
|
|
'id' => $subitem['id'],
|
2018-07-13 10:57:54 +03:00
|
|
|
'content' => $subcontent
|
2018-07-13 10:33:57 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$contentItems[$item['id']] = [
|
2020-10-05 16:12:57 +03:00
|
|
|
'id' => $item['id'],
|
2018-07-13 10:57:54 +03:00
|
|
|
'content' => $content
|
2018-07-13 10:33:57 +03:00
|
|
|
];
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|
|
|
|
|
2019-08-02 21:08:54 +03:00
|
|
|
$event = new LoadAdditionalScriptsEvent();
|
2020-08-10 15:29:21 +03:00
|
|
|
$this->eventDispatcher->dispatchTyped($event);
|
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
|
2020-03-04 15:51:40 +03:00
|
|
|
// Load Viewer scripts
|
|
|
|
if (class_exists(LoadViewer::class)) {
|
2020-03-06 17:44:42 +03:00
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadViewer());
|
2020-03-04 15:51:40 +03:00
|
|
|
}
|
2021-03-15 19:23:30 +03:00
|
|
|
$this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
|
2021-01-12 13:28:04 +03:00
|
|
|
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());
|
2019-10-10 12:26:15 +03:00
|
|
|
|
2020-10-05 16:12:57 +03:00
|
|
|
$params = [];
|
|
|
|
$params['usedSpacePercent'] = (int) $storageInfo['relative'];
|
|
|
|
$params['owner'] = $storageInfo['owner'] ?? '';
|
|
|
|
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? '';
|
|
|
|
$params['isPublic'] = false;
|
2021-04-23 18:29:34 +03:00
|
|
|
$params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no';
|
2020-10-05 16:12:57 +03:00
|
|
|
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
|
2016-04-12 12:51:50 +03:00
|
|
|
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
|
2020-10-05 16:12:57 +03:00
|
|
|
$params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false);
|
2021-02-16 13:36:29 +03:00
|
|
|
$params['isIE'] = \OC_Util::isIe();
|
2020-10-05 16:12:57 +03:00
|
|
|
$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
|
|
|
|
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
|
2021-01-10 11:14:49 +03:00
|
|
|
$cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true);
|
|
|
|
$params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0;
|
2020-10-05 16:12:57 +03:00
|
|
|
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
|
|
|
|
$params['appNavigation'] = $nav;
|
|
|
|
$params['appContents'] = $contentItems;
|
|
|
|
$params['hiddenFields'] = $event->getHiddenFields();
|
2015-11-16 22:57:41 +03:00
|
|
|
|
2015-12-02 19:30:40 +03:00
|
|
|
$response = new TemplateResponse(
|
2015-11-16 22:57:41 +03:00
|
|
|
$this->appName,
|
|
|
|
'index',
|
|
|
|
$params
|
|
|
|
);
|
2015-12-02 19:30:40 +03:00
|
|
|
$policy = new ContentSecurityPolicy();
|
|
|
|
$policy->addAllowedFrameDomain('\'self\'');
|
|
|
|
$response->setContentSecurityPolicy($policy);
|
|
|
|
|
|
|
|
return $response;
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects to the file list and highlight the given file id
|
|
|
|
*
|
|
|
|
* @param string $fileId file id to show
|
2016-06-07 14:51:16 +03:00
|
|
|
* @return RedirectResponse redirect response or not found response
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
2016-05-04 11:28:06 +03:00
|
|
|
*/
|
2019-03-14 17:12:16 +03:00
|
|
|
private function redirectToFile($fileId) {
|
2020-10-05 16:12:57 +03:00
|
|
|
$uid = $this->userSession->getUser()->getUID();
|
2016-08-19 09:15:30 +03:00
|
|
|
$baseFolder = $this->rootFolder->getUserFolder($uid);
|
2020-10-05 16:12:57 +03:00
|
|
|
$files = $baseFolder->getById($fileId);
|
|
|
|
$params = [];
|
2016-05-11 20:41:36 +03:00
|
|
|
|
2016-06-07 14:51:16 +03:00
|
|
|
if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
|
2020-10-05 16:12:57 +03:00
|
|
|
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
|
|
|
|
$files = $baseFolder->getById($fileId);
|
2016-06-07 14:51:16 +03:00
|
|
|
$params['view'] = 'trashbin';
|
|
|
|
}
|
2016-05-04 11:28:06 +03:00
|
|
|
|
2016-06-07 14:51:16 +03:00
|
|
|
if (!empty($files)) {
|
|
|
|
$file = current($files);
|
|
|
|
if ($file instanceof Folder) {
|
|
|
|
// set the full path to enter the folder
|
|
|
|
$params['dir'] = $baseFolder->getRelativePath($file->getPath());
|
|
|
|
} else {
|
|
|
|
// set parent path as dir
|
|
|
|
$params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
|
|
|
|
// and scroll to the entry
|
|
|
|
$params['scrollto'] = $file->getName();
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
2018-07-13 10:57:54 +03:00
|
|
|
|
2016-06-07 14:51:16 +03:00
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
2016-06-07 14:51:16 +03:00
|
|
|
throw new \OCP\Files\NotFoundException();
|
2016-05-04 11:28:06 +03:00
|
|
|
}
|
2015-11-16 22:57:41 +03:00
|
|
|
}
|