2020-01-30 13:37:01 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* @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
|
2020-04-29 12:57:22 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-01-30 13:37:01 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Preview\Storage;
|
|
|
|
|
|
|
|
use OC\Files\AppData\AppData;
|
|
|
|
use OC\SystemConfig;
|
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFolder;
|
|
|
|
|
|
|
|
class Root extends AppData {
|
|
|
|
public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) {
|
|
|
|
parent::__construct($rootFolder, $systemConfig, 'preview');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getFolder(string $name): ISimpleFolder {
|
|
|
|
$internalFolder = $this->getInternalFolder($name);
|
|
|
|
|
2020-07-31 00:53:54 +03:00
|
|
|
try {
|
|
|
|
return parent::getFolder('old-multibucket/' . $internalFolder);
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
// not in multibucket fallback #1
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return parent::getFolder('old-multibucket/' . $name);
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
// not in multibucket fallback #2
|
|
|
|
}
|
|
|
|
|
2020-01-30 13:37:01 +03:00
|
|
|
try {
|
|
|
|
return parent::getFolder($internalFolder);
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
/*
|
|
|
|
* The new folder structure is not found.
|
|
|
|
* Lets try the old one
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getFolder($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newFolder(string $name): ISimpleFolder {
|
|
|
|
$internalFolder = $this->getInternalFolder($name);
|
|
|
|
return parent::newFolder($internalFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not allow directory listing on this special root
|
|
|
|
* since it gets to big and time consuming
|
|
|
|
*/
|
|
|
|
public function getDirectoryListing(): array {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getInternalFolder(string $name): string {
|
|
|
|
return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name;
|
|
|
|
}
|
|
|
|
}
|