refactor: move utils to Util from Exif
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/579/head
parent
14011dc5fd
commit
265c0f795c
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
|||
namespace OCA\Memories\Controller;
|
||||
|
||||
use OCA\Memories\Exceptions;
|
||||
use OCA\Memories\Exif;
|
||||
use OCA\Memories\Util;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
@ -57,7 +56,7 @@ class ArchiveController extends GenericApiController
|
|||
}
|
||||
|
||||
// Create archive folder in the root of the user's configured timeline
|
||||
$configPaths = Exif::getTimelinePaths(Util::getUID());
|
||||
$configPaths = Util::getTimelinePaths(Util::getUID());
|
||||
$timelineFolders = [];
|
||||
$timelinePaths = [];
|
||||
|
||||
|
@ -134,7 +133,7 @@ class ArchiveController extends GenericApiController
|
|||
} else {
|
||||
// file not in archive, put it in there
|
||||
$af = \OCA\Memories\Util::$ARCHIVE_FOLDER;
|
||||
$destinationPath = Exif::sanitizePath($af.$relativeFilePath);
|
||||
$destinationPath = Util::sanitizePath($af.$relativeFilePath);
|
||||
}
|
||||
|
||||
// Remove the filename
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace OCA\Memories\Controller;
|
|||
use OCA\Memories\AppInfo\Application;
|
||||
use OCA\Memories\Db\FsManager;
|
||||
use OCA\Memories\Db\TimelineQuery;
|
||||
use OCA\Memories\Util;
|
||||
use OCP\AppFramework\AuthPublicShareController;
|
||||
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
|
@ -19,7 +20,6 @@ use OCP\IURLGenerator;
|
|||
use OCP\IUserSession;
|
||||
use OCP\Share\IManager as IShareManager;
|
||||
use OCP\Share\IShare;
|
||||
use OCP\Util;
|
||||
|
||||
class PublicController extends AuthPublicShareController
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ class PublicController extends AuthPublicShareController
|
|||
\OC_User::setIncognitoMode(true);
|
||||
|
||||
// Scripts
|
||||
Util::addScript($this->appName, 'memories-main');
|
||||
\OCP\Util::addScript($this->appName, 'memories-main');
|
||||
PageController::provideCommonInitialState($this->initialState);
|
||||
|
||||
// Share info
|
||||
|
@ -125,7 +125,7 @@ class PublicController extends AuthPublicShareController
|
|||
// Add OG metadata
|
||||
$params = ['token' => $this->getToken()];
|
||||
$url = $this->urlGenerator->linkToRouteAbsolute('memories.Public.showShare', $params);
|
||||
\OCA\Memories\Util::addOgMetadata($node, $node->getName(), $url, $params);
|
||||
Util::addOgMetadata($node, $node->getName(), $url, $params);
|
||||
|
||||
// Render the template
|
||||
$response = new PublicTemplateResponse($this->appName, 'main');
|
||||
|
@ -195,7 +195,7 @@ class PublicController extends AuthPublicShareController
|
|||
// Get the user's folders path
|
||||
$foldersPath = $this->config->getUserValue($user->getUID(), Application::APPNAME, 'foldersPath', '');
|
||||
$foldersPath = $foldersPath ?: '/';
|
||||
$foldersPath = \OCA\Memories\Exif::sanitizePath($foldersPath);
|
||||
$foldersPath = Util::sanitizePath($foldersPath);
|
||||
|
||||
// Check if relPath starts with foldersPath
|
||||
if (0 !== strpos($relPath, $foldersPath)) {
|
||||
|
|
|
@ -26,7 +26,6 @@ namespace OCA\Memories\Db;
|
|||
use OC\Files\Search\SearchComparison;
|
||||
use OC\Files\Search\SearchQuery;
|
||||
use OCA\Memories\Exceptions;
|
||||
use OCA\Memories\Exif;
|
||||
use OCA\Memories\Util;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
|
@ -103,13 +102,13 @@ class FsManager
|
|||
|
||||
try {
|
||||
if (null !== $folderPath) {
|
||||
$folder = $userFolder->get(Exif::sanitizePath($folderPath));
|
||||
$folder = $userFolder->get(Util::sanitizePath($folderPath));
|
||||
$root->addFolder($folder);
|
||||
} else {
|
||||
// Get timeline paths
|
||||
$paths = Exif::getTimelinePaths($uid);
|
||||
$paths = Util::getTimelinePaths($uid);
|
||||
if ($path = $this->request->getParam('timelinePath', null)) {
|
||||
$paths = [Exif::sanitizePath($path)];
|
||||
$paths = [Util::sanitizePath($path)];
|
||||
}
|
||||
|
||||
// Combined etag, for cache invalidation.
|
||||
|
|
30
lib/Exif.php
30
lib/Exif.php
|
@ -7,7 +7,6 @@ namespace OCA\Memories;
|
|||
use OCA\Memories\AppInfo\Application;
|
||||
use OCA\Memories\Service\BinExt;
|
||||
use OCP\Files\File;
|
||||
use OCP\IConfig;
|
||||
|
||||
class Exif
|
||||
{
|
||||
|
@ -65,35 +64,6 @@ class Exif
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of timeline paths as array.
|
||||
*/
|
||||
public static function getTimelinePaths(string $uid): array
|
||||
{
|
||||
$config = \OC::$server->get(IConfig::class);
|
||||
$paths = $config->getUserValue($uid, Application::APPNAME, 'timelinePath', null) ?? 'Photos/';
|
||||
|
||||
return array_map(fn ($p) => self::sanitizePath(trim($p)), explode(';', $paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a path to keep only ASCII characters and special characters.
|
||||
*/
|
||||
public static function sanitizePath(string $path)
|
||||
{
|
||||
$path = mb_ereg_replace('([^\\w\\s\\d\\-_~,;:!@#$&*{}\[\]\'\\[\\]\\(\\).\\\/])', '', $path);
|
||||
$path = mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any leading slash present on the path.
|
||||
*/
|
||||
public static function removeLeadingSlash(string $path)
|
||||
{
|
||||
return mb_ereg_replace('~^/+~', '', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get exif data as a JSON object from a Nextcloud file.
|
||||
*/
|
||||
|
|
|
@ -83,7 +83,7 @@ class Index
|
|||
} elseif ('1' === $mode || '0' === $mode) { // everything (or nothing)
|
||||
$paths = ['/'];
|
||||
} elseif ('2' === $mode) { // timeline
|
||||
$paths = \OCA\Memories\Exif::getTimelinePaths($uid);
|
||||
$paths = Util::getTimelinePaths($uid);
|
||||
} elseif ('3' === $mode) { // custom
|
||||
$paths = [Util::getSystemConfig('memories.index.path')];
|
||||
} else {
|
||||
|
|
22
lib/Util.php
22
lib/Util.php
|
@ -7,6 +7,7 @@ namespace OCA\Memories;
|
|||
use OC\Files\Search\SearchBinaryOperator;
|
||||
use OC\Files\Search\SearchComparison;
|
||||
use OC\Files\Search\SearchQuery;
|
||||
use OCA\Memories\AppInfo\Application;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\Files\Node;
|
||||
use OCP\Files\Search\ISearchBinaryOperator;
|
||||
|
@ -282,6 +283,27 @@ class Util
|
|||
return self::getSystemConfig('memories.gis_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of timeline paths as array.
|
||||
*/
|
||||
public static function getTimelinePaths(string $uid): array
|
||||
{
|
||||
$config = \OC::$server->get(IConfig::class);
|
||||
$paths = $config->getUserValue($uid, Application::APPNAME, 'timelinePath', null) ?? 'Photos/';
|
||||
|
||||
return array_map(fn ($p) => self::sanitizePath(trim($p)), explode(';', $paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a path to keep only ASCII characters and special characters.
|
||||
*/
|
||||
public static function sanitizePath(string $path)
|
||||
{
|
||||
$path = mb_ereg_replace('([^\\w\\s\\d\\-_~,;:!@#$&*{}\[\]\'\\[\\]\\(\\).\\\/])', '', $path);
|
||||
|
||||
return mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a system config key with the correct default.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue