Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
997e5067d3 | ||
|
|
1c0ac50048 | ||
|
|
8fc716387b | ||
|
|
fe3a58924b | ||
|
|
47b4cc4489 | ||
|
|
3f0d1780a1 | ||
|
|
3b62e27c7c | ||
|
|
f967134631 | ||
|
|
6b93d65d6a |
101
CHANGELOG.md
101
CHANGELOG.md
@@ -1,5 +1,106 @@
|
||||
# Changelog
|
||||
|
||||
## Changes 11/28/2025 (v2.2.1)
|
||||
|
||||
release(v2.2.1): fix(storage-explorer): DOM-safe rendering + docs for disk usage
|
||||
|
||||
- Refactor adminStorage breadcrumb builder to construct DOM nodes instead of using innerHTML.
|
||||
- Rework Storage explorer folder view to render rows via createElement/textContent, avoiding DOM text reinterpreted as HTML.
|
||||
- Keep deep-delete and pagination behavior unchanged while tightening up XSS/CodeQL concerns.
|
||||
- Update README feature list to mention disk usage summary and Pro storage explorer (ncdu-style) alongside user groups and client portals.
|
||||
|
||||
## Changes 11/28/2025 (v2.2.0)
|
||||
|
||||
release(v2.2.0): add storage explorer + disk usage scanner
|
||||
|
||||
- New **Storage / Disk Usage** admin section with snapshot-based totals and "Top folders by size".
|
||||
- Disk usage CLI scanner (`src/cli/disk_usage_scan.php`) and background rescan endpoint.
|
||||
|
||||
- New **Storage Explorer** (drilldown, top files view, deep-delete actions) available in FileRise Pro v1.2.0.
|
||||
- Non-Pro installsshow a blurred preview of the explorer with upgrade prompts.
|
||||
|
||||
Features
|
||||
|
||||
- Add new "Storage / Disk Usage" section to the Admin Panel with a summary card and "Top folders by size" table.
|
||||
- Introduce CLI disk usage scanner (src/cli/disk_usage_scan.php) that walks UPLOAD_DIR, applies FS::IGNORE()/SKIP(), and persists a structured snapshot to META_DIR/disk_usage.json.
|
||||
- Add /api/admin/diskUsageSummary.php and /api/admin/diskUsageTriggerScan.php endpoints to expose the snapshot and trigger background rescans from the UI.
|
||||
- Wire the new storage section into adminPanel.js with a Rescan button that launches the CLI worker and polls for a fresh snapshot.
|
||||
|
||||
Improvements
|
||||
|
||||
- Storage summary now shows total files, folders, scan duration, and last scan time, plus grouped volume usage across Uploads / Users / Metadata when available.
|
||||
- "Top folders by size" table supports a Pro-only "show more" interaction, but still provides a clean preview in the core edition.
|
||||
- Slight spacing / layout tweaks so the Storage card doesn’t sit flush against the Admin Panel header.
|
||||
|
||||
Pro integration
|
||||
|
||||
- Keep the full ncdu-style "Storage explorer" (per-folder drilldown + global Top files, deep delete toggle, size filters, etc.) behind FR_PRO_ACTIVE via /api/pro/diskUsageChildren.php and /api/pro/diskUsageTopFiles.php.
|
||||
- Pro-only delete-from-explorer actions are exposed via /api/pro/diskUsageDeleteFilePermanent.php and /api/pro/diskUsageDeleteFolderRecursive.php, reusing FileModel and FolderModel admin helpers.
|
||||
- Non-Pro instances still see the explorer teaser, but the table body is blurred and padded with "Pro" badges, clearly advertising the upgrade path without exposing the Pro internals.
|
||||
|
||||
DX / internals
|
||||
|
||||
- Centralize disk usage logic in DiskUsageModel: snapshot builder, summary (including volumes), per-folder children view, and global Top N file listing.
|
||||
- Ensure adminStorage.js is idempotent and safe to re-init when the Admin Panel is reopened (guards on data-* flags, re-wires only once).
|
||||
- Add robust PHP-CLI discovery and log output for the disk usage worker, mirroring the existing zip worker pattern.
|
||||
|
||||
---
|
||||
|
||||
## Changes 11/27/2025 (v2.1.0)
|
||||
|
||||
🦃🍂 Happy Thanksgiving. 🥧🍁🍽️
|
||||
|
||||
release(v2.1.0): add header zoom controls, preview tags & modal/dock polish
|
||||
|
||||
- **feat(ux): header zoom controls with persisted app zoom**
|
||||
- Add `zoom.js` with percent-based zoom API (`window.fileriseZoom`) and `--app-zoom` CSS variable.
|
||||
- Wrap the main app in `#appZoomShell` and scale via `transform: scale(var(--app-zoom))` so the whole UI zooms uniformly.
|
||||
- Add header zoom UI (+ / − / 100% reset) and wire it via `data-zoom` buttons.
|
||||
- Persist zoom level in `localStorage` and restore on load.
|
||||
|
||||
- **feat(prefs): user toggle to hide header zoom controls**
|
||||
- Add `hide_header_zoom_controls` i18n key.
|
||||
- Extend the Settings → Display fieldset with “Hide header zoom controls”.
|
||||
- Store preference in `localStorage('hideZoomControls')` and respect it from `appCore.js` when initializing header zoom UI.
|
||||
|
||||
- **feat(preview): show file tags next to preview title**
|
||||
- Add `.title-tags` container in the media viewer header.
|
||||
- When opening a file, look up its `tags` from `fileData` and render them as pill badges beside the filename in the modal top bar.
|
||||
|
||||
- **fix(modals): folder modals always centered above header cards**
|
||||
- Introduce `detachFolderModalsToBody()` in `folderManager.js` and call it on init + before opening create/rename/move/delete modals.
|
||||
- Move those modals under `document.body` with a stable high `z-index`, so they’re not clipped/hidden when the cards live in the header dock.
|
||||
|
||||
- **fix(dnd): header dock & hidden cards container**
|
||||
- Change `#hiddenCardsContainer` from `display:none` to an off-screen absolutely positioned container so card internals (modals/layout) still work while represented as header icons.
|
||||
- Ensure sidebar is always visible as a drop target while dragging (even when panels are collapsed), plus improved highlight & placeholder behavior.
|
||||
|
||||
- **feat(ux): header dock hover/lock polish**
|
||||
- Make header icon buttons share the same hover style as other header buttons.
|
||||
- Add `.is-locked` state so a pinned header icon stays visually “pressed” while its card modal is locked open.
|
||||
|
||||
- **feat(ux): header drop zone and zoom bar layout**
|
||||
- Rework `.header-right` to neatly align zoom controls, header dock, and user buttons.
|
||||
- Add a more flexible `.header-drop-zone` with smooth width/padding transitions and a centered `"Drop Zone"` label when active and empty.
|
||||
- Adjust responsive spacing around zoom controls on smaller screens.
|
||||
|
||||
- **tweak(prefs-modal): improve settings modal sizing**
|
||||
- Increase auth/settings modal `max-height` from 500px to 600px to fit the extra display options without excessive scrolling.
|
||||
|
||||
---
|
||||
|
||||
## Changes 11/26/2025 (v2.0.4)
|
||||
|
||||
release(v2.0.4): harden sessions and align Pro paths with USERS_DIR
|
||||
|
||||
- Enable strict_types in config.php and AdminController
|
||||
- Decouple PHP session lifetime from "remember me" window
|
||||
- Regenerate session ID on persistent token auto-login
|
||||
- Point Pro license / bundle paths at USERS_DIR instead of hardcoded /users
|
||||
- Tweak folder management card drag offset for better alignment
|
||||
|
||||
---
|
||||
|
||||
## Changes 11/26/2025 (v2.0.3)
|
||||
|
||||
release(v2.0.3): polish uploads, header dock, and panel fly animations
|
||||
|
||||
@@ -19,9 +19,10 @@ Drag & drop uploads, ACL-aware sharing, OnlyOffice integration, and a clean UI
|
||||
- 🌳 **Scales to huge trees** – Tested with **100k+ folders** in the sidebar tree.
|
||||
- 🧩 **ONLYOFFICE support (optional)** – Edit DOCX/XLSX/PPTX using your own Document Server.
|
||||
- 🌍 **WebDAV** – Mount FileRise as a drive from macOS, Windows, Linux, or Cyberduck/WinSCP.
|
||||
- 📊 **Storage / disk usage summary** – CLI scanner with snapshots, total usage, and per-volume breakdowns in the admin panel.
|
||||
- 🎨 **Polished UI** – Dark/light mode, responsive layout, in-browser previews & code editor.
|
||||
- 🔑 **Login + SSO** – Local users, TOTP 2FA, and OIDC (Auth0 / Authentik / Keycloak / etc.).
|
||||
- 👥 **User groups & client portals (Pro)** – Group-based ACLs and brandable client upload portals.
|
||||
- 👥 **Pro: user groups, client portals & storage explorer** – Group-based ACLs, brandable client upload portals, and an ncdu-style explorer to drill into folders, largest files, and clean up storage inline.
|
||||
|
||||
Full list of features available at [Full Feature Wiki](https://github.com/error311/FileRise/wiki/Features)
|
||||
|
||||
@@ -194,3 +195,8 @@ It bundles a small set of well‑known client and server libraries (Bootstrap, C
|
||||
All third‑party code remains under its original licenses.
|
||||
|
||||
See `THIRD_PARTY.md` and the `licenses/` folder for full details.
|
||||
|
||||
## 8. Press
|
||||
|
||||
- [Heise / iX Magazin – “FileRise 2.0: Web-Dateimanager mit Client Portals” (DE)](https://www.heise.de/news/FileRise-2-0-Web-Dateimanager-mit-Client-Portals-11092171.html)
|
||||
- [Heise / iX Magazin – “FileRise 2.0: Web File Manager with Client Portals” (EN)](https://www.heise.de/en/news/FileRise-2-0-Web-File-Manager-with-Client-Portals-11092376.html)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
// config.php
|
||||
|
||||
// Define constants
|
||||
@@ -101,10 +102,15 @@ $secure = ($envSecure !== false)
|
||||
? filter_var($envSecure, FILTER_VALIDATE_BOOLEAN)
|
||||
: (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
|
||||
|
||||
// Choose session lifetime based on "remember me" cookie
|
||||
|
||||
// PHP session lifetime (independent of "remember me")
|
||||
// Keep this reasonably short; "remember me" uses its own token.
|
||||
$defaultSession = 7200; // 2 hours
|
||||
$sessionLifetime = $defaultSession;
|
||||
|
||||
// "Remember me" window (how long the persistent token itself is valid)
|
||||
// This is used in persistent_tokens.json, *not* for PHP session lifetime.
|
||||
$persistentDays = 30 * 24 * 60 * 60; // 30 days
|
||||
$sessionLifetime = isset($_COOKIE['remember_me_token']) ? $persistentDays : $defaultSession;
|
||||
|
||||
/**
|
||||
* Start session idempotently:
|
||||
@@ -155,6 +161,11 @@ if (empty($_SESSION["authenticated"]) && !empty($_COOKIE['remember_me_token']))
|
||||
if (!empty($tokens[$token])) {
|
||||
$data = $tokens[$token];
|
||||
if ($data['expiry'] >= time()) {
|
||||
// NEW: mitigate session fixation
|
||||
if (session_status() === PHP_SESSION_ACTIVE) {
|
||||
session_regenerate_id(true);
|
||||
}
|
||||
|
||||
$_SESSION["authenticated"] = true;
|
||||
$_SESSION["username"] = $data["username"];
|
||||
$_SESSION["folderOnly"] = loadUserPermissions($data["username"]);
|
||||
@@ -162,7 +173,11 @@ if (empty($_SESSION["authenticated"]) && !empty($_COOKIE['remember_me_token']))
|
||||
} else {
|
||||
// expired — clean up
|
||||
unset($tokens[$token]);
|
||||
file_put_contents($tokFile, encryptData(json_encode($tokens, JSON_PRETTY_PRINT), $encryptionKey), LOCK_EX);
|
||||
file_put_contents(
|
||||
$tokFile,
|
||||
encryptData(json_encode($tokens, JSON_PRETTY_PRINT), $encryptionKey),
|
||||
LOCK_EX
|
||||
);
|
||||
setcookie('remember_me_token', '', time() - 3600, '/', '', $secure, true);
|
||||
}
|
||||
}
|
||||
@@ -253,14 +268,14 @@ if (!defined('FR_PRO_LICENSE')) {
|
||||
|
||||
// JSON license file used by AdminController::setLicense()
|
||||
if (!defined('PRO_LICENSE_FILE')) {
|
||||
define('PRO_LICENSE_FILE', PROJECT_ROOT . '/users/proLicense.json');
|
||||
define('PRO_LICENSE_FILE', rtrim(USERS_DIR, "/\\") . '/proLicense.json');
|
||||
}
|
||||
|
||||
// Optional plain-text license file (used as fallback in bootstrap)
|
||||
if (!defined('FR_PRO_LICENSE_FILE')) {
|
||||
$lf = getenv('FR_PRO_LICENSE_FILE');
|
||||
if ($lf === false || $lf === '') {
|
||||
$lf = PROJECT_ROOT . '/users/proLicense.txt';
|
||||
$lf = rtrim(USERS_DIR, "/\\") . '/proLicense.txt';
|
||||
}
|
||||
define('FR_PRO_LICENSE_FILE', $lf);
|
||||
}
|
||||
@@ -268,7 +283,7 @@ if (!defined('FR_PRO_LICENSE_FILE')) {
|
||||
// Where Pro code lives by default → inside users volume
|
||||
$proDir = getenv('FR_PRO_BUNDLE_DIR');
|
||||
if ($proDir === false || $proDir === '') {
|
||||
$proDir = PROJECT_ROOT . '/users/pro';
|
||||
$proDir = rtrim(USERS_DIR, "/\\") . '/pro';
|
||||
}
|
||||
$proDir = rtrim($proDir, "/\\");
|
||||
if (!defined('FR_PRO_BUNDLE_DIR')) {
|
||||
|
||||
41
public/api/admin/diskUsageSummary.php
Normal file
41
public/api/admin/diskUsageSummary.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// public/api/admin/diskUsageSummary.php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../../../config/config.php';
|
||||
require_once PROJECT_ROOT . '/src/models/DiskUsageModel.php';
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$authenticated = !empty($_SESSION['authenticated']);
|
||||
$isAdmin = !empty($_SESSION['isAdmin']) || (!empty($_SESSION['admin']) && $_SESSION['admin'] === '1');
|
||||
|
||||
if (!$authenticated || !$isAdmin) {
|
||||
http_response_code(401);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'Unauthorized',
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Optional tuning via query params
|
||||
$topFolders = isset($_GET['topFolders']) ? max(1, (int)$_GET['topFolders']) : 5;
|
||||
$topFiles = isset($_GET['topFiles']) ? max(0, (int)$_GET['topFiles']) : 0;
|
||||
|
||||
try {
|
||||
$summary = DiskUsageModel::getSummary($topFolders, $topFiles);
|
||||
http_response_code($summary['ok'] ? 200 : 404);
|
||||
echo json_encode($summary, JSON_UNESCAPED_SLASHES);
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'internal_error',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
102
public/api/admin/diskUsageTriggerScan.php
Normal file
102
public/api/admin/diskUsageTriggerScan.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// public/api/admin/diskUsageTriggerScan.php
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../../../config/config.php';
|
||||
require_once PROJECT_ROOT . '/src/models/DiskUsageModel.php';
|
||||
|
||||
// Basic auth / admin check
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$username = (string)($_SESSION['username'] ?? '');
|
||||
$isAdmin = !empty($_SESSION['isAdmin']) || (!empty($_SESSION['admin']) && $_SESSION['admin'] === '1');
|
||||
|
||||
if ($username === '' || !$isAdmin) {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'Forbidden',
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Release session lock early so the scanner/other requests aren't blocked
|
||||
@session_write_close();
|
||||
|
||||
// NOTE: previously this endpoint was Pro-only. Now it works on all instances.
|
||||
// Pro-only gate removed so free FileRise can also use the Rescan button.
|
||||
|
||||
/*
|
||||
if (!defined('FR_PRO_ACTIVE') || !FR_PRO_ACTIVE) {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'FileRise Pro is not active on this instance.',
|
||||
]);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
$worker = realpath(PROJECT_ROOT . '/src/cli/disk_usage_scan.php');
|
||||
if (!$worker || !is_file($worker)) {
|
||||
throw new RuntimeException('disk_usage_scan.php not found.');
|
||||
}
|
||||
|
||||
// Find a PHP CLI binary that actually works (same idea as zip_worker)
|
||||
$candidates = array_values(array_filter([
|
||||
PHP_BINARY ?: null,
|
||||
'/usr/local/bin/php',
|
||||
'/usr/bin/php',
|
||||
'/bin/php',
|
||||
]));
|
||||
|
||||
$php = null;
|
||||
foreach ($candidates as $bin) {
|
||||
if (!$bin) {
|
||||
continue;
|
||||
}
|
||||
$rc = 1;
|
||||
@exec(escapeshellcmd($bin) . ' -v >/dev/null 2>&1', $out, $rc);
|
||||
if ($rc === 0) {
|
||||
$php = $bin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$php) {
|
||||
throw new RuntimeException('No working php CLI found.');
|
||||
}
|
||||
|
||||
$meta = rtrim((string)META_DIR, '/\\');
|
||||
$logDir = $meta . DIRECTORY_SEPARATOR . 'logs';
|
||||
@mkdir($logDir, 0775, true);
|
||||
$logFile = $logDir . DIRECTORY_SEPARATOR . 'disk_usage_scan.log';
|
||||
|
||||
// nohup php disk_usage_scan.php >> log 2>&1 & echo $!
|
||||
$cmdStr =
|
||||
'nohup ' . escapeshellcmd($php) . ' ' . escapeshellarg($worker) .
|
||||
' >> ' . escapeshellarg($logFile) . ' 2>&1 & echo $!';
|
||||
|
||||
$pid = @shell_exec('/bin/sh -c ' . escapeshellarg($cmdStr));
|
||||
$pid = is_string($pid) ? (int)trim($pid) : 0;
|
||||
|
||||
http_response_code(200);
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'pid' => $pid > 0 ? $pid : null,
|
||||
'message' => 'Disk usage scan started in the background.',
|
||||
'logFile' => $logFile,
|
||||
], JSON_UNESCAPED_SLASHES);
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'internal_error',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
53
public/api/pro/diskUsageChildren.php
Normal file
53
public/api/pro/diskUsageChildren.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// public/api/pro/diskUsageChildren.php
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../../../config/config.php';
|
||||
|
||||
// Basic auth / admin check
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$username = (string)($_SESSION['username'] ?? '');
|
||||
$isAdmin = !empty($_SESSION['isAdmin']) || (!empty($_SESSION['admin']) && $_SESSION['admin'] === '1');
|
||||
|
||||
if ($username === '' || !$isAdmin) {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'Forbidden',
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Release session lock to avoid blocking parallel requests
|
||||
@session_write_close();
|
||||
|
||||
// Pro-only gate: require Pro active AND ProDiskUsage class available
|
||||
if (!defined('FR_PRO_ACTIVE') || !FR_PRO_ACTIVE || !class_exists('ProDiskUsage')) {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'FileRise Pro is not active on this instance.',
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$folderKey = isset($_GET['folder']) ? (string)$_GET['folder'] : 'root';
|
||||
|
||||
try {
|
||||
/** @var array $result */
|
||||
$result = ProDiskUsage::getChildren($folderKey);
|
||||
http_response_code(!empty($result['ok']) ? 200 : 404);
|
||||
echo json_encode($result, JSON_UNESCAPED_SLASHES);
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'internal_error',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
55
public/api/pro/diskUsageDeleteFilePermanent.php
Normal file
55
public/api/pro/diskUsageDeleteFilePermanent.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// public/api/pro/diskUsageDeleteFilePermanent.php
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../../../config/config.php';
|
||||
require_once PROJECT_ROOT . '/src/controllers/AdminController.php';
|
||||
require_once PROJECT_ROOT . '/src/models/FileModel.php';
|
||||
|
||||
// Pro-only gate: make sure Pro is really active
|
||||
if (!defined('FR_PRO_ACTIVE') || !FR_PRO_ACTIVE) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['ok' => false, 'error' => 'FileRise Pro is not active on this instance.']);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['ok' => false, 'error' => 'Method not allowed']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
AdminController::requireAuth();
|
||||
AdminController::requireAdmin();
|
||||
AdminController::requireCsrf();
|
||||
|
||||
$raw = file_get_contents('php://input');
|
||||
$body = json_decode($raw, true);
|
||||
if (!is_array($body) || empty($body['name'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['ok' => false, 'error' => 'Invalid input']);
|
||||
return;
|
||||
}
|
||||
|
||||
$folder = isset($body['folder']) ? (string)$body['folder'] : 'root';
|
||||
$folder = $folder === '' ? 'root' : trim($folder, "/\\ ");
|
||||
$name = (string)$body['name'];
|
||||
|
||||
$res = FileModel::deleteFilesPermanent($folder, [$name]);
|
||||
if (!empty($res['error'])) {
|
||||
echo json_encode(['ok' => false, 'error' => $res['error']]);
|
||||
} else {
|
||||
echo json_encode(['ok' => true, 'success' => $res['success'] ?? 'File deleted.']);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log('diskUsageDeleteFilePermanent error: '.$e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['ok' => false, 'error' => 'Internal error']);
|
||||
}
|
||||
60
public/api/pro/diskUsageDeleteFolderRecursive.php
Normal file
60
public/api/pro/diskUsageDeleteFolderRecursive.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// public/api/pro/diskUsageDeleteFolderRecursive.php
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../../../config/config.php';
|
||||
require_once PROJECT_ROOT . '/src/controllers/AdminController.php';
|
||||
require_once PROJECT_ROOT . '/src/models/FolderModel.php';
|
||||
|
||||
// Pro-only gate
|
||||
if (!defined('FR_PRO_ACTIVE') || !FR_PRO_ACTIVE) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['ok' => false, 'error' => 'FileRise Pro is not active on this instance.']);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['ok' => false, 'error' => 'Method not allowed']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
AdminController::requireAuth();
|
||||
AdminController::requireAdmin();
|
||||
AdminController::requireCsrf();
|
||||
|
||||
$raw = file_get_contents('php://input');
|
||||
$body = json_decode($raw, true);
|
||||
if (!is_array($body) || !isset($body['folder'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['ok' => false, 'error' => 'Invalid input']);
|
||||
return;
|
||||
}
|
||||
|
||||
$folder = (string)$body['folder'];
|
||||
$folder = $folder === '' ? 'root' : trim($folder, "/\\ ");
|
||||
|
||||
if (strtolower($folder) === 'root') {
|
||||
http_response_code(400);
|
||||
echo json_encode(['ok' => false, 'error' => 'Cannot deep delete root folder.']);
|
||||
return;
|
||||
}
|
||||
|
||||
$res = FolderModel::deleteFolderRecursiveAdmin($folder);
|
||||
if (!empty($res['error'])) {
|
||||
echo json_encode(['ok' => false, 'error' => $res['error']]);
|
||||
} else {
|
||||
echo json_encode(['ok' => true, 'success' => $res['success'] ?? 'Folder deleted.']);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log('diskUsageDeleteFolderRecursive error: '.$e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['ok' => false, 'error' => 'Internal error']);
|
||||
}
|
||||
51
public/api/pro/diskUsageTopFiles.php
Normal file
51
public/api/pro/diskUsageTopFiles.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// public/api/pro/diskUsageTopFiles.php
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../../../config/config.php';
|
||||
|
||||
// Basic auth / admin check
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$username = (string)($_SESSION['username'] ?? '');
|
||||
$isAdmin = !empty($_SESSION['isAdmin']) || (!empty($_SESSION['admin']) && $_SESSION['admin'] === '1');
|
||||
|
||||
if ($username === '' || !$isAdmin) {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'Forbidden',
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
@session_write_close();
|
||||
|
||||
// Pro-only gate: require Pro active AND ProDiskUsage class
|
||||
if (!defined('FR_PRO_ACTIVE') || !FR_PRO_ACTIVE || !class_exists('ProDiskUsage')) {
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'FileRise Pro is not active on this instance.',
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$limit = isset($_GET['limit']) ? max(1, (int)$_GET['limit']) : 100;
|
||||
|
||||
try {
|
||||
$result = ProDiskUsage::getTopFiles($limit);
|
||||
http_response_code(!empty($result['ok']) ? 200 : 404);
|
||||
echo json_encode($result, JSON_UNESCAPED_SLASHES);
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'error' => 'internal_error',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
@@ -228,10 +228,7 @@ body{letter-spacing: 0.2px;
|
||||
padding: 9px;}
|
||||
#userDropdownToggle{border-radius: 4px !important;
|
||||
padding: 6px 10px !important;}
|
||||
#headerDropArea.header-drop-zone{display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
min-height: 40px;}
|
||||
|
||||
.header-buttons button:hover{background-color: rgba(122,179,255,.14);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||
color: #fff;}
|
||||
@@ -254,6 +251,49 @@ body{letter-spacing: 0.2px;
|
||||
justify-content: center;}
|
||||
}
|
||||
.header-buttons button i{font-size: 24px;}
|
||||
|
||||
.header-zoom-controls .zoom-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: #fff;
|
||||
border-radius: 50%;
|
||||
padding: 4px;
|
||||
transition: background-color 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.header-zoom-controls .zoom-btn:hover {
|
||||
background-color: rgba(122,179,255,.14);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.header-zoom-controls .zoom-btn .material-icons {
|
||||
font-size: 16px;
|
||||
}
|
||||
.header-buttons button,
|
||||
#headerDropArea .header-card-icon {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: #fff;
|
||||
transition: background-color 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.header-buttons button:not(#userDropdownToggle),
|
||||
#headerDropArea .header-card-icon {
|
||||
border-radius: 50%;
|
||||
padding: 9px;
|
||||
}
|
||||
|
||||
.header-buttons button:hover,
|
||||
#headerDropArea .header-card-icon:hover,
|
||||
#headerDropArea .header-card-icon.is-locked {
|
||||
background-color: rgba(122,179,255,.14) !important;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.dark-mode-toggle{background-color: #424242;
|
||||
border: 1px solid #fff;
|
||||
color: #fff;
|
||||
@@ -272,11 +312,6 @@ body{letter-spacing: 0.2px;
|
||||
.dark-mode .folder-help-tooltip{background-color: #333 !important;
|
||||
color: #eee !important;
|
||||
border: 1px solid #555 !important;}
|
||||
#folderHelpBtn i.material-icons.folder-help-icon{-webkit-text-fill-color: orange !important;
|
||||
color: inherit !important;
|
||||
padding-right: 10px !important;}
|
||||
.dark-mode #folderHelpBtn i.material-icons.folder-help-icon{-webkit-text-fill-color: #ffa500 !important;
|
||||
padding-right: 10px !important;}
|
||||
@media (max-width: 790px) {
|
||||
.header-container{flex-wrap: wrap;
|
||||
height: auto;}
|
||||
@@ -1384,6 +1419,7 @@ label{font-size: 0.9rem;}
|
||||
}
|
||||
#sidebarDropArea.highlight,
|
||||
#uploadFolderRow.highlight{border: 2px dashed #1565C0;
|
||||
border-radius: var(--menu-radius);
|
||||
background-color: #eef;}
|
||||
.drag-header{cursor: grab;
|
||||
user-select: none;
|
||||
@@ -1488,12 +1524,7 @@ body:not(.dark-mode){--download-spinner-color: #000;}
|
||||
.collapse-btn:hover{background: rgba(0, 0, 0, 0.1);}
|
||||
.toggle-modal-btn:focus,
|
||||
.collapse-btn:focus{outline: none;}
|
||||
.header-drop-zone{width: 66px;
|
||||
height: 36px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
display: inline-flex;}
|
||||
|
||||
.header-drop-zone.drag-active{border: 2px dashed #1565C0;
|
||||
background-color: #eef;
|
||||
background-color: transparent;
|
||||
@@ -1502,10 +1533,23 @@ body:not(.dark-mode){--download-spinner-color: #000;}
|
||||
.dark-mode .header-drop-zone.drag-active{background-color: #333;
|
||||
border: 2px dashed #555;
|
||||
color: #fff;}
|
||||
.header-drop-zone.drag-active:empty::before{content: "Drop Zone";
|
||||
font-size: 10px;
|
||||
padding-right: 6px;
|
||||
color: #aaa;}
|
||||
.header-drop-zone {
|
||||
position: relative; /* so ::before can absolutely position inside */
|
||||
}
|
||||
|
||||
.header-drop-zone.drag-active:empty::before {
|
||||
content: "Drop Zone";
|
||||
position: absolute;
|
||||
inset: 0; /* top/right/bottom/left: 0 */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
font-size: 10px;
|
||||
padding-right: 2px;
|
||||
color: #aaa;
|
||||
pointer-events: none; /* optional, so it doesn't block drops */
|
||||
}
|
||||
#fileList tbody tr.clickable-row{-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
@@ -2092,4 +2136,118 @@ body.dark-mode #decreaseFont:not(:disabled):hover,body.dark-mode #increaseFont:n
|
||||
#fileList tr.folder-row.folder-row-droptarget .folder-row-name{font-weight:600}
|
||||
#fileList table.filr-table tbody tr.folder-row>td{padding-top:0!important;padding-bottom:0!important}
|
||||
#fileList table.filr-table tbody tr.folder-row>td.folder-icon-cell{overflow:visible}
|
||||
#fileList tr.folder-row .folder-row-inner,#fileList tr.folder-row .folder-row-name{cursor:inherit}
|
||||
#fileList tr.folder-row .folder-row-inner,#fileList tr.folder-row .folder-row-name{cursor:inherit}
|
||||
|
||||
:root {
|
||||
--app-zoom: 1; /* 1.0 = 100% */
|
||||
}
|
||||
|
||||
#appZoomShell {
|
||||
transform-origin: top left;
|
||||
transform: scale(var(--app-zoom));
|
||||
/* compensate so scaled content still fills the viewport */
|
||||
width: calc(100% / var(--app-zoom));
|
||||
height: calc(100% / var(--app-zoom));
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
|
||||
.header-zoom-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin-right: 10px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
body:not(.dark-mode) .header-zoom-controls .zoom-vertical,
|
||||
body:not(.dark-mode) .header-zoom-controls .zoom-meta,
|
||||
body:not(.dark-mode) .header-zoom-controls .btn-icon.zoom-btn,
|
||||
body:not(.dark-mode) .header-zoom-controls .btn-icon.zoom-btn .material-icons{
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
|
||||
.header-zoom-controls .zoom-vertical,
|
||||
.header-zoom-controls .zoom-meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
.header-zoom-controls .btn-icon.zoom-btn {
|
||||
width: 24px;
|
||||
height: 20px;
|
||||
padding: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Smaller material icons */
|
||||
.header-zoom-controls .btn-icon.zoom-btn .material-icons {
|
||||
font-size: 15px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.zoom-display {
|
||||
min-width: 3ch;
|
||||
text-align: center;
|
||||
font-size: 0.72rem;
|
||||
line-height: 1.1;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.header-right {
|
||||
gap: 8px;
|
||||
}
|
||||
.header-zoom-controls {
|
||||
border-right: none;
|
||||
padding-right: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.header-drop-zone {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 0;
|
||||
margin-right: 0px;
|
||||
min-width: 0;
|
||||
min-height: 50px;
|
||||
flex: 0 0 auto;
|
||||
transition:
|
||||
min-width 0.15s ease,
|
||||
padding 0.15s ease,
|
||||
background-color 0.15s ease,
|
||||
box-shadow 0.15s ease;
|
||||
}
|
||||
|
||||
.header-card-icon {
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.header-card-icon .material-icons {
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.header-drop-zone.drag-active {
|
||||
padding: 0 12px;
|
||||
min-width: 100px;
|
||||
border-radius: 16px;
|
||||
background-color: rgba(255, 255, 255, 0.06);
|
||||
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
<link rel="stylesheet" href="/css/styles.css?v={{APP_QVER}}">
|
||||
<link rel="stylesheet" href="/css/vendor/roboto.css?v={{APP_QVER}}">
|
||||
|
||||
<!-- Fonts (ok to keep as real preloads) -->
|
||||
<!-- Fonts -->
|
||||
<link rel="preload" as="font" href="/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3KUBHMdazTgWw.woff2?v={{APP_QVER}}" type="font/woff2" crossorigin>
|
||||
<link rel="preload" as="font" href="/fonts/roboto/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3yUBHMdazQ.woff2?v={{APP_QVER}}" type="font/woff2" crossorigin>
|
||||
|
||||
@@ -61,7 +61,27 @@
|
||||
<h1>FileRise</h1>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<div class="header-buttons-wrapper" style="display: flex; align-items: center; gap: 10px;">
|
||||
<!-- Zoom controls FIRST on the right -->
|
||||
<div class="header-zoom-controls">
|
||||
<!-- Left stack: + / - -->
|
||||
<div class="zoom-vertical">
|
||||
<button class="btn-icon zoom-btn" data-zoom="in" title="Zoom in">
|
||||
<span class="material-icons">add</span>
|
||||
</button>
|
||||
<button class="btn-icon zoom-btn" data-zoom="out" title="Zoom out">
|
||||
<span class="material-icons">remove</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Right stack: 100% / reset -->
|
||||
<div class="zoom-meta">
|
||||
<span id="zoomDisplay" class="zoom-display">100%</span>
|
||||
<button class="btn-icon zoom-btn" data-zoom="reset" title="Reset zoom">
|
||||
<span class="material-icons">refresh</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-buttons-wrapper" style="display: flex; align-items: center;">
|
||||
|
||||
<div id="headerDropArea" class="header-drop-zone"></div>
|
||||
<div class="header-buttons">
|
||||
@@ -112,6 +132,7 @@
|
||||
<!-- Custom Toast Container -->
|
||||
<div id="customToast"></div>
|
||||
<div id="hiddenCardsContainer" style="display:none;"></div>
|
||||
<div id="appZoomShell">
|
||||
<main id="main" hidden>
|
||||
<div class="row mt-4" id="loginForm">
|
||||
<div class="col-12">
|
||||
@@ -190,10 +211,6 @@
|
||||
<div id="folderManagementCard" class="card" style="width: 100%; position: relative;">
|
||||
<div class="card-header" style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<span data-i18n-key="folder_navigation">Folder Navigation & Management</span>
|
||||
<button id="folderHelpBtn" class="btn btn-link" data-i18n-title="folder_help"
|
||||
style="padding: 0; border: none; background: none;">
|
||||
<i class="material-icons folder-help-icon" style="font-size: 24px;">info</i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body custom-folder-card-body">
|
||||
<div class="form-group d-flex align-items-top" style="padding-top:0; margin-bottom:0;">
|
||||
@@ -276,27 +293,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="folderHelpTooltip" class="folder-help-tooltip"
|
||||
style="display:none;position:absolute;top:50px;right:15px;background:#fff;border:1px solid #ccc;padding:10px;z-index:1000;box-shadow:2px 2px 6px rgba(0,0,0,0.2);border-radius:8px;max-width:320px;line-height:1.35;">
|
||||
<style>
|
||||
/* Dark mode polish */
|
||||
body.dark-mode #folderHelpTooltip {
|
||||
background:#2c2c2c; border-color:#555; color:#e8e8e8; box-shadow:2px 2px 10px rgba(0,0,0,.5);
|
||||
}
|
||||
#folderHelpTooltip .folder-help-list { margin:0; padding-left:18px; }
|
||||
#folderHelpTooltip .folder-help-list li { margin:6px 0; }
|
||||
</style>
|
||||
<ul class="folder-help-list">
|
||||
<li data-i18n-key="folder_help_click_view">Click a folder in the tree to view its files.</li>
|
||||
<li data-i18n-key="folder_help_expand_chevrons">Use chevrons to expand/collapse. Locked folders (padlock) can expand but can’t be opened.</li>
|
||||
<li data-i18n-key="folder_help_context_menu">Right-click a folder for quick actions: Create, Move, Rename, Share, Color, Delete.</li>
|
||||
<li data-i18n-key="folder_help_drag_drop">Drag a folder onto another folder <em>or</em> a breadcrumb to move it.</li>
|
||||
<li data-i18n-key="folder_help_load_more">For long lists, click “Load more” to fetch the next page of folders.</li>
|
||||
<li data-i18n-key="folder_help_last_folder">Your last opened folder is remembered. If you lose access, we pick the first allowed folder automatically.</li>
|
||||
<li data-i18n-key="folder_help_breadcrumbs">Use the breadcrumb to jump up the path. You can also drop onto a breadcrumb.</li>
|
||||
<li data-i18n-key="folder_help_permissions">Buttons enable/disable based on your permissions for the selected folder.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -401,7 +397,7 @@
|
||||
</div> <!-- end container-fluid -->
|
||||
</div> <!-- end mainColumn -->
|
||||
</div> <!-- end main-wrapper -->
|
||||
|
||||
</div>
|
||||
<!-- Download Progress Modal -->
|
||||
<div id="downloadProgressModal" class="modal" style="display: none;">
|
||||
<div class="modal-content" style="text-align: center; padding: 20px;">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1684
public/js/adminStorage.js
Normal file
1684
public/js/adminStorage.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -93,6 +93,24 @@ export function initializeApp() {
|
||||
// default: false (unchecked)
|
||||
window.showFoldersInList = stored === 'true';
|
||||
|
||||
const zoomWrap = document.querySelector('.header-zoom-controls');
|
||||
if (zoomWrap) {
|
||||
const hideZoom = localStorage.getItem('hideZoomControls') === 'true';
|
||||
if (hideZoom) {
|
||||
zoomWrap.style.display = 'none';
|
||||
zoomWrap.setAttribute('aria-hidden', 'true');
|
||||
} else {
|
||||
zoomWrap.style.display = 'flex';
|
||||
zoomWrap.removeAttribute('aria-hidden');
|
||||
}
|
||||
|
||||
// Always load zoom.js once app is running
|
||||
const QVER = (window.APP_QVER && String(window.APP_QVER)) || '{{APP_QVER}}';
|
||||
import(`/js/zoom.js?v=${encodeURIComponent(QVER)}`).catch(err => {
|
||||
console.warn('[zoom] failed to load zoom.js', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Load public site config early (safe subset)
|
||||
loadAdminConfigFunc();
|
||||
|
||||
@@ -176,6 +194,25 @@ export function initializeApp() {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Zoom controls: load only for logged-in app ----
|
||||
(function loadZoomControls() {
|
||||
const zoomWrap = document.querySelector('.header-zoom-controls');
|
||||
if (!zoomWrap) return;
|
||||
|
||||
// show container (keep CSS default = hidden)
|
||||
zoomWrap.style.display = 'flex';
|
||||
zoomWrap.style.alignItems = 'center';
|
||||
|
||||
try {
|
||||
const QVER = (window.APP_QVER && String(window.APP_QVER)) || '{{APP_QVER}}';
|
||||
import(`/js/zoom.js?v=${encodeURIComponent(QVER)}`)
|
||||
.catch(err => console.warn('[zoom] failed to load:', err));
|
||||
} catch (e) {
|
||||
console.warn('[zoom] load error:', e);
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
/* =========================
|
||||
LOGOUT (shared)
|
||||
========================= */
|
||||
|
||||
@@ -195,7 +195,7 @@ export async function openUserPanel() {
|
||||
color: ${isDark ? '#e0e0e0' : '#000'};
|
||||
padding: 20px;
|
||||
max-width: 600px; width:90%;
|
||||
overflow-y: auto; max-height: 500px;
|
||||
overflow-y: auto; max-height: 600px;
|
||||
border: ${isDark ? '1px solid #444' : '1px solid #ccc'};
|
||||
box-sizing: border-box;
|
||||
scrollbar-width: none;
|
||||
@@ -351,66 +351,108 @@ export async function openUserPanel() {
|
||||
langFs.appendChild(langSel);
|
||||
content.appendChild(langFs);
|
||||
|
||||
// --- Display fieldset: strip + inline folder rows ---
|
||||
const dispFs = document.createElement('fieldset');
|
||||
dispFs.style.marginBottom = '15px';
|
||||
|
||||
const dispLegend = document.createElement('legend');
|
||||
dispLegend.textContent = t('display');
|
||||
dispFs.appendChild(dispLegend);
|
||||
|
||||
// 1) Show folder strip above list
|
||||
const stripLabel = document.createElement('label');
|
||||
stripLabel.style.cursor = 'pointer';
|
||||
stripLabel.style.display = 'block';
|
||||
stripLabel.style.marginBottom = '4px';
|
||||
|
||||
const stripCb = document.createElement('input');
|
||||
stripCb.type = 'checkbox';
|
||||
stripCb.id = 'showFoldersInList';
|
||||
stripCb.style.verticalAlign = 'middle';
|
||||
|
||||
{
|
||||
const storedStrip = localStorage.getItem('showFoldersInList');
|
||||
// default: unchecked
|
||||
stripCb.checked = storedStrip === null ? false : storedStrip === 'true';
|
||||
}
|
||||
|
||||
stripLabel.appendChild(stripCb);
|
||||
stripLabel.append(` ${t('show_folders_above_files')}`);
|
||||
dispFs.appendChild(stripLabel);
|
||||
|
||||
// 2) Show inline folder rows above files in table view
|
||||
const inlineLabel = document.createElement('label');
|
||||
inlineLabel.style.cursor = 'pointer';
|
||||
inlineLabel.style.display = 'block';
|
||||
|
||||
const inlineCb = document.createElement('input');
|
||||
inlineCb.type = 'checkbox';
|
||||
inlineCb.id = 'showInlineFolders';
|
||||
inlineCb.style.verticalAlign = 'middle';
|
||||
|
||||
{
|
||||
const storedInline = localStorage.getItem('showInlineFolders');
|
||||
inlineCb.checked = storedInline === null ? true : storedInline === 'true';
|
||||
}
|
||||
|
||||
inlineLabel.appendChild(inlineCb);
|
||||
// you’ll want a string like this in i18n:
|
||||
// "show_inline_folders": "Show folders inline (above files)"
|
||||
inlineLabel.append(` ${t('show_inline_folders') || 'Show folders inline (above files)'}`);
|
||||
dispFs.appendChild(inlineLabel);
|
||||
|
||||
content.appendChild(dispFs);
|
||||
|
||||
// Handlers: toggle + refresh list
|
||||
stripCb.addEventListener('change', () => {
|
||||
window.showFoldersInList = stripCb.checked;
|
||||
localStorage.setItem('showFoldersInList', stripCb.checked);
|
||||
if (typeof window.loadFileList === 'function') {
|
||||
window.loadFileList(window.currentFolder || 'root');
|
||||
}
|
||||
});
|
||||
// --- Display fieldset: strip + inline folder rows ---
|
||||
const dispFs = document.createElement('fieldset');
|
||||
dispFs.style.marginBottom = '15px';
|
||||
|
||||
const dispLegend = document.createElement('legend');
|
||||
dispLegend.textContent = t('display');
|
||||
dispFs.appendChild(dispLegend);
|
||||
|
||||
// 1) Show folder strip above list
|
||||
const stripLabel = document.createElement('label');
|
||||
stripLabel.style.cursor = 'pointer';
|
||||
stripLabel.style.display = 'block';
|
||||
stripLabel.style.marginBottom = '4px';
|
||||
|
||||
const stripCb = document.createElement('input');
|
||||
stripCb.type = 'checkbox';
|
||||
stripCb.id = 'showFoldersInList';
|
||||
stripCb.style.verticalAlign = 'middle';
|
||||
|
||||
{
|
||||
const storedStrip = localStorage.getItem('showFoldersInList');
|
||||
stripCb.checked = storedStrip === null ? false : storedStrip === 'true';
|
||||
}
|
||||
|
||||
stripLabel.appendChild(stripCb);
|
||||
stripLabel.append(` ${t('show_folders_above_files')}`);
|
||||
dispFs.appendChild(stripLabel);
|
||||
|
||||
// 2) Show inline folder rows above files in table view
|
||||
const inlineLabel = document.createElement('label');
|
||||
inlineLabel.style.cursor = 'pointer';
|
||||
inlineLabel.style.display = 'block';
|
||||
|
||||
const inlineCb = document.createElement('input');
|
||||
inlineCb.type = 'checkbox';
|
||||
inlineCb.id = 'showInlineFolders';
|
||||
inlineCb.style.verticalAlign = 'middle';
|
||||
|
||||
{
|
||||
const storedInline = localStorage.getItem('showInlineFolders');
|
||||
inlineCb.checked = storedInline === null ? true : storedInline === 'true';
|
||||
}
|
||||
|
||||
inlineLabel.appendChild(inlineCb);
|
||||
inlineLabel.append(` ${t('show_inline_folders') || 'Show folders inline (above files)'}`);
|
||||
dispFs.appendChild(inlineLabel);
|
||||
|
||||
// 3) Hide header zoom controls
|
||||
const zoomLabel = document.createElement('label');
|
||||
zoomLabel.style.cursor = 'pointer';
|
||||
zoomLabel.style.display = 'block';
|
||||
zoomLabel.style.marginTop = '4px';
|
||||
|
||||
const zoomCb = document.createElement('input');
|
||||
zoomCb.type = 'checkbox';
|
||||
zoomCb.id = 'hideHeaderZoomControls';
|
||||
zoomCb.style.verticalAlign = 'middle';
|
||||
|
||||
{
|
||||
const storedZoom = localStorage.getItem('hideZoomControls');
|
||||
zoomCb.checked = storedZoom === 'true';
|
||||
}
|
||||
|
||||
zoomLabel.appendChild(zoomCb);
|
||||
zoomLabel.append(` ${t('hide_header_zoom_controls') || 'Hide zoom controls in header'}`);
|
||||
dispFs.appendChild(zoomLabel);
|
||||
|
||||
content.appendChild(dispFs);
|
||||
|
||||
// Handlers: toggle + refresh list
|
||||
stripCb.addEventListener('change', () => {
|
||||
window.showFoldersInList = stripCb.checked;
|
||||
localStorage.setItem('showFoldersInList', stripCb.checked);
|
||||
if (typeof window.loadFileList === 'function') {
|
||||
window.loadFileList(window.currentFolder || 'root');
|
||||
}
|
||||
});
|
||||
|
||||
inlineCb.addEventListener('change', () => {
|
||||
window.showInlineFolders = inlineCb.checked;
|
||||
localStorage.setItem('showInlineFolders', inlineCb.checked);
|
||||
if (typeof window.loadFileList === 'function') {
|
||||
window.loadFileList(window.currentFolder || 'root');
|
||||
}
|
||||
});
|
||||
|
||||
// NEW: zoom hide/show handler
|
||||
zoomCb.addEventListener('change', () => {
|
||||
const hideZoom = zoomCb.checked;
|
||||
localStorage.setItem('hideZoomControls', hideZoom ? 'true' : 'false');
|
||||
|
||||
const zoomWrap = document.querySelector('.header-zoom-controls');
|
||||
if (!zoomWrap) return;
|
||||
|
||||
if (hideZoom) {
|
||||
zoomWrap.style.display = 'none';
|
||||
zoomWrap.setAttribute('aria-hidden', 'true');
|
||||
} else {
|
||||
zoomWrap.style.display = 'flex';
|
||||
zoomWrap.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
|
||||
inlineCb.addEventListener('change', () => {
|
||||
window.showInlineFolders = inlineCb.checked;
|
||||
|
||||
@@ -133,7 +133,19 @@ function insertCardInHeader(card) {
|
||||
if (!hidden) {
|
||||
hidden = document.createElement('div');
|
||||
hidden.id = 'hiddenCardsContainer';
|
||||
hidden.style.display = 'none';
|
||||
|
||||
// Park cards off–screen but keep them rendered so modals/layout still work
|
||||
Object.assign(hidden.style, {
|
||||
position: 'absolute',
|
||||
left: '-9999px',
|
||||
top: '0',
|
||||
width: '0',
|
||||
height: '0',
|
||||
overflow: 'visible',
|
||||
pointerEvents: 'none'
|
||||
// **NO** display:none here
|
||||
});
|
||||
|
||||
document.body.appendChild(hidden);
|
||||
}
|
||||
if (card.parentNode?.id !== 'hiddenCardsContainer') hidden.appendChild(card);
|
||||
@@ -212,7 +224,12 @@ function insertCardInHeader(card) {
|
||||
iconButton.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
isLocked = !isLocked;
|
||||
if (isLocked) showModal(); else hideModal();
|
||||
iconButton.classList.toggle('is-locked', isLocked);
|
||||
if (isLocked) {
|
||||
showModal();
|
||||
} else {
|
||||
hideModal();
|
||||
}
|
||||
});
|
||||
|
||||
host.appendChild(iconButton);
|
||||
@@ -524,7 +541,7 @@ function animateCardsOutOfHeaderThen(done) {
|
||||
if (card.id === 'uploadCard') {
|
||||
toCy -= 48; // a bit higher
|
||||
} else if (card.id === 'folderManagementCard') {
|
||||
toCy += 60; // a bit lower
|
||||
toCy += 48; // a bit lower
|
||||
}
|
||||
}
|
||||
|
||||
@@ -941,7 +958,8 @@ function makeCardDraggable(card) {
|
||||
const sb = getSidebar();
|
||||
if (sb) {
|
||||
sb.classList.add('active', 'highlight');
|
||||
if (!isZonesCollapsed()) sb.style.display = 'block';
|
||||
// Always show sidebar as a drop target while dragging
|
||||
sb.style.display = 'block';
|
||||
ensureSidebarPlaceholder(); // make empty sidebar easy to drop into
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,27 @@ export function handleDeleteSelected(e) {
|
||||
attachEnterKeyListener("deleteFilesModal", "confirmDeleteFiles");
|
||||
}
|
||||
|
||||
const FILE_MODAL_IDS = [
|
||||
'deleteFilesModal',
|
||||
'downloadZipModal',
|
||||
'downloadProgressModal',
|
||||
'createFileModal',
|
||||
'downloadFileModal',
|
||||
'copyFilesModal',
|
||||
'moveFilesModal',
|
||||
'renameFileModal',
|
||||
'createFolderModal', // if this exists in your HTML
|
||||
];
|
||||
|
||||
function portalFileModalsToBody() {
|
||||
FILE_MODAL_IDS.forEach(id => {
|
||||
const el = document.getElementById(id);
|
||||
if (el && el.parentNode !== document.body) {
|
||||
document.body.appendChild(el);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// --- Upload modal "portal" support ---
|
||||
let _uploadCardSentinel = null;
|
||||
@@ -818,6 +839,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
// Expose initFileActions so it can be called from fileManager.js
|
||||
export function initFileActions() {
|
||||
portalFileModalsToBody();
|
||||
const deleteSelectedBtn = document.getElementById("deleteSelectedBtn");
|
||||
if (deleteSelectedBtn) {
|
||||
deleteSelectedBtn.replaceWith(deleteSelectedBtn.cloneNode(true));
|
||||
|
||||
@@ -239,7 +239,26 @@ function ensureMediaModal() {
|
||||
</div>`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
// Ensure a container for tags next to the title (created once)
|
||||
(function ensureTitleTagsContainer() {
|
||||
const titleRow = overlay.querySelector('.media-title');
|
||||
if (!titleRow) return;
|
||||
|
||||
let tagsEl = overlay.querySelector('.title-tags');
|
||||
if (!tagsEl) {
|
||||
tagsEl = document.createElement('div');
|
||||
tagsEl.className = 'title-tags';
|
||||
Object.assign(tagsEl.style, {
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
gap: '4px',
|
||||
marginLeft: '6px',
|
||||
maxHeight: '32px',
|
||||
overflow: 'hidden',
|
||||
});
|
||||
titleRow.appendChild(tagsEl);
|
||||
}
|
||||
})();
|
||||
// theme the close “×” for visibility + hover rules that match your site:
|
||||
const closeBtn = overlay.querySelector("#closeFileModal");
|
||||
function paintCloseBase() {
|
||||
@@ -272,17 +291,46 @@ function ensureMediaModal() {
|
||||
function setTitle(overlay, name) {
|
||||
const textEl = overlay.querySelector('.title-text');
|
||||
const iconEl = overlay.querySelector('.title-icon');
|
||||
const tagsEl = overlay.querySelector('.title-tags');
|
||||
|
||||
// File name + tooltip
|
||||
if (textEl) {
|
||||
textEl.textContent = name || '';
|
||||
textEl.setAttribute('title', name || '');
|
||||
}
|
||||
|
||||
// File type icon
|
||||
if (iconEl) {
|
||||
iconEl.textContent = getIconForFile(name);
|
||||
// keep the icon legible in both themes
|
||||
const dark = document.documentElement.classList.contains('dark-mode');
|
||||
iconEl.style.color = dark ? '#f5f5f5' : '#111111';
|
||||
iconEl.style.opacity = dark ? '0.96' : '0.9';
|
||||
}
|
||||
|
||||
// Tag badges next to the title
|
||||
if (tagsEl) {
|
||||
tagsEl.innerHTML = '';
|
||||
|
||||
let fileObj = null;
|
||||
if (Array.isArray(fileData)) {
|
||||
fileObj = fileData.find(f => f.name === name);
|
||||
}
|
||||
|
||||
if (fileObj && Array.isArray(fileObj.tags) && fileObj.tags.length) {
|
||||
fileObj.tags.forEach(tag => {
|
||||
const badge = document.createElement('span');
|
||||
badge.textContent = tag.name;
|
||||
badge.style.backgroundColor = tag.color || '#444';
|
||||
badge.style.color = '#fff';
|
||||
badge.style.padding = '2px 6px';
|
||||
badge.style.borderRadius = '999px';
|
||||
badge.style.fontSize = '0.75rem';
|
||||
badge.style.lineHeight = '1.2';
|
||||
badge.style.whiteSpace = 'nowrap';
|
||||
tagsEl.appendChild(badge);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Topbar icon (theme-aware) used for image tools + video actions
|
||||
|
||||
@@ -10,6 +10,29 @@ import { fetchWithCsrf } from './auth.js?v={{APP_QVER}}';
|
||||
import { loadCsrfToken } from './appCore.js?v={{APP_QVER}}';
|
||||
|
||||
|
||||
function detachFolderModalsToBody() {
|
||||
const ids = [
|
||||
'createFolderModal',
|
||||
'deleteFolderModal',
|
||||
'moveFolderModal',
|
||||
'renameFolderModal',
|
||||
];
|
||||
|
||||
ids.forEach(id => {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
|
||||
if (el.parentNode !== document.body) {
|
||||
document.body.appendChild(el);
|
||||
}
|
||||
|
||||
if (!el.style.zIndex) {
|
||||
el.style.zIndex = '13000';
|
||||
}
|
||||
});
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', detachFolderModalsToBody);
|
||||
|
||||
const PAGE_LIMIT = 100;
|
||||
|
||||
/* ----------------------
|
||||
@@ -1711,6 +1734,7 @@ function bindFolderManagerContextMenu() {
|
||||
Rename / Delete / Create hooks
|
||||
----------------------*/
|
||||
export function openRenameFolderModal() {
|
||||
detachFolderModalsToBody();
|
||||
const selectedFolder = window.currentFolder || "root";
|
||||
if (!selectedFolder || selectedFolder === "root") { showToast("Please select a valid folder to rename."); return; }
|
||||
const parts = selectedFolder.split("/");
|
||||
@@ -1781,6 +1805,7 @@ if (submitRename) submitRename.addEventListener("click", function (event) {
|
||||
});
|
||||
|
||||
export function openDeleteFolderModal() {
|
||||
detachFolderModalsToBody();
|
||||
const selectedFolder = window.currentFolder || "root";
|
||||
if (!selectedFolder || selectedFolder === "root") { showToast("Please select a valid folder to delete."); return; }
|
||||
const msgEl = document.getElementById("deleteFolderMessage");
|
||||
@@ -1823,6 +1848,7 @@ if (confirmDelete) confirmDelete.addEventListener("click", async function () {
|
||||
|
||||
const createBtn = document.getElementById("createFolderBtn");
|
||||
if (createBtn) createBtn.addEventListener("click", function () {
|
||||
detachFolderModalsToBody();
|
||||
const modal = document.getElementById("createFolderModal");
|
||||
const input = document.getElementById("newFolderName");
|
||||
if (modal) modal.style.display = "block";
|
||||
@@ -1885,6 +1911,7 @@ if (submitCreate) submitCreate.addEventListener("click", async () => {
|
||||
Move (modal) + Color carry + State migration as well
|
||||
----------------------*/
|
||||
export function openMoveFolderUI(sourceFolder) {
|
||||
detachFolderModalsToBody();
|
||||
const modal = document.getElementById('moveFolderModal');
|
||||
const targetSel = document.getElementById('moveFolderTarget');
|
||||
if (sourceFolder && sourceFolder !== 'root') window.currentFolder = sourceFolder;
|
||||
|
||||
@@ -35,6 +35,8 @@ const translations = {
|
||||
"tag_name": "Tag Name:",
|
||||
"tag_color": "Tag Color:",
|
||||
"save_tag": "Save Tag",
|
||||
"no_tags_available": "No tags available",
|
||||
"current_tags": "Current Tags",
|
||||
"light_mode": "Light Mode",
|
||||
"dark_mode": "Dark Mode",
|
||||
"upload_instruction": "Drop files/folders here or click 'Choose files'",
|
||||
@@ -337,7 +339,10 @@ const translations = {
|
||||
"size": "Size",
|
||||
"modified": "Modified",
|
||||
"created": "Created",
|
||||
"owner": "Owner"
|
||||
"owner": "Owner",
|
||||
"hide_header_zoom_controls": "Hide header zoom controls",
|
||||
"preview_not_available": "Preview is not available for this file type.",
|
||||
"storage_pro_bundle_outdated": "Please upgrade to the latest FileRise Pro bundle to use the Storage explorer."
|
||||
},
|
||||
es: {
|
||||
"please_log_in_to_continue": "Por favor, inicie sesión para continuar.",
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// generated by CI
|
||||
window.APP_VERSION = 'v2.0.3';
|
||||
window.APP_VERSION = 'v2.2.1';
|
||||
|
||||
92
public/js/zoom.js
Normal file
92
public/js/zoom.js
Normal file
@@ -0,0 +1,92 @@
|
||||
// /js/zoom.js
|
||||
(function () {
|
||||
const MIN_PERCENT = 60; // 60%
|
||||
const MAX_PERCENT = 140; // 140%
|
||||
const STEP_PERCENT = 5; // 5%
|
||||
const STORAGE_KEY = 'filerise.appZoomPercent';
|
||||
|
||||
function clampPercent(p) {
|
||||
return Math.max(MIN_PERCENT, Math.min(MAX_PERCENT, p));
|
||||
}
|
||||
|
||||
function updateDisplay(p) {
|
||||
const el = document.getElementById('zoomDisplay');
|
||||
if (el) el.textContent = `${p}%`;
|
||||
}
|
||||
|
||||
function applyZoomPercent(p) {
|
||||
const clamped = clampPercent(p);
|
||||
const scale = clamped / 100;
|
||||
|
||||
document.documentElement.style.setProperty('--app-zoom', String(scale));
|
||||
try { localStorage.setItem(STORAGE_KEY, String(clamped)); } catch {}
|
||||
|
||||
updateDisplay(clamped);
|
||||
return clamped;
|
||||
}
|
||||
|
||||
function getCurrentPercent() {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (raw) {
|
||||
const n = parseInt(raw, 10);
|
||||
if (Number.isFinite(n) && n > 0) return clampPercent(n);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const v = getComputedStyle(document.documentElement)
|
||||
.getPropertyValue('--app-zoom')
|
||||
.trim();
|
||||
const n = parseFloat(v);
|
||||
if (Number.isFinite(n) && n > 0) {
|
||||
return clampPercent(Math.round(n * 100));
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
|
||||
// Public-ish API (percent-based)
|
||||
window.fileriseZoom = {
|
||||
in() {
|
||||
const next = getCurrentPercent() + STEP_PERCENT;
|
||||
return applyZoomPercent(next);
|
||||
},
|
||||
out() {
|
||||
const next = getCurrentPercent() - STEP_PERCENT;
|
||||
return applyZoomPercent(next);
|
||||
},
|
||||
reset() {
|
||||
return applyZoomPercent(100);
|
||||
},
|
||||
setPercent(p) {
|
||||
return applyZoomPercent(p);
|
||||
},
|
||||
currentPercent: getCurrentPercent
|
||||
};
|
||||
|
||||
function initZoomUI() {
|
||||
// bind buttons
|
||||
const btns = document.querySelectorAll('.zoom-btn[data-zoom]');
|
||||
btns.forEach(btn => {
|
||||
if (btn.__zoomBound) return;
|
||||
btn.__zoomBound = true;
|
||||
|
||||
btn.addEventListener('click', () => {
|
||||
const mode = btn.dataset.zoom;
|
||||
if (mode === 'in') window.fileriseZoom.in();
|
||||
else if (mode === 'out') window.fileriseZoom.out();
|
||||
else if (mode === 'reset') window.fileriseZoom.reset();
|
||||
});
|
||||
});
|
||||
|
||||
// apply initial zoom + update display
|
||||
const initial = getCurrentPercent();
|
||||
applyZoomPercent(initial);
|
||||
}
|
||||
|
||||
// Run immediately if DOM is ready, otherwise wait
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initZoomUI, { once: true });
|
||||
} else {
|
||||
initZoomUI();
|
||||
}
|
||||
})();
|
||||
BIN
resources/StorageDiskUsage.png
Normal file
BIN
resources/StorageDiskUsage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 738 KiB |
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# === Update FileRise to v2.0.2 (safe rsync) ===
|
||||
# === Update FileRise to v2.1.0 (safe rsync, no composer on demo) ===
|
||||
set -Eeuo pipefail
|
||||
|
||||
VER="v2.0.2"
|
||||
VER="v2.1.0"
|
||||
ASSET="FileRise-${VER}.zip" # matches GitHub release asset name
|
||||
|
||||
WEBROOT="/var/www"
|
||||
TMP="/tmp/filerise-update"
|
||||
|
||||
@@ -35,6 +36,7 @@ STAGE_DIR="$(find "$TMP" -maxdepth 1 -type d -name 'FileRise*' ! -path "$TMP" |
|
||||
# - keep public/.htaccess
|
||||
# - keep data dirs and current config.php
|
||||
# - DO NOT touch filerise-site / bundles / demo config
|
||||
# - DO NOT touch vendor/ so Stripe + other libs stay intact on demo
|
||||
rsync -a --delete \
|
||||
--exclude='public/.htaccess' \
|
||||
--exclude='uploads/***' \
|
||||
@@ -43,6 +45,7 @@ rsync -a --delete \
|
||||
--exclude='filerise-bundles/***' \
|
||||
--exclude='filerise-config/***' \
|
||||
--exclude='filerise-site/***' \
|
||||
--exclude='vendor/***' \
|
||||
--exclude='.github/***' \
|
||||
--exclude='docker-compose.yml' \
|
||||
"$STAGE_DIR"/ "$WEBROOT"/
|
||||
@@ -50,23 +53,20 @@ rsync -a --delete \
|
||||
# 4) Ownership (Ubuntu/Debian w/ Apache)
|
||||
chown -R www-data:www-data "$WEBROOT"
|
||||
|
||||
# 5) Composer autoload optimization if composer is available
|
||||
if command -v composer >/dev/null 2>&1; then
|
||||
cd "$WEBROOT" || { echo "cd to $WEBROOT failed" >&2; exit 1; }
|
||||
composer install --no-dev --optimize-autoloader
|
||||
fi
|
||||
# 5) Composer — still disabled on demo
|
||||
# if command -v composer >/dev/null 2>&1; then
|
||||
# cd "$WEBROOT" || { echo "cd to $WEBROOT failed" >&2; exit 1; }
|
||||
# composer install --no-dev --optimize-autoloader
|
||||
# fi
|
||||
|
||||
# 6) Force demo mode ON in config/config.php
|
||||
CFG_FILE="$WEBROOT/config/config.php"
|
||||
if [[ -f "$CFG_FILE" ]]; then
|
||||
# Make a one-time backup of config.php before editing
|
||||
cp "$CFG_FILE" "${CFG_FILE}.bak.$stamp" || true
|
||||
|
||||
# Flip FR_DEMO_MODE to true if it exists as false
|
||||
sed -i "s/define('FR_DEMO_MODE',[[:space:]]*false);/define('FR_DEMO_MODE', true);/" "$CFG_FILE" || true
|
||||
fi
|
||||
|
||||
# 7) Reload Apache (don’t fail the whole script if reload isn’t available)
|
||||
systemctl reload apache2 2>/dev/null || true
|
||||
|
||||
echo "FileRise updated to ${VER} (code). Demo mode forced ON. Data, Pro bundles, and demo site preserved."
|
||||
echo "FileRise updated to ${VER} (code). Demo mode forced ON. Data, Pro bundles, site, and vendor/ (Stripe) preserved."
|
||||
42
src/cli/disk_usage_scan.php
Normal file
42
src/cli/disk_usage_scan.php
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// src/cli/disk_usage_scan.php
|
||||
//
|
||||
// Build or refresh the disk usage snapshot used by the Admin "Storage / Disk Usage" view.
|
||||
|
||||
require __DIR__ . '/../../config/config.php';
|
||||
require __DIR__ . '/../../src/models/DiskUsageModel.php';
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
try {
|
||||
$snapshot = DiskUsageModel::buildSnapshot();
|
||||
$elapsed = microtime(true) - $start;
|
||||
|
||||
$bytes = (int)($snapshot['root_bytes'] ?? 0);
|
||||
$files = (int)($snapshot['root_files'] ?? 0);
|
||||
|
||||
$human = function (int $b): string {
|
||||
if ($b <= 0) return '0 B';
|
||||
$units = ['B','KB','MB','GB','TB','PB'];
|
||||
$i = (int)floor(log($b, 1024));
|
||||
$i = max(0, min($i, count($units) - 1));
|
||||
$val = $b / pow(1024, $i);
|
||||
return sprintf('%.2f %s', $val, $units[$i]);
|
||||
};
|
||||
|
||||
$msg = sprintf(
|
||||
"Disk usage snapshot written to %s\nScanned %d files, total %s in %.2f seconds.\n",
|
||||
DiskUsageModel::snapshotPath(),
|
||||
$files,
|
||||
$human($bytes),
|
||||
$elapsed
|
||||
);
|
||||
fwrite(STDOUT, $msg);
|
||||
exit(0);
|
||||
} catch (Throwable $e) {
|
||||
fwrite(STDERR, "Error building disk usage snapshot: " . $e->getMessage() . "\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
// src/controllers/AdminController.php
|
||||
|
||||
require_once __DIR__ . '/../../config/config.php';
|
||||
@@ -241,7 +242,7 @@ public function setLicense(): void
|
||||
// Store license + updatedAt in JSON file
|
||||
if (!defined('PRO_LICENSE_FILE')) {
|
||||
// Fallback if constant not defined for some reason
|
||||
define('PRO_LICENSE_FILE', PROJECT_ROOT . '/users/proLicense.json');
|
||||
define('PRO_LICENSE_FILE', rtrim(USERS_DIR, "/\\") . '/proLicense.json');
|
||||
}
|
||||
|
||||
$payload = [
|
||||
@@ -566,10 +567,11 @@ public function installProBundle(): void
|
||||
|
||||
$projectRoot = rtrim(PROJECT_ROOT, DIRECTORY_SEPARATOR);
|
||||
|
||||
// Where Pro bundle code lives (defaults to PROJECT_ROOT . '/users/pro')
|
||||
// Where Pro bundle code lives (defaults to USERS_DIR . '/pro')
|
||||
$projectRoot = rtrim(PROJECT_ROOT, DIRECTORY_SEPARATOR);
|
||||
$bundleRoot = defined('FR_PRO_BUNDLE_DIR')
|
||||
? rtrim(FR_PRO_BUNDLE_DIR, DIRECTORY_SEPARATOR)
|
||||
: ($projectRoot . DIRECTORY_SEPARATOR . 'users' . DIRECTORY_SEPARATOR . 'pro');
|
||||
: (rtrim(USERS_DIR, "/\\") . DIRECTORY_SEPARATOR . 'pro');
|
||||
|
||||
// Put README-Pro.txt / LICENSE-Pro.txt inside the bundle dir as well
|
||||
$proDocsDir = $bundleRoot;
|
||||
|
||||
723
src/models/DiskUsageModel.php
Normal file
723
src/models/DiskUsageModel.php
Normal file
@@ -0,0 +1,723 @@
|
||||
<?php
|
||||
// src/models/DiskUsageModel.php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once PROJECT_ROOT . '/config/config.php';
|
||||
require_once PROJECT_ROOT . '/src/lib/FS.php';
|
||||
|
||||
/**
|
||||
* DiskUsageModel
|
||||
*
|
||||
* Builds and reads a cached snapshot of disk usage under UPLOAD_DIR.
|
||||
* Snapshot is stored as JSON under META_DIR . '/disk_usage.json'.
|
||||
*
|
||||
* Folder keys mirror the rest of FileRise:
|
||||
* - "root" is the upload root
|
||||
* - "foo/bar" are subfolders under UPLOAD_DIR
|
||||
*
|
||||
* We intentionally skip:
|
||||
* - trash subtree
|
||||
* - profile_pics subtree
|
||||
* - dot-prefixed names
|
||||
* - FS::IGNORE() entries like @eaDir, .DS_Store, etc.
|
||||
*/
|
||||
class DiskUsageModel
|
||||
{
|
||||
/** Where we persist the snapshot JSON. */
|
||||
public const SNAPSHOT_BASENAME = 'disk_usage.json';
|
||||
|
||||
/** Maximum number of per-file records to keep (for Top N view). */
|
||||
private const TOP_FILE_LIMIT = 1000;
|
||||
|
||||
/**
|
||||
* Absolute path to the snapshot JSON file.
|
||||
*/
|
||||
public static function snapshotPath(): string
|
||||
{
|
||||
$meta = rtrim((string)META_DIR, '/\\');
|
||||
return $meta . DIRECTORY_SEPARATOR . self::SNAPSHOT_BASENAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a fresh snapshot of disk usage under UPLOAD_DIR and write it to disk.
|
||||
*
|
||||
* Returns the structured snapshot array (same shape as stored JSON).
|
||||
*
|
||||
* @throws RuntimeException on configuration or IO errors.
|
||||
*/
|
||||
public static function buildSnapshot(): array
|
||||
{
|
||||
$start = microtime(true);
|
||||
|
||||
$root = realpath(UPLOAD_DIR);
|
||||
if ($root === false || !is_dir($root)) {
|
||||
throw new RuntimeException('Uploads directory is not configured correctly.');
|
||||
}
|
||||
$root = rtrim($root, DIRECTORY_SEPARATOR);
|
||||
|
||||
$IGNORE = FS::IGNORE();
|
||||
$SKIP = FS::SKIP();
|
||||
|
||||
// Folder map: key => [
|
||||
// 'key' => string,
|
||||
// 'parent' => string|null,
|
||||
// 'name' => string,
|
||||
// 'bytes' => int,
|
||||
// 'files' => int,
|
||||
// 'dirs' => int,
|
||||
// 'latest_mtime' => int
|
||||
// ]
|
||||
$folders = [];
|
||||
|
||||
// Root entry
|
||||
$folders['root'] = [
|
||||
'key' => 'root',
|
||||
'parent' => null,
|
||||
'name' => 'root',
|
||||
'bytes' => 0,
|
||||
'files' => 0,
|
||||
'dirs' => 0,
|
||||
'latest_mtime' => 0,
|
||||
];
|
||||
|
||||
// File records (we may trim to TOP_FILE_LIMIT later)
|
||||
// Each item: [
|
||||
// 'folder' => folderKey,
|
||||
// 'name' => file name,
|
||||
// 'path' => "folder/name" or just name if root,
|
||||
// 'bytes' => int,
|
||||
// 'mtime' => int
|
||||
// ]
|
||||
$files = [];
|
||||
|
||||
$rootLen = strlen($root);
|
||||
|
||||
$it = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator(
|
||||
$root,
|
||||
FilesystemIterator::SKIP_DOTS
|
||||
| FilesystemIterator::FOLLOW_SYMLINKS
|
||||
),
|
||||
RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
|
||||
foreach ($it as $path => $info) {
|
||||
/** @var SplFileInfo $info */
|
||||
$name = $info->getFilename();
|
||||
|
||||
// Skip dotfiles / dotdirs
|
||||
if ($name === '.' || $name === '..') {
|
||||
continue;
|
||||
}
|
||||
if ($name[0] === '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip system/ignored entries
|
||||
if (in_array($name, $IGNORE, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Relative path under UPLOAD_DIR, normalized with '/'
|
||||
$rel = substr($path, $rootLen);
|
||||
$rel = str_replace('\\', '/', $rel);
|
||||
$rel = ltrim($rel, '/');
|
||||
|
||||
// Should only happen for the root itself, which we seeded
|
||||
if ($rel === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isDir = $info->isDir();
|
||||
|
||||
if ($isDir) {
|
||||
$folderKey = $rel;
|
||||
$lowerRel = strtolower($folderKey);
|
||||
|
||||
// Skip trash/profile_pics subtrees entirely
|
||||
if ($lowerRel === 'trash' || strpos($lowerRel, 'trash/') === 0) {
|
||||
$it->next();
|
||||
continue;
|
||||
}
|
||||
if ($lowerRel === 'profile_pics' || strpos($lowerRel, 'profile_pics/') === 0) {
|
||||
$it->next();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip SKIP entries at any level
|
||||
$baseLower = strtolower(basename($folderKey));
|
||||
if (in_array($baseLower, $SKIP, true)) {
|
||||
$it->next();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Register folder
|
||||
if (!isset($folders[$folderKey])) {
|
||||
$parent = self::parentKeyOf($folderKey);
|
||||
if (!isset($folders[$parent])) {
|
||||
// Ensure parent exists (important for aggregation step later)
|
||||
$folders[$parent] = [
|
||||
'key' => $parent,
|
||||
'parent' => self::parentKeyOf($parent),
|
||||
'name' => self::basenameKey($parent),
|
||||
'bytes' => 0,
|
||||
'files' => 0,
|
||||
'dirs' => 0,
|
||||
'latest_mtime' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$folders[$folderKey] = [
|
||||
'key' => $folderKey,
|
||||
'parent' => $parent,
|
||||
'name' => self::basenameKey($folderKey),
|
||||
'bytes' => 0,
|
||||
'files' => 0,
|
||||
'dirs' => 0,
|
||||
'latest_mtime' => 0,
|
||||
];
|
||||
// Increment dir count on parent
|
||||
if ($parent !== null && isset($folders[$parent])) {
|
||||
$folders[$parent]['dirs']++;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// File entry
|
||||
// Determine folder key where this file resides
|
||||
$relDir = str_replace('\\', '/', dirname($rel));
|
||||
if ($relDir === '.' || $relDir === '') {
|
||||
$folderKey = 'root';
|
||||
} else {
|
||||
$folderKey = $relDir;
|
||||
}
|
||||
|
||||
$lowerFolder = strtolower($folderKey);
|
||||
if ($lowerFolder === 'trash' || strpos($lowerFolder, 'trash/') === 0) {
|
||||
continue;
|
||||
}
|
||||
if ($lowerFolder === 'profile_pics' || strpos($lowerFolder, 'profile_pics/') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip SKIP entries for files inside unwanted app-specific dirs
|
||||
$baseLower = strtolower(basename($folderKey));
|
||||
if (in_array($baseLower, $SKIP, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure folder exists in map
|
||||
if (!isset($folders[$folderKey])) {
|
||||
$parent = self::parentKeyOf($folderKey);
|
||||
if (!isset($folders[$parent])) {
|
||||
$folders[$parent] = [
|
||||
'key' => $parent,
|
||||
'parent' => self::parentKeyOf($parent),
|
||||
'name' => self::basenameKey($parent),
|
||||
'bytes' => 0,
|
||||
'files' => 0,
|
||||
'dirs' => 0,
|
||||
'latest_mtime' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$folders[$folderKey] = [
|
||||
'key' => $folderKey,
|
||||
'parent' => $parent,
|
||||
'name' => self::basenameKey($folderKey),
|
||||
'bytes' => 0,
|
||||
'files' => 0,
|
||||
'dirs' => 0,
|
||||
'latest_mtime' => 0,
|
||||
];
|
||||
if ($parent !== null && isset($folders[$parent])) {
|
||||
$folders[$parent]['dirs']++;
|
||||
}
|
||||
}
|
||||
|
||||
$bytes = (int)$info->getSize();
|
||||
$mtime = (int)$info->getMTime();
|
||||
|
||||
// Update folder leaf stats
|
||||
$folders[$folderKey]['bytes'] += $bytes;
|
||||
$folders[$folderKey]['files']++;
|
||||
if ($mtime > $folders[$folderKey]['latest_mtime']) {
|
||||
$folders[$folderKey]['latest_mtime'] = $mtime;
|
||||
}
|
||||
|
||||
// Remember file record (we may trim later)
|
||||
$filePath = ($folderKey === 'root')
|
||||
? $name
|
||||
: ($folderKey . '/' . $name);
|
||||
|
||||
$files[] = [
|
||||
'folder' => $folderKey,
|
||||
'name' => $name,
|
||||
'path' => $filePath,
|
||||
'bytes' => $bytes,
|
||||
'mtime' => $mtime,
|
||||
];
|
||||
}
|
||||
|
||||
// Aggregate folder bytes up the tree so each folder includes its descendants.
|
||||
// Process folders from deepest to shallowest.
|
||||
$keys = array_keys($folders);
|
||||
usort($keys, function (string $a, string $b): int {
|
||||
return self::depthOf($b) <=> self::depthOf($a);
|
||||
});
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$parent = $folders[$key]['parent'];
|
||||
if ($parent !== null && isset($folders[$parent])) {
|
||||
$folders[$parent]['bytes'] += $folders[$key]['bytes'];
|
||||
$folders[$parent]['files'] += $folders[$key]['files'];
|
||||
$folders[$parent]['dirs'] += $folders[$key]['dirs'];
|
||||
$parentLatest = $folders[$parent]['latest_mtime'];
|
||||
if ($folders[$key]['latest_mtime'] > $parentLatest) {
|
||||
$folders[$parent]['latest_mtime'] = $folders[$key]['latest_mtime'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Root aggregate
|
||||
$rootBytes = isset($folders['root']) ? (int)$folders['root']['bytes'] : 0;
|
||||
$rootFiles = isset($folders['root']) ? (int)$folders['root']['files'] : 0;
|
||||
|
||||
// Count of folders under the upload root (excluding "root" itself)
|
||||
$rootFolders = 0;
|
||||
if (!empty($folders)) {
|
||||
$rootFolders = max(0, count($folders) - 1);
|
||||
}
|
||||
|
||||
// Trim top files list
|
||||
usort($files, function (array $a, array $b): int {
|
||||
// descending by bytes, then by path
|
||||
if ($a['bytes'] === $b['bytes']) {
|
||||
return strcmp($a['path'], $b['path']);
|
||||
}
|
||||
return ($a['bytes'] < $b['bytes']) ? 1 : -1;
|
||||
});
|
||||
if (count($files) > self::TOP_FILE_LIMIT) {
|
||||
$files = array_slice($files, 0, self::TOP_FILE_LIMIT);
|
||||
}
|
||||
|
||||
$snapshot = [
|
||||
'version' => 1,
|
||||
'generated_at' => time(),
|
||||
'scan_seconds' => microtime(true) - $start,
|
||||
'root_bytes' => $rootBytes,
|
||||
'root_files' => $rootFiles,
|
||||
'root_folders' => $rootFolders,
|
||||
// Store folders as numerically-indexed array
|
||||
'folders' => array_values($folders),
|
||||
'files' => $files,
|
||||
];
|
||||
|
||||
$path = self::snapshotPath();
|
||||
$dir = dirname($path);
|
||||
if (!is_dir($dir)) {
|
||||
@mkdir($dir, 0775, true);
|
||||
}
|
||||
|
||||
$json = json_encode($snapshot, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
if ($json === false) {
|
||||
throw new RuntimeException('Failed to encode disk usage snapshot.');
|
||||
}
|
||||
|
||||
if (@file_put_contents($path, $json) === false) {
|
||||
throw new RuntimeException('Failed to write disk usage snapshot to ' . $path);
|
||||
}
|
||||
|
||||
return $snapshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the snapshot from disk, or return null if missing or invalid.
|
||||
*/
|
||||
public static function loadSnapshot(): ?array
|
||||
{
|
||||
$path = self::snapshotPath();
|
||||
if (!is_file($path)) {
|
||||
return null;
|
||||
}
|
||||
$raw = @file_get_contents($path);
|
||||
if ($raw === false || $raw === '') {
|
||||
return null;
|
||||
}
|
||||
$data = json_decode($raw, true);
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($data['version']) || (int)$data['version'] !== 1) {
|
||||
return null;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute a lightweight summary for the Admin panel.
|
||||
*
|
||||
* @param int $maxTopFolders How many top folders to include.
|
||||
* @param int $maxTopFilesPreview Optional number of top files to include as preview.
|
||||
* @return array
|
||||
*/
|
||||
public static function getSummary(int $maxTopFolders = 5, int $maxTopFilesPreview = 0): array
|
||||
{
|
||||
$snapshot = self::loadSnapshot();
|
||||
if ($snapshot === null) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'no_snapshot',
|
||||
'message' => 'No disk usage snapshot found. Run the disk usage scan to generate one.',
|
||||
'generatedAt' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$rootBytes = (int)($snapshot['root_bytes'] ?? 0);
|
||||
$folders = is_array($snapshot['folders'] ?? null) ? $snapshot['folders'] : [];
|
||||
|
||||
// --- Build "volumes" across core FileRise dirs (UPLOAD/USERS/META) ---
|
||||
$volumeRoots = [
|
||||
'uploads' => defined('UPLOAD_DIR') ? (string)UPLOAD_DIR : null,
|
||||
'users' => defined('USERS_DIR') ? (string)USERS_DIR : null,
|
||||
'meta' => defined('META_DIR') ? (string)META_DIR : null,
|
||||
];
|
||||
|
||||
$volumesMap = [];
|
||||
$uploadReal = null;
|
||||
|
||||
if (defined('UPLOAD_DIR')) {
|
||||
$tmp = realpath(UPLOAD_DIR);
|
||||
if ($tmp !== false && is_dir($tmp)) {
|
||||
$uploadReal = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($volumeRoots as $kind => $dir) {
|
||||
if ($dir === null || $dir === '') {
|
||||
continue;
|
||||
}
|
||||
$real = realpath($dir);
|
||||
if ($real === false || !is_dir($real)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$total = @disk_total_space($real);
|
||||
$free = @disk_free_space($real);
|
||||
if ($total === false || $free === false || $total <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$total = (int)$total;
|
||||
$free = (int)$free;
|
||||
$used = $total - $free;
|
||||
if ($used < 0) {
|
||||
$used = 0;
|
||||
}
|
||||
$usedPct = ($used * 100.0) / $total;
|
||||
|
||||
// Group by same total+free => assume same underlying volume
|
||||
$bucketKey = $total . ':' . $free;
|
||||
if (!isset($volumesMap[$bucketKey])) {
|
||||
$volumesMap[$bucketKey] = [
|
||||
'totalBytes' => $total,
|
||||
'freeBytes' => $free,
|
||||
'usedBytes' => $used,
|
||||
'usedPercent' => $usedPct,
|
||||
'roots' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$volumesMap[$bucketKey]['roots'][] = [
|
||||
'kind' => $kind, // "uploads" | "users" | "meta"
|
||||
'path' => $real,
|
||||
];
|
||||
}
|
||||
|
||||
$volumes = array_values($volumesMap);
|
||||
// Sort by usedPercent desc (heaviest first)
|
||||
usort($volumes, function (array $a, array $b): int {
|
||||
$pa = (float)($a['usedPercent'] ?? 0.0);
|
||||
$pb = (float)($b['usedPercent'] ?? 0.0);
|
||||
if ($pa === $pb) {
|
||||
return 0;
|
||||
}
|
||||
return ($pa < $pb) ? 1 : -1;
|
||||
});
|
||||
|
||||
// Backwards-compat: root filesystem metrics based on the volume
|
||||
// that contains UPLOAD_DIR (if we can detect it).
|
||||
$fsTotalBytes = null;
|
||||
$fsFreeBytes = null;
|
||||
$fsUsedBytes = null;
|
||||
$fsUsedPct = null;
|
||||
|
||||
if ($uploadReal && !empty($volumes)) {
|
||||
foreach ($volumes as $vol) {
|
||||
foreach ($vol['roots'] as $root) {
|
||||
if (!isset($root['path'])) continue;
|
||||
if ((string)$root['path'] === (string)$uploadReal) {
|
||||
$fsTotalBytes = (int)$vol['totalBytes'];
|
||||
$fsFreeBytes = (int)$vol['freeBytes'];
|
||||
$fsUsedBytes = (int)$vol['usedBytes'];
|
||||
$fsUsedPct = (float)$vol['usedPercent'];
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Top N non-root folders by bytes (from snapshot)
|
||||
$candidates = array_filter($folders, function (array $f): bool {
|
||||
return isset($f['key']) && $f['key'] !== 'root';
|
||||
});
|
||||
|
||||
usort($candidates, function (array $a, array $b): int {
|
||||
$ba = (int)($a['bytes'] ?? 0);
|
||||
$bb = (int)($b['bytes'] ?? 0);
|
||||
if ($ba === $bb) {
|
||||
return strcmp((string)$a['key'], (string)$b['key']);
|
||||
}
|
||||
return ($ba < $bb) ? 1 : -1;
|
||||
});
|
||||
|
||||
if ($maxTopFolders > 0 && count($candidates) > $maxTopFolders) {
|
||||
$candidates = array_slice($candidates, 0, $maxTopFolders);
|
||||
}
|
||||
|
||||
$topFolders = [];
|
||||
foreach ($candidates as $f) {
|
||||
$bytes = (int)($f['bytes'] ?? 0);
|
||||
$pct = ($rootBytes > 0) ? ($bytes * 100.0 / $rootBytes) : 0.0;
|
||||
$topFolders[] = [
|
||||
'folder' => (string)$f['key'],
|
||||
'name' => (string)$f['name'],
|
||||
'bytes' => $bytes,
|
||||
'files' => (int)($f['files'] ?? 0),
|
||||
'dirs' => (int)($f['dirs'] ?? 0),
|
||||
'latest_mtime' => (int)($f['latest_mtime'] ?? 0),
|
||||
'percentOfTotal' => $pct,
|
||||
];
|
||||
}
|
||||
|
||||
// totalFolders: prefer snapshot["root_folders"], but fall back to counting
|
||||
$totalFolders = isset($snapshot['root_folders'])
|
||||
? (int)$snapshot['root_folders']
|
||||
: max(0, count($folders) - 1);
|
||||
|
||||
$out = [
|
||||
'ok' => true,
|
||||
'generatedAt' => (int)($snapshot['generated_at'] ?? 0),
|
||||
'scanSeconds' => (float)($snapshot['scan_seconds'] ?? 0.0),
|
||||
'totalBytes' => $rootBytes,
|
||||
'totalFiles' => (int)($snapshot['root_files'] ?? 0),
|
||||
'totalFolders' => $totalFolders,
|
||||
'topFolders' => $topFolders,
|
||||
// original fields (for single-root view)
|
||||
'uploadRoot' => $uploadReal,
|
||||
'fsTotalBytes' => $fsTotalBytes,
|
||||
'fsFreeBytes' => $fsFreeBytes,
|
||||
'fsUsedBytes' => $fsUsedBytes,
|
||||
'fsUsedPercent' => $fsUsedPct,
|
||||
// new grouped volumes: each with total/free/used and roots[]
|
||||
'volumes' => $volumes,
|
||||
];
|
||||
|
||||
if ($maxTopFilesPreview > 0) {
|
||||
$files = is_array($snapshot['files'] ?? null) ? $snapshot['files'] : [];
|
||||
if (count($files) > $maxTopFilesPreview) {
|
||||
$files = array_slice($files, 0, $maxTopFilesPreview);
|
||||
}
|
||||
$out['topFiles'] = $files;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return direct children (folders + files) of a given folder key.
|
||||
*
|
||||
* @param string $folderKey
|
||||
* @return array
|
||||
*/
|
||||
public static function getChildren(string $folderKey): array
|
||||
{
|
||||
$folderKey = ($folderKey === '' || $folderKey === '/') ? 'root' : $folderKey;
|
||||
|
||||
$snapshot = self::loadSnapshot();
|
||||
if ($snapshot === null) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'no_snapshot',
|
||||
];
|
||||
}
|
||||
|
||||
$rootBytes = (int)($snapshot['root_bytes'] ?? 0);
|
||||
$folders = is_array($snapshot['folders'] ?? null) ? $snapshot['folders'] : [];
|
||||
$files = is_array($snapshot['files'] ?? null) ? $snapshot['files'] : [];
|
||||
|
||||
// Index folders by key
|
||||
$folderByKey = [];
|
||||
foreach ($folders as $f) {
|
||||
if (!isset($f['key'])) continue;
|
||||
$folderByKey[(string)$f['key']] = $f;
|
||||
}
|
||||
if (!isset($folderByKey[$folderKey])) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'folder_not_found',
|
||||
];
|
||||
}
|
||||
|
||||
$childrenFolders = [];
|
||||
foreach ($folders as $f) {
|
||||
if (!isset($f['parent']) || !isset($f['key'])) continue;
|
||||
if ((string)$f['parent'] === $folderKey) {
|
||||
$bytes = (int)($f['bytes'] ?? 0);
|
||||
$pct = ($rootBytes > 0) ? ($bytes * 100.0 / $rootBytes) : 0.0;
|
||||
$childrenFolders[] = [
|
||||
'type' => 'folder',
|
||||
'folder' => (string)$f['key'],
|
||||
'name' => (string)$f['name'],
|
||||
'bytes' => $bytes,
|
||||
'files' => (int)($f['files'] ?? 0),
|
||||
'dirs' => (int)($f['dirs'] ?? 0),
|
||||
'latest_mtime' => (int)($f['latest_mtime'] ?? 0),
|
||||
'percentOfTotal' => $pct,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$childrenFiles = [];
|
||||
foreach ($files as $file) {
|
||||
if (!isset($file['folder']) || !isset($file['name'])) continue;
|
||||
if ((string)$file['folder'] !== $folderKey) continue;
|
||||
|
||||
$bytes = (int)($file['bytes'] ?? 0);
|
||||
$pct = ($rootBytes > 0) ? ($bytes * 100.0 / $rootBytes) : 0.0;
|
||||
$childrenFiles[] = [
|
||||
'type' => 'file',
|
||||
'folder' => (string)$file['folder'],
|
||||
'name' => (string)$file['name'],
|
||||
'path' => (string)($file['path'] ?? $file['name']),
|
||||
'bytes' => $bytes,
|
||||
'mtime' => (int)($file['mtime'] ?? 0),
|
||||
'percentOfTotal' => $pct,
|
||||
];
|
||||
}
|
||||
|
||||
// Sort children: folders first (by bytes desc), then files (by bytes desc)
|
||||
usort($childrenFolders, function (array $a, array $b): int {
|
||||
$ba = (int)($a['bytes'] ?? 0);
|
||||
$bb = (int)($b['bytes'] ?? 0);
|
||||
if ($ba === $bb) {
|
||||
return strcmp((string)$a['name'], (string)$b['name']);
|
||||
}
|
||||
return ($ba < $bb) ? 1 : -1;
|
||||
});
|
||||
|
||||
usort($childrenFiles, function (array $a, array $b): int {
|
||||
$ba = (int)($a['bytes'] ?? 0);
|
||||
$bb = (int)($b['bytes'] ?? 0);
|
||||
if ($ba === $bb) {
|
||||
return strcmp((string)$a['name'], (string)$b['name']);
|
||||
}
|
||||
return ($ba < $bb) ? 1 : -1;
|
||||
});
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'folder' => $folderKey,
|
||||
'folders' => $childrenFolders,
|
||||
'files' => $childrenFiles,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the global Top N files by size from the snapshot.
|
||||
*
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public static function getTopFiles(int $limit = 100): array
|
||||
{
|
||||
$snapshot = self::loadSnapshot();
|
||||
if ($snapshot === null) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'no_snapshot',
|
||||
];
|
||||
}
|
||||
|
||||
$rootBytes = (int)($snapshot['root_bytes'] ?? 0);
|
||||
$files = is_array($snapshot['files'] ?? null) ? $snapshot['files'] : [];
|
||||
|
||||
if ($limit > 0 && count($files) > $limit) {
|
||||
$files = array_slice($files, 0, $limit);
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($files as $file) {
|
||||
$bytes = (int)($file['bytes'] ?? 0);
|
||||
$pct = ($rootBytes > 0) ? ($bytes * 100.0 / $rootBytes) : 0.0;
|
||||
$out[] = [
|
||||
'folder' => (string)($file['folder'] ?? 'root'),
|
||||
'name' => (string)($file['name'] ?? ''),
|
||||
'path' => (string)($file['path'] ?? ($file['name'] ?? '')),
|
||||
'bytes' => $bytes,
|
||||
'mtime' => (int)($file['mtime'] ?? 0),
|
||||
'percentOfTotal' => $pct,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'files' => $out,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: derive the parent folder key ("root" -> null, "foo/bar" -> "foo").
|
||||
*/
|
||||
private static function parentKeyOf(string $key): ?string
|
||||
{
|
||||
if ($key === 'root' || $key === '') {
|
||||
return null;
|
||||
}
|
||||
$key = trim($key, '/');
|
||||
if ($key === '') return null;
|
||||
$pos = strrpos($key, '/');
|
||||
if ($pos === false) {
|
||||
return 'root';
|
||||
}
|
||||
$parent = substr($key, 0, $pos);
|
||||
return ($parent === '' ? 'root' : $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: basename of a folder key. "root" -> "root", "foo/bar" -> "bar".
|
||||
*/
|
||||
private static function basenameKey(?string $key): string
|
||||
{
|
||||
if ($key === null || $key === '' || $key === 'root') {
|
||||
return 'root';
|
||||
}
|
||||
$key = trim($key, '/');
|
||||
$pos = strrpos($key, '/');
|
||||
if ($pos === false) {
|
||||
return $key;
|
||||
}
|
||||
return substr($key, $pos + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: approximate depth of a folder key (root->0, "foo"->1, "foo/bar"->2, etc.)
|
||||
*/
|
||||
private static function depthOf(string $key): int
|
||||
{
|
||||
if ($key === '' || $key === 'root') return 0;
|
||||
return substr_count(trim($key, '/'), '/') + 1;
|
||||
}
|
||||
}
|
||||
@@ -549,6 +549,67 @@ class FileModel {
|
||||
];
|
||||
}
|
||||
|
||||
public static function deleteFilesPermanent(string $folder, array $files): array
|
||||
{
|
||||
$errors = [];
|
||||
$deleted = [];
|
||||
|
||||
list($uploadDir, $err) = self::resolveFolderPath($folder, false);
|
||||
if ($err) return ['error' => $err];
|
||||
|
||||
$uploadDir = rtrim($uploadDir, '/\\') . DIRECTORY_SEPARATOR;
|
||||
$safeFileNamePattern = REGEX_FILE_NAME;
|
||||
|
||||
foreach ($files as $fileName) {
|
||||
$originalName = basename(trim((string)$fileName));
|
||||
$basename = $originalName;
|
||||
|
||||
if ($basename === '') {
|
||||
$errors[] = 'Empty file name.';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!preg_match($safeFileNamePattern, $basename)) {
|
||||
$errors[] = "$basename has an invalid name.";
|
||||
continue;
|
||||
}
|
||||
|
||||
$filePath = $uploadDir . $basename;
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
if (!@unlink($filePath)) {
|
||||
$errors[] = "Failed to delete {$basename}.";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$deleted[] = $basename;
|
||||
|
||||
// Remove from folder metadata if present
|
||||
$metadataFile = self::getMetadataFilePath($folder);
|
||||
if (file_exists($metadataFile)) {
|
||||
$meta = json_decode(file_get_contents($metadataFile), true);
|
||||
if (is_array($meta) && isset($meta[$basename])) {
|
||||
unset($meta[$basename]);
|
||||
@file_put_contents($metadataFile, json_encode($meta, JSON_PRETTY_PRINT), LOCK_EX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors && !$deleted) {
|
||||
return ['error' => implode('; ', $errors)];
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
return [
|
||||
'error' => implode('; ', $errors),
|
||||
'success' => 'Deleted: ' . implode(', ', $deleted),
|
||||
];
|
||||
}
|
||||
|
||||
return ['success' => 'Deleted: ' . implode(', ', $deleted)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ZIP archive of the specified files from a given folder.
|
||||
*
|
||||
|
||||
@@ -483,6 +483,64 @@ class FolderModel
|
||||
}
|
||||
|
||||
|
||||
public static function deleteFolderRecursiveAdmin(string $folder): array
|
||||
{
|
||||
if (strtolower($folder) === 'root') {
|
||||
return ['error' => 'Cannot delete root folder.'];
|
||||
}
|
||||
|
||||
[$real, $relative, $err] = self::resolveFolderPath($folder, false);
|
||||
if ($err) return ['error' => $err];
|
||||
|
||||
if (!is_dir($real)) {
|
||||
return ['error' => 'Folder not found.'];
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
|
||||
$it = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($real, \FilesystemIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
|
||||
foreach ($it as $path => $info) {
|
||||
if ($info->isDir()) {
|
||||
if (!@rmdir($path)) {
|
||||
$errors[] = "Failed to delete directory: {$path}";
|
||||
}
|
||||
} else {
|
||||
if (!@unlink($path)) {
|
||||
$errors[] = "Failed to delete file: {$path}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!@rmdir($real)) {
|
||||
$errors[] = "Failed to delete directory: {$real}";
|
||||
}
|
||||
|
||||
// Remove metadata JSONs for this subtree
|
||||
$relative = trim($relative, "/\\ ");
|
||||
if ($relative !== '' && $relative !== 'root') {
|
||||
$prefix = str_replace(['/', '\\', ' '], '-', $relative);
|
||||
$globPat = META_DIR . $prefix . '*_metadata.json';
|
||||
$metaFiles = glob($globPat) ?: [];
|
||||
foreach ($metaFiles as $mf) {
|
||||
@unlink($mf);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove ownership mappings for the subtree.
|
||||
self::removeOwnerForTree($relative);
|
||||
|
||||
if ($errors) {
|
||||
return ['error' => implode('; ', $errors)];
|
||||
}
|
||||
|
||||
return ['success' => 'Folder and all contents deleted.'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a folder if it is empty and removes its corresponding metadata.
|
||||
* Also removes ownership mappings for this folder and all its descendants.
|
||||
|
||||
Reference in New Issue
Block a user