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

2
.gitignore vendored
View file

@ -2,4 +2,6 @@
*.iml
/vendor/
/build/
node_modules/
/.php-cs-fixer.cache
js/*hot-update.*

3
babel.config.js Normal file
View file

@ -0,0 +1,3 @@
const babelConfig = require('@nextcloud/babel-config')
module.exports = babelConfig

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() {

10047
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

39
package.json Normal file
View file

@ -0,0 +1,39 @@
{
"name": "groupfolder_filesystem_snapshots",
"description": "App proving a PHP API for other apps, that allows restoring a nextcloud groupfolder to a previous snapshot in the filesystem.",
"version": "1.0.0",
"author": "Jonathan Treffler <mail@jonathan-treffler.de>",
"contributors": [],
"bugs": {
"url": "https://git.verdigado.com/verdigado/nextcloud_groupfolder_filesystem_snapshots/issues"
},
"repository": {
"url": "https://git.verdigado.com/verdigado/nextcloud_groupfolder_filesystem_snapshots",
"type": "git"
},
"homepage": "https://git.verdigado.com/verdigado/nextcloud_groupfolder_filesystem_snapshots",
"license": "agpl",
"private": true,
"scripts": {
"build": "webpack --node-env production --progress",
"dev": "webpack --node-env development --progress",
"watch": "webpack --node-env development --progress --watch"
},
"dependencies": {
"@nextcloud/axios": "^2.3.0",
"@nextcloud/vue": "^7.4.0",
"vue": "^2.7.14"
},
"browserslist": [
"extends @nextcloud/browserslist-config"
],
"engines": {
"node": "^16.0.0",
"npm": "^7.0.0 || ^8.0.0"
},
"devDependencies": {
"@nextcloud/babel-config": "^1.0.0",
"@nextcloud/browserslist-config": "^2.3.0",
"@nextcloud/webpack-vue-config": "^5.4.0"
}
}

0
src/adminSettings.js Normal file
View file

View file

@ -0,0 +1,6 @@
<?php
$appId = OCA\GroupfolderFilesystemSnapshots\AppInfo\Application::APP_ID;
\OCP\Util::addScript($appId, $appId . '-adminSettings');
?>
<div id="groupfolder_filesystem_snapshots_admin_settings"></div>

11
webpack.config.js Normal file
View file

@ -0,0 +1,11 @@
const path = require('path')
const webpackConfig = require('@nextcloud/webpack-vue-config')
webpackConfig.entry = {
"adminSettings": {
import: path.join(__dirname, 'src', 'adminSettings.js'),
}
}
module.exports = webpackConfig