added admin settings service and api; made filesystem paths configurable; added babel config; added admin settings webpack config

This commit is contained in:
Jonathan Treffler 2024-04-23 19:51:41 +02:00 committed by root
parent 188ea3dfa9
commit b79f6cab6b
12 changed files with 10224 additions and 32 deletions

View file

@ -0,0 +1,47 @@
<?php
namespace OCA\GroupfolderFilesystemSnapshots\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCA\GroupfolderFilesystemSnapshots\AppInfo\Application;
use OCA\GroupfolderFilesystemSnapshots\Service\SettingsService;
class AdminSettingsController extends Controller {
public function __construct(
private SettingsService $settingsService,
) {
parent::__construct(
Application::APP_ID,
\OC::$server->get(IRequest::class),
);
}
/**
* @return JSONResponse
*/
public function index(): JSONResponse {
return new JSONResponse($this->settingsService->getAppValues());
}
/**
* @param $key
*
* @return JSONResponse
*/
public function show($key): JSONResponse {
return new JSONResponse($this->settingsService->getAppValue($key));
}
/**
* @param $key
* @param $value
*
* @return JSONResponse
*/
public function update($key, $value): JSONResponse {
return new JSONResponse($this->settingsService->setAppValue($key, $value));
}
}

View file

@ -4,33 +4,30 @@ namespace OCA\GroupfolderFilesystemSnapshots\Manager;
use OCP\IConfig;
use OCP\Files\IRootFolder;
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Mount\MountProvider;
class PathManager {
private IConfig $config;
private IRootFolder $rootFolder;
private FolderManager $groupfolderFolderManager;
/** @var MountProvider */
protected $mountProvider;
use OCA\GroupfolderFilesystemSnapshots\Service\SettingsService;
const FILESYSTEM_ROOT_PATH = "/srv/nextcloud/files/";
const FILESYSTEM_SNAPSHOT_PATH = "/srv/nextcloud/files/.zfs/snapshot/";
class PathManager {
//const FILESYSTEM_ROOT_PATH = "/srv/nextcloud/files/";
//const FILESYSTEM_SNAPSHOT_PATH = "/srv/nextcloud/files/.zfs/snapshot/";
public function __construct(
IConfig $config,
IRootFolder $rootFolder,
FolderManager $manager,
MountProvider $mountProvider,
){
$this->config = $config;
$this->groupfolderFolderManager = $manager;
$this->rootFolder = $rootFolder;
$this->mountProvider = $mountProvider;
private IConfig $config,
private IRootFolder $rootFolder,
private FolderManager $groupfolderFolderManager,
private MountProvider $mountProvider,
private SettingsService $settingsService,
){}
public function getFilesystemMountpointPath() {
return $this->settingsService->getAppValue("filesystem_mountpoint_path");
}
public function getFilesystemSnapshotPath() {
return self::FILESYSTEM_SNAPSHOT_PATH;
public function getFilesystemSnapshotsPath() {
return $this->settingsService->getAppValue("filesystem_snapshots_path");
}
// Nextcloud general
@ -44,17 +41,22 @@ class PathManager {
// Snapshots
public function getSnapshotPath(string $snapshotId) {
return realpath(self::FILESYSTEM_SNAPSHOT_PATH . DIRECTORY_SEPARATOR . $snapshotId . DIRECTORY_SEPARATOR);
return realpath($this->getFilesystemSnapshotsPath() . DIRECTORY_SEPARATOR . $snapshotId . DIRECTORY_SEPARATOR);
}
public function convertToSnapshotPath(string $filesystemPath, string $snapshotId) {
$filesystemMountpointPath = $this->getFilesystemMountpointPath();
$filesystemPath = realpath($filesystemPath);
if(!str_starts_with($filesystemPath, self::FILESYSTEM_ROOT_PATH)) {
if($filesystemMountpointPath == '') {
return false;
}
return str_replace(self::FILESYSTEM_ROOT_PATH, $this->getSnapshotPath($snapshotId) . DIRECTORY_SEPARATOR, $filesystemPath);
if(!str_starts_with($filesystemPath, $filesystemMountpointPath)) {
return false;
}
return str_replace($filesystemMountpointPath, $this->getSnapshotPath($snapshotId) . DIRECTORY_SEPARATOR, $filesystemPath);
}
// Groupfolders

View file

@ -37,7 +37,7 @@ class SnapshotManager {
}
function getAll() {
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotPath());
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotsPath());
foreach ($iterator as $fileinfo) {
if(!$fileinfo->isDir()) continue;
yield new Snapshot($fileinfo->getFilename());

View file

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace OCA\GroupfolderFilesystemSnapshots\Service;
use OCA\GroupfolderFilesystemSnapshots\AppInfo\Application;
use OCP\IConfig;
class SettingsService {
private static array $VALID_APP_SETTINGS = ["filesystem_mountpoint_path", "filesystem_snapshots_path"];
public function __construct(private IConfig $config) {
}
public function getAppValues(): array {
$result = [];
foreach(self::$VALID_APP_SETTINGS as $key) {
$result[$key] = $this->config->getAppValue(Application::APP_ID, $key);
}
return $result;
}
public function getAppValue(string $key): string {
if(in_array($key, self::$VALID_APP_SETTINGS)) {
return $this->config->getAppValue(Application::APP_ID, $key);
}
}
public function setAppValue(string $key, string $value): string {
if(in_array($key, self::$VALID_APP_SETTINGS)) {
if($value !== '') {
$this->config->setAppValue(Application::APP_ID, $key, $value);
} else {
$this->config->deleteAppValue(Application::APP_ID, $key);
}
return $value;
}
}
}

View file

@ -2,25 +2,18 @@
namespace OCA\GroupfolderFilesystemSnapshots\Settings;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Settings\ISettings;
class SnapshotsAdmin implements ISettings {
private IConfig $config;
public function __construct(IConfig $config) {
$this->config = $config;
public function __construct() {
}
/**
* @return TemplateResponse
*/
public function getForm() {
$parameters = [
'Filesystem Snapshots Path' => $this->config->getSystemValue('snapshots_path', true),
];
return new TemplateResponse('settings', 'settings/admin', $parameters, '');
return new TemplateResponse('groupfolder_filesystem_snapshots', 'settings/admin');
}
public function getSection() {