Skip to content

Commit 6a30564

Browse files
committed
fix: trash bin, boolean validation, download scheme, and dependency updates
- Wire elFinder trash bin per volume: assign unique trash dirs under uploads/.bitapps-fm-trash/{n}/ (writable path), set explicit volume id on each trash FileRoot so trashHash resolves correctly for restore - Add custom BooleanRule class; remove conflicting sanitize:text from boolean fields in Settings and Permissions request validators - Normalize AJAX URL scheme client-side to fix insecure-download warning behind SSL-terminating reverse proxies - Wrap elfinder-editors.js in jQuery IIFE via Vite writeBundle plugin - Upgrade frontend deps: React 19, antd 6, react-query 5, TypeScript 6, Vite 8, ESLint 10 (flat config) Assisted-By: AI
1 parent 4534178 commit 6a30564

55 files changed

Lines changed: 4000 additions & 4133 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 136 deletions
This file was deleted.

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "submodule/sources/elFinder"]
2-
path = submodule/sources/elFinder
3-
url = git@github.com:Bit-Apps-Pro/elFinder.git
41
[submodule "submodule/sources/elFinder-Material-Theme"]
52
path = submodule/sources/elFinder-Material-Theme
63
url = git@github.com:RobiNN1/elFinder-Material-Theme.git

backend/app/Config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ public static function uploadBaseURL()
234234

235235
public static function getTrashDir()
236236
{
237-
return self::uploadBaseDir() . DIRECTORY_SEPARATOR . '.trash';
237+
$uploadDir = wp_upload_dir();
238+
239+
return $uploadDir['basedir'] . DIRECTORY_SEPARATOR . '.bitapps-fm-trash';
238240
}
239241

240242
/**

backend/app/Http/Controllers/FileManagerController.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,49 @@ public function getFinderOptions()
9292
$allVolumes = $this->getFileRoots();
9393
$volumeCount = \count($allVolumes);
9494
$invalidVolumeCount = 0;
95+
96+
$isTrashAllowed = Plugin::instance()->preferences()->isTrashAllowed();
97+
$trashVolumes = [];
98+
9599
foreach ($allVolumes as $root) {
96100
if (!$root->isReadable()) {
97101
$invalidVolumeCount++;
98102

99103
continue;
100104
}
101105

106+
if ($isTrashAllowed) {
107+
// Each volume gets its own trash folder so deletions are isolated.
108+
// Trash driver uses id 't'; Nth trash volume root hash = "t{N}_Lw"
109+
// (base64('/') = 'Lw', the encoded root-relative path '/').
110+
$trashSeq = \count($trashVolumes) + 1;
111+
$trashHash = 't' . $trashSeq . '_Lw';
112+
$trashDir = Config::getTrashDir() . DIRECTORY_SEPARATOR . $trashSeq;
113+
114+
$root->setTrashHash($trashHash);
115+
$trashVolumes[] = $trashDir;
116+
}
117+
102118
$finderOptions->setRoot($root);
103119
}
104120

105121
if ($volumeCount === $invalidVolumeCount) {
106122
throw new PreCommandException(esc_html__('There is no readable volume. Please select an readable folder from settings', 'file-manager'));
107123
}
108124

125+
foreach ($trashVolumes as $trashSeq => $trashDir) {
126+
if (!is_dir($trashDir)) {
127+
wp_mkdir_p($trashDir);
128+
}
129+
130+
if (is_dir($trashDir)) {
131+
$trashRoot = new FileRoot($trashDir, '', 'Trash', 'Trash');
132+
// Explicitly set id so the volume hash is predictable: t{trashSeq}_Lw
133+
$trashRoot->setOption('id', $trashSeq + 1);
134+
$finderOptions->setRoot($trashRoot);
135+
}
136+
}
137+
109138
return $finderOptions;
110139
}
111140

backend/app/Http/Requests/Permissions/PermissionsUpdateRequest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
exit;
77
}
88

9+
use BitApps\FM\Http\Rules\BooleanRule;
910
use BitApps\FM\Http\Rules\ValidateCommandsRule;
1011
use BitApps\FM\Http\Rules\ValidateRolesRule;
1112
use BitApps\FM\Http\Rules\ValidateUsersRule;
@@ -23,7 +24,7 @@ public function authorize()
2324
public function rules()
2425
{
2526
return [
26-
'do_not_use_for_admin' => ['sanitize:text', 'nullable','boolean'],
27+
'do_not_use_for_admin' => ['nullable', BooleanRule::class],
2728
'fileType' => ['nullable','array'],
2829
'file_size' => ['sanitize:text', 'nullable','Integer'],
2930
'root_folder' => ['sanitize:text', 'nullable', ValidPathRule::class],
@@ -36,7 +37,7 @@ public function rules()
3637
'by_role.*.path' => ['nullable', ValidPathRule::class],
3738
'by_role.*.commands' => ['nullable', ValidateCommandsRule::class],
3839
'guest.path' => ['sanitize:text', 'nullable','string', ValidPathRule::class],
39-
'guest.can_download' => ['sanitize:text', 'nullable', 'boolean'],
40+
'guest.can_download' => ['nullable', BooleanRule::class],
4041
];
4142
}
4243
}

backend/app/Http/Requests/Settings/SettingsUpdateRequest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
exit;
77
}
88

9+
use BitApps\FM\Http\Rules\BooleanRule;
910
use BitApps\FM\Http\Rules\ValidPathRule;
1011
use BitApps\FM\Http\Rules\ValidUIOptionRule;
1112
use BitApps\FM\Vendor\BitApps\WPKit\Http\Request\Request;
@@ -21,13 +22,13 @@ public function authorize()
2122
public function rules()
2223
{
2324
return [
24-
'show_url_path' => ['sanitize:text', 'nullable','boolean'],
25-
'show_hidden_files' => ['sanitize:text', 'nullable','boolean'],
26-
'wp_media_sync' => ['sanitize:text', 'nullable','boolean'],
27-
'create_trash_files_folders' => ['sanitize:text', 'nullable','boolean'],
28-
'create_hidden_files_folders' => ['sanitize:text', 'nullable','boolean'],
29-
'remember_last_dir' => ['sanitize:text', 'nullable','boolean'],
30-
'clear_history_on_reload' => ['sanitize:text', 'nullable','boolean'],
25+
'show_url_path' => ['nullable', BooleanRule::class],
26+
'show_hidden_files' => ['nullable', BooleanRule::class],
27+
'wp_media_sync' => ['nullable', BooleanRule::class],
28+
'create_trash_files_folders' => ['nullable', BooleanRule::class],
29+
'create_hidden_files_folders' => ['nullable', BooleanRule::class],
30+
'remember_last_dir' => ['nullable', BooleanRule::class],
31+
'clear_history_on_reload' => ['nullable', BooleanRule::class],
3132
'root_folder_name' => ['sanitize:text', 'required','string'],
3233
'theme' => ['sanitize:text', 'required','string'],
3334
'language' => ['sanitize:text', 'required','string'],
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace BitApps\FM\Http\Rules;
4+
5+
if (! \defined('ABSPATH')) {
6+
exit;
7+
}
8+
9+
use BitApps\FM\Vendor\BitApps\WPValidator\Rule;
10+
11+
class BooleanRule extends Rule
12+
{
13+
private $_message = 'The :attribute field must be true or false';
14+
15+
public function validate($value): bool
16+
{
17+
return \in_array($value, [true, false, 'true', 'false', '1', '0', 1, 0, 'on', 'off', 'yes', 'no'], true);
18+
}
19+
20+
public function message()
21+
{
22+
return $this->_message;
23+
}
24+
}

backend/app/Providers/FileManager/FileRoot.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace BitApps\FM\Providers\FileManager;
44

5+
use function BitApps\FM\Functions\fileSystemAdapter;
6+
57
use Exception;
68

79
\defined('ABSPATH') || exit();
@@ -527,7 +529,7 @@ public function __construct($path, $url, $alias = null, $driver = 'LocalFileSyst
527529
*/
528530
public function isReadable()
529531
{
530-
return is_readable($this->_path);
532+
return fileSystemAdapter()->is_readable($this->_path);
531533
}
532534

533535
/**
216 KB
Loading

0 commit comments

Comments
 (0)