release(v2.2.2): feat(folders): show inline folder stats & dates
This commit is contained in:
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,5 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Changes 11/29/2025 (v2.2.2)
|
||||||
|
|
||||||
|
release(v2.2.2): feat(folders): show inline folder stats & dates
|
||||||
|
|
||||||
|
- Extend FolderModel::countVisible() to track earliest and latest file mtimes
|
||||||
|
- Format folder created/modified timestamps via DATE_TIME_FORMAT on the backend
|
||||||
|
- Add a small folder stats cache in fileListView.js to reuse isEmpty.php responses
|
||||||
|
- Use shared fetchFolderStats() for both folder strip icons and inline folder rows
|
||||||
|
- Show per-folder item counts, total size, and created/modified dates in inline rows
|
||||||
|
- Make size parsing more robust by accepting multiple backend size keys (bytes/sizeBytes/size/totalBytes)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Changes 11/28/2025 (v2.2.1)
|
## Changes 11/28/2025 (v2.2.1)
|
||||||
|
|
||||||
release(v2.2.1): fix(storage-explorer): DOM-safe rendering + docs for disk usage
|
release(v2.2.1): fix(storage-explorer): DOM-safe rendering + docs for disk usage
|
||||||
@@ -9,6 +22,8 @@ release(v2.2.1): fix(storage-explorer): DOM-safe rendering + docs for disk usage
|
|||||||
- Keep deep-delete and pagination behavior unchanged while tightening up XSS/CodeQL concerns.
|
- 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.
|
- 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)
|
## Changes 11/28/2025 (v2.2.0)
|
||||||
|
|
||||||
release(v2.2.0): add storage explorer + disk usage scanner
|
release(v2.2.0): add storage explorer + disk usage scanner
|
||||||
|
|||||||
@@ -295,6 +295,27 @@ try {
|
|||||||
// Global flag for advanced search mode.
|
// Global flag for advanced search mode.
|
||||||
window.advancedSearchEnabled = false;
|
window.advancedSearchEnabled = false;
|
||||||
|
|
||||||
|
// --- Folder stats cache (for isEmpty.php) ---
|
||||||
|
const _folderStatsCache = new Map();
|
||||||
|
|
||||||
|
function fetchFolderStats(folder) {
|
||||||
|
if (!folder) return Promise.resolve(null);
|
||||||
|
|
||||||
|
if (_folderStatsCache.has(folder)) {
|
||||||
|
return _folderStatsCache.get(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `/api/folder/isEmpty.php?folder=${encodeURIComponent(folder)}&t=${Date.now()}`;
|
||||||
|
const p = _fetchJSONWithTimeout(url, 2500)
|
||||||
|
.catch(() => ({ folders: 0, files: 0 }))
|
||||||
|
.finally(() => {
|
||||||
|
// keep the resolved value; the Promise itself stays in the map
|
||||||
|
});
|
||||||
|
|
||||||
|
_folderStatsCache.set(folder, p);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/* ===========================================================
|
/* ===========================================================
|
||||||
SECURITY: build file URLs only via the API (no /uploads)
|
SECURITY: build file URLs only via the API (no /uploads)
|
||||||
=========================================================== */
|
=========================================================== */
|
||||||
@@ -428,19 +449,19 @@ function attachStripIconAsync(hostEl, fullPath, size = 28) {
|
|||||||
// make sure this brand-new SVG is sized correctly
|
// make sure this brand-new SVG is sized correctly
|
||||||
try { syncFolderIconSizeToRowHeight(); } catch {}
|
try { syncFolderIconSizeToRowHeight(); } catch {}
|
||||||
|
|
||||||
const url = `/api/folder/isEmpty.php?folder=${encodeURIComponent(fullPath)}&t=${Date.now()}`;
|
fetchFolderStats(fullPath)
|
||||||
_fetchJSONWithTimeout(url, 2500)
|
.then(stats => {
|
||||||
.then(({ folders = 0, files = 0 }) => {
|
if (!stats) return;
|
||||||
if ((folders + files) > 0 && iconSpan.dataset.kind !== 'paper') {
|
const folders = Number.isFinite(stats.folders) ? stats.folders : 0;
|
||||||
// 2) swap to "paper" icon
|
const files = Number.isFinite(stats.files) ? stats.files : 0;
|
||||||
iconSpan.dataset.kind = 'paper';
|
|
||||||
iconSpan.innerHTML = folderSVG('paper');
|
|
||||||
|
|
||||||
// re-apply sizing to this new SVG too
|
if ((folders + files) > 0 && iconSpan.dataset.kind !== 'paper') {
|
||||||
try { syncFolderIconSizeToRowHeight(); } catch {}
|
iconSpan.dataset.kind = 'paper';
|
||||||
}
|
iconSpan.innerHTML = folderSVG('paper');
|
||||||
})
|
try { syncFolderIconSizeToRowHeight(); } catch {}
|
||||||
.catch(() => { /* ignore */ });
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------
|
/* -----------------------------
|
||||||
@@ -1156,6 +1177,19 @@ function injectInlineFolderRows(fileListContent, folder, pageSubfolders) {
|
|||||||
);
|
);
|
||||||
if (actionsIdx < 0) actionsIdx = -1;
|
if (actionsIdx < 0) actionsIdx = -1;
|
||||||
|
|
||||||
|
// NEW: created / modified column indices (uploaded = created in your header)
|
||||||
|
let createdIdx = headerCells.findIndex(th =>
|
||||||
|
(th.dataset && (th.dataset.column === "uploaded" || th.dataset.column === "created")) ||
|
||||||
|
/\b(uploaded|created)\b/i.test((th.textContent || "").trim())
|
||||||
|
);
|
||||||
|
if (createdIdx < 0) createdIdx = -1;
|
||||||
|
|
||||||
|
let modifiedIdx = headerCells.findIndex(th =>
|
||||||
|
(th.dataset && th.dataset.column === "modified") ||
|
||||||
|
/\bmodified\b/i.test((th.textContent || "").trim())
|
||||||
|
);
|
||||||
|
if (modifiedIdx < 0) modifiedIdx = -1;
|
||||||
|
|
||||||
// Remove any previous folder rows
|
// Remove any previous folder rows
|
||||||
tbody.querySelectorAll("tr.folder-row").forEach(tr => tr.remove());
|
tbody.querySelectorAll("tr.folder-row").forEach(tr => tr.remove());
|
||||||
|
|
||||||
@@ -1356,19 +1390,32 @@ if (iconSpan) {
|
|||||||
iconSpan.style.marginTop = "0px"; // small down nudge
|
iconSpan.style.marginTop = "0px"; // small down nudge
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----- FOLDER STATS + OWNER + CAPS (keep your existing code below here) -----
|
// ----- FOLDER STATS + OWNER + CAPS -----
|
||||||
const sizeCellIndex = (sizeIdx >= 0 && sizeIdx < tr.cells.length) ? sizeIdx : -1;
|
const sizeCellIndex = (sizeIdx >= 0 && sizeIdx < tr.cells.length) ? sizeIdx : -1;
|
||||||
const nameCellIndex = (nameIdx >= 0 && nameIdx < tr.cells.length) ? nameIdx : -1;
|
const nameCellIndex = (nameIdx >= 0 && nameIdx < tr.cells.length) ? nameIdx : -1;
|
||||||
|
const createdCellIndex = (createdIdx >= 0 && createdIdx < tr.cells.length) ? createdIdx : -1;
|
||||||
|
const modifiedCellIndex = (modifiedIdx >= 0 && modifiedIdx < tr.cells.length) ? modifiedIdx : -1;
|
||||||
|
|
||||||
const url = `/api/folder/isEmpty.php?folder=${encodeURIComponent(sf.full)}&t=${Date.now()}`;
|
fetchFolderStats(sf.full).then(stats => {
|
||||||
_fetchJSONWithTimeout(url, 2500).then(stats => {
|
|
||||||
if (!stats) return;
|
if (!stats) return;
|
||||||
|
|
||||||
const foldersCount = Number.isFinite(stats.folders) ? stats.folders : 0;
|
const foldersCount = Number.isFinite(stats.folders) ? stats.folders : 0;
|
||||||
const filesCount = Number.isFinite(stats.files) ? stats.files : 0;
|
const filesCount = Number.isFinite(stats.files) ? stats.files : 0;
|
||||||
const bytes = Number.isFinite(stats.bytes)
|
// Try multiple possible size keys so backend + JS can drift a bit
|
||||||
? stats.bytes
|
let bytes = null;
|
||||||
: (Number.isFinite(stats.sizeBytes) ? stats.sizeBytes : null);
|
const sizeCandidates = [
|
||||||
|
stats.bytes,
|
||||||
|
stats.sizeBytes,
|
||||||
|
stats.size,
|
||||||
|
stats.totalBytes
|
||||||
|
];
|
||||||
|
for (const v of sizeCandidates) {
|
||||||
|
const n = Number(v);
|
||||||
|
if (Number.isFinite(n) && n >= 0) {
|
||||||
|
bytes = n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let pieces = [];
|
let pieces = [];
|
||||||
if (foldersCount) pieces.push(`${foldersCount} folder${foldersCount === 1 ? "" : "s"}`);
|
if (foldersCount) pieces.push(`${foldersCount} folder${foldersCount === 1 ? "" : "s"}`);
|
||||||
@@ -1395,6 +1442,26 @@ if (iconSpan) {
|
|||||||
sizeCell.title = `${countLabel}${bytes != null && bytes >= 0 ? " • " + sizeLabel : ""}`;
|
sizeCell.title = `${countLabel}${bytes != null && bytes >= 0 ? " • " + sizeLabel : ""}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (createdCellIndex >= 0) {
|
||||||
|
const createdCell = tr.cells[createdCellIndex];
|
||||||
|
if (createdCell) {
|
||||||
|
const txt = (stats && typeof stats.earliest_uploaded === 'string')
|
||||||
|
? stats.earliest_uploaded
|
||||||
|
: '';
|
||||||
|
createdCell.textContent = txt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifiedCellIndex >= 0) {
|
||||||
|
const modCell = tr.cells[modifiedCellIndex];
|
||||||
|
if (modCell) {
|
||||||
|
const txt = (stats && typeof stats.latest_mtime === 'string')
|
||||||
|
? stats.latest_mtime
|
||||||
|
: '';
|
||||||
|
modCell.textContent = txt;
|
||||||
|
}
|
||||||
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
if (sizeCellIndex >= 0) {
|
if (sizeCellIndex >= 0) {
|
||||||
const sizeCell = tr.cells[sizeCellIndex];
|
const sizeCell = tr.cells[sizeCellIndex];
|
||||||
|
|||||||
@@ -12,110 +12,135 @@ class FolderModel
|
|||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
|
|
||||||
public static function countVisible(string $folder, string $user, array $perms): array
|
public static function countVisible(string $folder, string $user, array $perms): array
|
||||||
{
|
{
|
||||||
$folder = ACL::normalizeFolder($folder);
|
$folder = ACL::normalizeFolder($folder);
|
||||||
|
|
||||||
// If the user can't view this folder at all, short-circuit (admin/read/read_own)
|
// If the user can't view this folder at all, short-circuit (admin/read/read_own)
|
||||||
$canViewFolder = ACL::isAdmin($perms)
|
$canViewFolder = ACL::isAdmin($perms)
|
||||||
|| ACL::canRead($user, $perms, $folder)
|
|| ACL::canRead($user, $perms, $folder)
|
||||||
|| ACL::canReadOwn($user, $perms, $folder);
|
|| ACL::canReadOwn($user, $perms, $folder);
|
||||||
if (!$canViewFolder) {
|
if (!$canViewFolder) {
|
||||||
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEW: distinguish full read vs own-only for this folder
|
// NEW: distinguish full read vs own-only for this folder
|
||||||
$hasFullRead = ACL::isAdmin($perms) || ACL::canRead($user, $perms, $folder);
|
$hasFullRead = ACL::isAdmin($perms) || ACL::canRead($user, $perms, $folder);
|
||||||
// if !$hasFullRead but $canViewFolder is true, they’re effectively "view own" only
|
// if !$hasFullRead but $canViewFolder is true, they’re effectively "view own" only
|
||||||
|
|
||||||
$base = realpath((string)UPLOAD_DIR);
|
$base = realpath((string)UPLOAD_DIR);
|
||||||
if ($base === false) {
|
if ($base === false) {
|
||||||
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve target dir + ACL-relative prefix
|
// Resolve target dir + ACL-relative prefix
|
||||||
if ($folder === 'root') {
|
if ($folder === 'root') {
|
||||||
$dir = $base;
|
$dir = $base;
|
||||||
$relPrefix = '';
|
$relPrefix = '';
|
||||||
} else {
|
} else {
|
||||||
$parts = array_filter(explode('/', $folder), fn($p) => $p !== '');
|
$parts = array_filter(explode('/', $folder), fn($p) => $p !== '');
|
||||||
foreach ($parts as $seg) {
|
foreach ($parts as $seg) {
|
||||||
if (!self::isSafeSegment($seg)) {
|
if (!self::isSafeSegment($seg)) {
|
||||||
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$guess = $base . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts);
|
$guess = $base . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts);
|
||||||
$dir = self::safeReal($base, $guess);
|
$dir = self::safeReal($base, $guess);
|
||||||
if ($dir === null || !is_dir($dir)) {
|
if ($dir === null || !is_dir($dir)) {
|
||||||
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
||||||
}
|
}
|
||||||
$relPrefix = implode('/', $parts);
|
$relPrefix = implode('/', $parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
$IGNORE = ['@eaDir', '#recycle', '.DS_Store', 'Thumbs.db'];
|
$IGNORE = ['@eaDir', '#recycle', '.DS_Store', 'Thumbs.db'];
|
||||||
$SKIP = ['trash', 'profile_pics'];
|
$SKIP = ['trash', 'profile_pics'];
|
||||||
|
|
||||||
$entries = @scandir($dir);
|
$entries = @scandir($dir);
|
||||||
if ($entries === false) {
|
if ($entries === false) {
|
||||||
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
return ['folders' => 0, 'files' => 0, 'bytes' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$folderCount = 0;
|
$folderCount = 0;
|
||||||
$fileCount = 0;
|
$fileCount = 0;
|
||||||
$totalBytes = 0;
|
$totalBytes = 0;
|
||||||
|
|
||||||
$MAX_SCAN = 4000;
|
// NEW: stats for created / modified
|
||||||
$scanned = 0;
|
$earliestUploaded = null; // min mtime
|
||||||
|
$latestMtime = null; // max mtime
|
||||||
|
|
||||||
foreach ($entries as $name) {
|
$MAX_SCAN = 4000;
|
||||||
if (++$scanned > $MAX_SCAN) {
|
$scanned = 0;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($name === '.' || $name === '..') continue;
|
foreach ($entries as $name) {
|
||||||
if ($name[0] === '.') continue;
|
if (++$scanned > $MAX_SCAN) {
|
||||||
if (in_array($name, $IGNORE, true)) continue;
|
break;
|
||||||
if (in_array(strtolower($name), $SKIP, true)) continue;
|
}
|
||||||
if (!self::isSafeSegment($name)) continue;
|
|
||||||
|
|
||||||
$abs = $dir . DIRECTORY_SEPARATOR . $name;
|
if ($name === '.' || $name === '..') continue;
|
||||||
|
if ($name[0] === '.') continue;
|
||||||
|
if (in_array($name, $IGNORE, true)) continue;
|
||||||
|
if (in_array(strtolower($name), $SKIP, true)) continue;
|
||||||
|
if (!self::isSafeSegment($name)) continue;
|
||||||
|
|
||||||
if (@is_dir($abs)) {
|
$abs = $dir . DIRECTORY_SEPARATOR . $name;
|
||||||
if (@is_link($abs)) {
|
|
||||||
$safe = self::safeReal($base, $abs);
|
|
||||||
if ($safe === null || !is_dir($safe)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$childRel = ($relPrefix === '' ? $name : $relPrefix . '/' . $name);
|
if (@is_dir($abs)) {
|
||||||
if (
|
if (@is_link($abs)) {
|
||||||
ACL::isAdmin($perms)
|
$safe = self::safeReal($base, $abs);
|
||||||
|| ACL::canRead($user, $perms, $childRel)
|
if ($safe === null || !is_dir($safe)) {
|
||||||
|| ACL::canReadOwn($user, $perms, $childRel)
|
continue;
|
||||||
) {
|
}
|
||||||
$folderCount++;
|
}
|
||||||
}
|
|
||||||
} elseif (@is_file($abs)) {
|
|
||||||
// Only count files if the user has full read on *this* folder.
|
|
||||||
// If they’re view_own-only here, don’t leak or mis-report counts.
|
|
||||||
if (!$hasFullRead) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fileCount++;
|
$childRel = ($relPrefix === '' ? $name : $relPrefix . '/' . $name);
|
||||||
$sz = @filesize($abs);
|
if (
|
||||||
if (is_int($sz) && $sz > 0) {
|
ACL::isAdmin($perms)
|
||||||
$totalBytes += $sz;
|
|| ACL::canRead($user, $perms, $childRel)
|
||||||
}
|
|| ACL::canReadOwn($user, $perms, $childRel)
|
||||||
}
|
) {
|
||||||
}
|
$folderCount++;
|
||||||
|
}
|
||||||
|
} elseif (@is_file($abs)) {
|
||||||
|
// Only count files if the user has full read on *this* folder.
|
||||||
|
// If they’re view_own-only here, don’t leak or mis-report counts.
|
||||||
|
if (!$hasFullRead) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
$fileCount++;
|
||||||
'folders' => $folderCount,
|
$sz = @filesize($abs);
|
||||||
'files' => $fileCount,
|
if (is_int($sz) && $sz > 0) {
|
||||||
'bytes' => $totalBytes,
|
$totalBytes += $sz;
|
||||||
];
|
}
|
||||||
}
|
|
||||||
|
// NEW: track earliest / latest mtime from visible files
|
||||||
|
$mt = @filemtime($abs);
|
||||||
|
if (is_int($mt) && $mt > 0) {
|
||||||
|
if ($earliestUploaded === null || $mt < $earliestUploaded) {
|
||||||
|
$earliestUploaded = $mt;
|
||||||
|
}
|
||||||
|
if ($latestMtime === null || $mt > $latestMtime) {
|
||||||
|
$latestMtime = $mt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'folders' => $folderCount,
|
||||||
|
'files' => $fileCount,
|
||||||
|
'bytes' => $totalBytes,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Only include when we actually saw at least one readable file
|
||||||
|
if ($earliestUploaded !== null) {
|
||||||
|
$result['earliest_uploaded'] = date(DATE_TIME_FORMAT, $earliestUploaded);
|
||||||
|
}
|
||||||
|
if ($latestMtime !== null) {
|
||||||
|
$result['latest_mtime'] = date(DATE_TIME_FORMAT, $latestMtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/* Helpers (private) */
|
/* Helpers (private) */
|
||||||
private static function isSafeSegment(string $name): bool
|
private static function isSafeSegment(string $name): bool
|
||||||
|
|||||||
Reference in New Issue
Block a user