added admin settings service and api; made filesystem paths configurable; added babel config; added admin settings webpack config
This commit is contained in:
parent
188ea3dfa9
commit
b79f6cab6b
12 changed files with 10224 additions and 32 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,4 +2,6 @@
|
||||||
*.iml
|
*.iml
|
||||||
/vendor/
|
/vendor/
|
||||||
/build/
|
/build/
|
||||||
|
node_modules/
|
||||||
/.php-cs-fixer.cache
|
/.php-cs-fixer.cache
|
||||||
|
js/*hot-update.*
|
3
babel.config.js
Normal file
3
babel.config.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
const babelConfig = require('@nextcloud/babel-config')
|
||||||
|
|
||||||
|
module.exports = babelConfig
|
47
lib/Controller/AdminSettingsController.php
Normal file
47
lib/Controller/AdminSettingsController.php
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,33 +4,30 @@ namespace OCA\GroupfolderFilesystemSnapshots\Manager;
|
||||||
|
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
|
||||||
use OCA\GroupFolders\Folder\FolderManager;
|
use OCA\GroupFolders\Folder\FolderManager;
|
||||||
use OCA\GroupFolders\Mount\MountProvider;
|
use OCA\GroupFolders\Mount\MountProvider;
|
||||||
|
|
||||||
class PathManager {
|
use OCA\GroupfolderFilesystemSnapshots\Service\SettingsService;
|
||||||
private IConfig $config;
|
|
||||||
private IRootFolder $rootFolder;
|
|
||||||
private FolderManager $groupfolderFolderManager;
|
|
||||||
/** @var MountProvider */
|
|
||||||
protected $mountProvider;
|
|
||||||
|
|
||||||
const FILESYSTEM_ROOT_PATH = "/srv/nextcloud/files/";
|
class PathManager {
|
||||||
const FILESYSTEM_SNAPSHOT_PATH = "/srv/nextcloud/files/.zfs/snapshot/";
|
//const FILESYSTEM_ROOT_PATH = "/srv/nextcloud/files/";
|
||||||
|
//const FILESYSTEM_SNAPSHOT_PATH = "/srv/nextcloud/files/.zfs/snapshot/";
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IConfig $config,
|
private IConfig $config,
|
||||||
IRootFolder $rootFolder,
|
private IRootFolder $rootFolder,
|
||||||
FolderManager $manager,
|
private FolderManager $groupfolderFolderManager,
|
||||||
MountProvider $mountProvider,
|
private MountProvider $mountProvider,
|
||||||
){
|
private SettingsService $settingsService,
|
||||||
$this->config = $config;
|
){}
|
||||||
$this->groupfolderFolderManager = $manager;
|
|
||||||
$this->rootFolder = $rootFolder;
|
public function getFilesystemMountpointPath() {
|
||||||
$this->mountProvider = $mountProvider;
|
return $this->settingsService->getAppValue("filesystem_mountpoint_path");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilesystemSnapshotPath() {
|
public function getFilesystemSnapshotsPath() {
|
||||||
return self::FILESYSTEM_SNAPSHOT_PATH;
|
return $this->settingsService->getAppValue("filesystem_snapshots_path");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nextcloud general
|
// Nextcloud general
|
||||||
|
@ -44,17 +41,22 @@ class PathManager {
|
||||||
|
|
||||||
// Snapshots
|
// Snapshots
|
||||||
public function getSnapshotPath(string $snapshotId) {
|
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) {
|
public function convertToSnapshotPath(string $filesystemPath, string $snapshotId) {
|
||||||
|
$filesystemMountpointPath = $this->getFilesystemMountpointPath();
|
||||||
$filesystemPath = realpath($filesystemPath);
|
$filesystemPath = realpath($filesystemPath);
|
||||||
|
|
||||||
if(!str_starts_with($filesystemPath, self::FILESYSTEM_ROOT_PATH)) {
|
if($filesystemMountpointPath == '') {
|
||||||
return false;
|
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
|
// Groupfolders
|
||||||
|
|
|
@ -37,7 +37,7 @@ class SnapshotManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAll() {
|
function getAll() {
|
||||||
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotPath());
|
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotsPath());
|
||||||
foreach ($iterator as $fileinfo) {
|
foreach ($iterator as $fileinfo) {
|
||||||
if(!$fileinfo->isDir()) continue;
|
if(!$fileinfo->isDir()) continue;
|
||||||
yield new Snapshot($fileinfo->getFilename());
|
yield new Snapshot($fileinfo->getFilename());
|
||||||
|
|
42
lib/Service/SettingsService.php
Normal file
42
lib/Service/SettingsService.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,25 +2,18 @@
|
||||||
namespace OCA\GroupfolderFilesystemSnapshots\Settings;
|
namespace OCA\GroupfolderFilesystemSnapshots\Settings;
|
||||||
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\IConfig;
|
|
||||||
use OCP\Settings\ISettings;
|
use OCP\Settings\ISettings;
|
||||||
|
|
||||||
class SnapshotsAdmin implements ISettings {
|
class SnapshotsAdmin implements ISettings {
|
||||||
private IConfig $config;
|
|
||||||
|
|
||||||
public function __construct(IConfig $config) {
|
public function __construct() {
|
||||||
$this->config = $config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TemplateResponse
|
* @return TemplateResponse
|
||||||
*/
|
*/
|
||||||
public function getForm() {
|
public function getForm() {
|
||||||
$parameters = [
|
return new TemplateResponse('groupfolder_filesystem_snapshots', 'settings/admin');
|
||||||
'Filesystem Snapshots Path' => $this->config->getSystemValue('snapshots_path', true),
|
|
||||||
];
|
|
||||||
|
|
||||||
return new TemplateResponse('settings', 'settings/admin', $parameters, '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSection() {
|
public function getSection() {
|
||||||
|
|
10047
package-lock.json
generated
Normal file
10047
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
39
package.json
Normal file
39
package.json
Normal 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
0
src/adminSettings.js
Normal file
6
templates/settings/admin.php
Normal file
6
templates/settings/admin.php
Normal 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
11
webpack.config.js
Normal 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
|
Loading…
Reference in a new issue