Show root access in sidebar and normalize write permissions
@@ -36,10 +36,12 @@
36
36
37
37
## server/routes/admin.js
38
38
- POST /api/admin/users - Creates a new user and enforces case-insensitive username uniqueness.
39
- normalizePermissions(permissions) - Normalizes permission maps and enforces that write access implies read access.
39
40
40
41
## server/routes/files.js
41
42
- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.
42
43
- POST /api/files/root-alias - Sets a display-only alias for an exact configured root path (no filesystem rename).
44
- GET /api/files/root-access - Returns users who can access an exact configured root and their access mode (R / R+W).
43
45
- GET /api/files/thumbnail - Serves cache-only thumbnail images for authorized files; returns 404 while cache is not ready.
44
46
45
47
## public/app.js
@@ -55,10 +57,11 @@
55
57
- showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().
56
58
- showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.
57
59
- loadThumbnails() - Registers visible file icons for lazy thumbnail loading; retries missing cache thumbnails during incremental refresh.
58
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files.
60
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404.
59
61
- getThumbnailKind(name) - Classifies files into image/text/badge thumbnail strategies.
60
62
- observeThumbnailIcon(iconEl) - Defers thumbnail fetch work until file icons are near/in the viewport.
61
63
- disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.
64
- setThumbnailPending(iconEl, pending) - Toggles per-icon pending spinner state while a cached image thumbnail is not ready yet.
62
65
- buildThumbnailSource(item, blob, kind) - Produces thumbnail image source (data/blob URL) for icon injection.
63
66
64
67
## tests/thumbnail-cache.test.js
@@ -92,6 +95,10 @@
92
95
- makeFileItem(item) - Builds a .file-item element; roots in Home now use folder-like interaction (single-click focus, double-click open), roots are non-draggable, and mobile long-press contextmenu suppression remains.
93
96
- attachMobileLongPress(el, item) - Adds mobile long-press detection on file/folder tiles to open the item sidebar without desktop side effects.
94
97
- openSidebar(item) - Renders item details/actions in sidebar; roots show alias + original name + usage stats, hide Move To/Delete, keep Rename.
98
- fetchRootAccessList(rootPath) - Fetches root access users from the server for a specific configured root.
99
- formatRootAccessList(users) - Formats root access entries as "username mode" values for sidebar rendering.
100
- openSidebar(item) - Renders item details/actions in sidebar; root selections include alias/original name/usage/access list and keep Rename while hiding Move To/Delete.
101
- openFolderSidebar() - Shows current folder details when nothing is selected; when at root base-level it also shows root access list.
95
102
- openRenameModal(item) - Renames files/folders; for roots this writes display alias via /api/files/root-alias and reloads roots.
96
103
97
104
## public/drag-move.js
@@ -36,10 +36,12 @@36
36
37
## server/routes/admin.js37
## server/routes/admin.js38
- POST /api/admin/users - Creates a new user and enforces case-insensitive username uniqueness.38
- POST /api/admin/users - Creates a new user and enforces case-insensitive username uniqueness.39
- normalizePermissions(permissions) - Normalizes permission maps and enforces that write access implies read access.39
40
40
## server/routes/files.js41
## server/routes/files.js41
- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.42
- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.42
- POST /api/files/root-alias - Sets a display-only alias for an exact configured root path (no filesystem rename).43
- POST /api/files/root-alias - Sets a display-only alias for an exact configured root path (no filesystem rename).44
- GET /api/files/root-access - Returns users who can access an exact configured root and their access mode (R / R+W).43
- GET /api/files/thumbnail - Serves cache-only thumbnail images for authorized files; returns 404 while cache is not ready.45
- GET /api/files/thumbnail - Serves cache-only thumbnail images for authorized files; returns 404 while cache is not ready.44
46
45
## public/app.js47
## public/app.js@@ -55,10 +57,11 @@55
- showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().57
- showPrompt(title, message, defaultValue) - In-page text-input dialog; returns Promise<string|null>. Use instead of window.prompt().56
- showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.58
- showOverwrite(filename) - In-page overwrite-decision dialog for file conflicts; returns Promise<'yes'|'no'|'all'|'none'>.57
- loadThumbnails() - Registers visible file icons for lazy thumbnail loading; retries missing cache thumbnails during incremental refresh.59
- loadThumbnails() - Registers visible file icons for lazy thumbnail loading; retries missing cache thumbnails during incremental refresh.58
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files.60
- loadOneThumbnail(iconEl) - Loads thumbnails from server cache endpoint for images, text snapshots for text files, and badges for other files; marks image icons as pending when cache returns 404.59
- getThumbnailKind(name) - Classifies files into image/text/badge thumbnail strategies.61
- getThumbnailKind(name) - Classifies files into image/text/badge thumbnail strategies.60
- observeThumbnailIcon(iconEl) - Defers thumbnail fetch work until file icons are near/in the viewport.62
- observeThumbnailIcon(iconEl) - Defers thumbnail fetch work until file icons are near/in the viewport.61
- disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.63
- disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.64
- setThumbnailPending(iconEl, pending) - Toggles per-icon pending spinner state while a cached image thumbnail is not ready yet.62
- buildThumbnailSource(item, blob, kind) - Produces thumbnail image source (data/blob URL) for icon injection.65
- buildThumbnailSource(item, blob, kind) - Produces thumbnail image source (data/blob URL) for icon injection.63
66
64
## tests/thumbnail-cache.test.js67
## tests/thumbnail-cache.test.js@@ -92,6 +95,10 @@92
- makeFileItem(item) - Builds a .file-item element; roots in Home now use folder-like interaction (single-click focus, double-click open), roots are non-draggable, and mobile long-press contextmenu suppression remains.95
- makeFileItem(item) - Builds a .file-item element; roots in Home now use folder-like interaction (single-click focus, double-click open), roots are non-draggable, and mobile long-press contextmenu suppression remains.93
- attachMobileLongPress(el, item) - Adds mobile long-press detection on file/folder tiles to open the item sidebar without desktop side effects.96
- attachMobileLongPress(el, item) - Adds mobile long-press detection on file/folder tiles to open the item sidebar without desktop side effects.94
- openSidebar(item) - Renders item details/actions in sidebar; roots show alias + original name + usage stats, hide Move To/Delete, keep Rename.97
- openSidebar(item) - Renders item details/actions in sidebar; roots show alias + original name + usage stats, hide Move To/Delete, keep Rename.98
- fetchRootAccessList(rootPath) - Fetches root access users from the server for a specific configured root.99
- formatRootAccessList(users) - Formats root access entries as "username mode" values for sidebar rendering.100
- openSidebar(item) - Renders item details/actions in sidebar; root selections include alias/original name/usage/access list and keep Rename while hiding Move To/Delete.101
- openFolderSidebar() - Shows current folder details when nothing is selected; when at root base-level it also shows root access list.95
- openRenameModal(item) - Renames files/folders; for roots this writes display alias via /api/files/root-alias and reloads roots.102
- openRenameModal(item) - Renames files/folders; for roots this writes display alias via /api/files/root-alias and reloads roots.96
103
97
## public/drag-move.js104
## public/drag-move.js@@ -13,6 +13,8 @@
13
13
- `GET /api/admin/config`
14
14
- `PUT /api/admin/config`
15
15
- `POST /api/admin/shutdown`
16
- `normalizes permissions so write implies read on create`
17
- `normalizes permissions so write implies read on update`
16
18
17
19
---
18
20
@@ -45,6 +47,9 @@
45
47
- `GET /api/files/thumbnail`
46
48
- `returns 404 while cached thumbnail is not ready`
47
49
- `serves cached thumbnail file when available`
50
- `GET /api/files/root-access`
51
- `returns users with R/R+W modes for an exact root path`
52
- `rejects non-exact nested root paths`
48
53
49
54
---
50
55
@@ -62,5 +67,7 @@
62
67
- `suppresses default context menu on mobile file long-press`
63
68
- `in Home, root tiles single-click focus and double-click open`
64
69
- `root sidebar shows alias and original name, and excludes Move to action`
70
- `base-level root sidebar shows access list with no item selected`
71
- `shows pending icon spinner when image thumbnail cache is not ready`
65
72
66
73
---
@@ -13,6 +13,8 @@13
- `GET /api/admin/config`13
- `GET /api/admin/config`14
- `PUT /api/admin/config`14
- `PUT /api/admin/config`15
- `POST /api/admin/shutdown`15
- `POST /api/admin/shutdown`16
- `normalizes permissions so write implies read on create`17
- `normalizes permissions so write implies read on update`16
18
17
---19
---18
20
@@ -45,6 +47,9 @@45
- `GET /api/files/thumbnail`47
- `GET /api/files/thumbnail`46
- `returns 404 while cached thumbnail is not ready`48
- `returns 404 while cached thumbnail is not ready`47
- `serves cached thumbnail file when available`49
- `serves cached thumbnail file when available`50
- `GET /api/files/root-access`51
- `returns users with R/R+W modes for an exact root path`52
- `rejects non-exact nested root paths`48
53
49
---54
---50
55
@@ -62,5 +67,7 @@62
- `suppresses default context menu on mobile file long-press`67
- `suppresses default context menu on mobile file long-press`63
- `in Home, root tiles single-click focus and double-click open`68
- `in Home, root tiles single-click focus and double-click open`64
- `root sidebar shows alias and original name, and excludes Move to action`69
- `root sidebar shows alias and original name, and excludes Move to action`70
- `base-level root sidebar shows access list with no item selected`71
- `shows pending icon spinner when image thumbnail cache is not ready`65
72
66
---73
---@@ -1103,6 +1103,14 @@ async function openSidebar (item)
1103
1103
<dt>Remaining</dt><dd>${free}</dd>
1104
1104
`;
1105
1105
}
1106
1107
const accessUsers = await fetchRootAccessList(item.path);
1108
if (accessUsers)
1109
{
1110
dl.innerHTML += `
1111
<dt>Access</dt><dd>${formatRootAccessList(accessUsers)}</dd>
1112
`;
1113
}
1106
1114
}
1107
1115
1108
1116
const btnOpen = document.createElement('button');
@@ -1167,11 +1175,27 @@ function openFolderSidebar ()
1167
1175
1168
1176
const dirs = STATE.items.filter(i => i.isDir).length;
1169
1177
const files = STATE.items.length - dirs;
1170
dl.innerHTML = `
1178
const baseDetails = `
1171
1179
<dt>Path</dt><dd>${STATE.currentDir}</dd>
1172
1180
<dt>Folders</dt><dd>${dirs}</dd>
1173
1181
<dt>Files</dt><dd>${files}</dd>
1174
1182
`;
1183
dl.innerHTML = baseDetails;
1184
1185
if (samePath(STATE.currentDir, STATE.currentRoot.path))
1186
{
1187
dl.innerHTML += '<dt>Access</dt><dd>Loading…</dd>';
1188
const currentDirAtStart = STATE.currentDir;
1189
const currentRootPathAtStart = STATE.currentRoot.path;
1190
void fetchRootAccessList(currentRootPathAtStart).then((accessUsers) =>
1191
{
1192
if (!accessUsers) return;
1193
if (!STATE.currentRoot) return;
1194
if (!samePath(STATE.currentDir, currentDirAtStart)) return;
1195
if (!samePath(STATE.currentRoot.path, currentRootPathAtStart)) return;
1196
dl.innerHTML = `${baseDetails}<dt>Access</dt><dd>${formatRootAccessList(accessUsers)}</dd>`;
1197
});
1198
}
1175
1199
}
1176
1200
1177
1201
function closeSidebar ()
@@ -1207,6 +1231,20 @@ function basenameOfPath (p)
1207
1231
return parts.length ? parts[parts.length - 1] : String(p || '');
1208
1232
}
1209
1233
1234
async function fetchRootAccessList (rootPath)
1235
{
1236
if (!rootPath) return null;
1237
const data = await api('GET', `/files/root-access?rootPath=${encodeURIComponent(rootPath)}`).catch(() => null);
1238
if (!data || !Array.isArray(data.users)) return null;
1239
return data.users;
1240
}
1241
1242
function formatRootAccessList (users)
1243
{
1244
if (!Array.isArray(users) || users.length === 0) return 'No users';
1245
return users.map(u => `${u.username} ${u.mode}`).join(', ');
1246
}
1247
1210
1248
function rootPermissionLabel (root)
1211
1249
{
1212
1250
return (root && (root.originalName || root.label)) || '';
@@ -2569,6 +2607,20 @@ function disconnectThumbnailObserver ()
2569
2607
STATE.thumbnailObserver = null;
2570
2608
}
2571
2609
2610
function setThumbnailPending (iconEl, pending)
2611
{
2612
if (!iconEl) return;
2613
if (pending)
2614
{
2615
iconEl.classList.add('thumb-pending');
2616
iconEl.dataset.thumbPending = '1';
2617
return;
2618
}
2619
2620
iconEl.classList.remove('thumb-pending');
2621
delete iconEl.dataset.thumbPending;
2622
}
2623
2572
2624
function getThumbnailKind (name)
2573
2625
{
2574
2626
const ext = extOf(name || '');
@@ -2734,6 +2786,7 @@ async function loadOneThumbnail (iconEl)
2734
2786
2735
2787
if (kind === 'badge')
2736
2788
{
2789
setThumbnailPending(iconEl, false);
2737
2790
srcUrl = badgeThumbnailDataUrl(item.name, kind);
2738
2791
}
2739
2792
else if (kind === 'image')
@@ -2754,7 +2807,14 @@ async function loadOneThumbnail (iconEl)
2754
2807
return;
2755
2808
}
2756
2809
2810
if (res.status === 404)
2811
{
2812
setThumbnailPending(iconEl, true);
2813
return;
2814
}
2815
2757
2816
if (!res.ok || !iconEl.isConnected) return;
2817
setThumbnailPending(iconEl, false);
2758
2818
2759
2819
const blob = await res.blob();
2760
2820
srcUrl = URL.createObjectURL(blob);
@@ -2762,6 +2822,7 @@ async function loadOneThumbnail (iconEl)
2762
2822
}
2763
2823
else
2764
2824
{
2825
setThumbnailPending(iconEl, false);
2765
2826
const maxBytes = maxThumbBytesForKind(kind);
2766
2827
if (maxBytes > 0 && typeof item.size === 'number' && item.size > maxBytes)
2767
2828
{
@@ -1103,6 +1103,14 @@ async function openSidebar (item)1103
<dt>Remaining</dt><dd>${free}</dd>1103
<dt>Remaining</dt><dd>${free}</dd>1104
`;1104
`;1105
}1105
}1106
1107
const accessUsers = await fetchRootAccessList(item.path);1108
if (accessUsers)1109
{1110
dl.innerHTML += `1111
<dt>Access</dt><dd>${formatRootAccessList(accessUsers)}</dd>1112
`;1113
}1106
}1114
}1107
1115
1108
const btnOpen = document.createElement('button');1116
const btnOpen = document.createElement('button');@@ -1167,11 +1175,27 @@ function openFolderSidebar ()1167
1175
1168
const dirs = STATE.items.filter(i => i.isDir).length;1176
const dirs = STATE.items.filter(i => i.isDir).length;1169
const files = STATE.items.length - dirs;1177
const files = STATE.items.length - dirs;1170
dl.innerHTML = `1178
const baseDetails = `1171
<dt>Path</dt><dd>${STATE.currentDir}</dd>1179
<dt>Path</dt><dd>${STATE.currentDir}</dd>1172
<dt>Folders</dt><dd>${dirs}</dd>1180
<dt>Folders</dt><dd>${dirs}</dd>1173
<dt>Files</dt><dd>${files}</dd>1181
<dt>Files</dt><dd>${files}</dd>1174
`;1182
`;1183
dl.innerHTML = baseDetails;1184
1185
if (samePath(STATE.currentDir, STATE.currentRoot.path))1186
{1187
dl.innerHTML += '<dt>Access</dt><dd>Loading…</dd>';1188
const currentDirAtStart = STATE.currentDir;1189
const currentRootPathAtStart = STATE.currentRoot.path;1190
void fetchRootAccessList(currentRootPathAtStart).then((accessUsers) =>1191
{1192
if (!accessUsers) return;1193
if (!STATE.currentRoot) return;1194
if (!samePath(STATE.currentDir, currentDirAtStart)) return;1195
if (!samePath(STATE.currentRoot.path, currentRootPathAtStart)) return;1196
dl.innerHTML = `${baseDetails}<dt>Access</dt><dd>${formatRootAccessList(accessUsers)}</dd>`;1197
});1198
}1175
}1199
}1176
1200
1177
function closeSidebar ()1201
function closeSidebar ()@@ -1207,6 +1231,20 @@ function basenameOfPath (p)1207
return parts.length ? parts[parts.length - 1] : String(p || '');1231
return parts.length ? parts[parts.length - 1] : String(p || '');1208
}1232
}1209
1233
1234
async function fetchRootAccessList (rootPath)1235
{1236
if (!rootPath) return null;1237
const data = await api('GET', `/files/root-access?rootPath=${encodeURIComponent(rootPath)}`).catch(() => null);1238
if (!data || !Array.isArray(data.users)) return null;1239
return data.users;1240
}1241
1242
function formatRootAccessList (users)1243
{1244
if (!Array.isArray(users) || users.length === 0) return 'No users';1245
return users.map(u => `${u.username} ${u.mode}`).join(', ');1246
}1247
1210
function rootPermissionLabel (root)1248
function rootPermissionLabel (root)1211
{1249
{1212
return (root && (root.originalName || root.label)) || '';1250
return (root && (root.originalName || root.label)) || '';@@ -2569,6 +2607,20 @@ function disconnectThumbnailObserver ()2569
STATE.thumbnailObserver = null;2607
STATE.thumbnailObserver = null;2570
}2608
}2571
2609
2610
function setThumbnailPending (iconEl, pending)2611
{2612
if (!iconEl) return;2613
if (pending)2614
{2615
iconEl.classList.add('thumb-pending');2616
iconEl.dataset.thumbPending = '1';2617
return;2618
}2619
2620
iconEl.classList.remove('thumb-pending');2621
delete iconEl.dataset.thumbPending;2622
}2623
2572
function getThumbnailKind (name)2624
function getThumbnailKind (name)2573
{2625
{2574
const ext = extOf(name || '');2626
const ext = extOf(name || '');@@ -2734,6 +2786,7 @@ async function loadOneThumbnail (iconEl)2734
2786
2735
if (kind === 'badge')2787
if (kind === 'badge')2736
{2788
{2789
setThumbnailPending(iconEl, false);2737
srcUrl = badgeThumbnailDataUrl(item.name, kind);2790
srcUrl = badgeThumbnailDataUrl(item.name, kind);2738
}2791
}2739
else if (kind === 'image')2792
else if (kind === 'image')@@ -2754,7 +2807,14 @@ async function loadOneThumbnail (iconEl)2754
return;2807
return;2755
}2808
}2756
2809
2810
if (res.status === 404)2811
{2812
setThumbnailPending(iconEl, true);2813
return;2814
}2815
2757
if (!res.ok || !iconEl.isConnected) return;2816
if (!res.ok || !iconEl.isConnected) return;2817
setThumbnailPending(iconEl, false);2758
2818
2759
const blob = await res.blob();2819
const blob = await res.blob();2760
srcUrl = URL.createObjectURL(blob);2820
srcUrl = URL.createObjectURL(blob);@@ -2762,6 +2822,7 @@ async function loadOneThumbnail (iconEl)2762
}2822
}2763
else2823
else2764
{2824
{2825
setThumbnailPending(iconEl, false);2765
const maxBytes = maxThumbBytesForKind(kind);2826
const maxBytes = maxThumbBytesForKind(kind);2766
if (maxBytes > 0 && typeof item.size === 'number' && item.size > maxBytes)2827
if (maxBytes > 0 && typeof item.size === 'number' && item.size > maxBytes)2767
{2828
{@@ -308,6 +308,27 @@ button.danger:hover {
308
308
display: flex;
309
309
align-items: center;
310
310
justify-content: center;
311
position: relative;
312
}
313
314
.file-item .icon.thumb-pending::after {
315
content: '';
316
position: absolute;
317
width: 14px;
318
height: 14px;
319
right: -2px;
320
bottom: -2px;
321
border: 2px solid rgba(232, 234, 240, 0.35);
322
border-top-color: var(--accent);
323
border-radius: 50%;
324
animation: icon-thumb-spin 0.75s linear infinite;
325
background: rgba(15, 17, 23, 0.85);
326
}
327
328
@keyframes icon-thumb-spin {
329
to {
330
transform: rotate(360deg);
331
}
311
332
}
312
333
313
334
.file-item .icon svg {
@@ -308,6 +308,27 @@ button.danger:hover {308
display: flex;308
display: flex;309
align-items: center;309
align-items: center;310
justify-content: center;310
justify-content: center;311
position: relative;312
}313
314
.file-item .icon.thumb-pending::after {315
content: '';316
position: absolute;317
width: 14px;318
height: 14px;319
right: -2px;320
bottom: -2px;321
border: 2px solid rgba(232, 234, 240, 0.35);322
border-top-color: var(--accent);323
border-radius: 50%;324
animation: icon-thumb-spin 0.75s linear infinite;325
background: rgba(15, 17, 23, 0.85);326
}327
328
@keyframes icon-thumb-spin {329
to {330
transform: rotate(360deg);331
}311
}332
}312
333
313
.file-item .icon svg {334
.file-item .icon svg {@@ -11,6 +11,23 @@ const { loadConfig, saveConfig, getEffectivePaths } = require('../config');
11
11
12
12
const BCRYPT_ROUNDS = 12;
13
13
14
function normalizePermissions (permissions)
15
{
16
if (!permissions || typeof permissions !== 'object') return {};
17
18
const normalized = {};
19
for (const [key, value] of Object.entries(permissions))
20
{
21
if (!value || typeof value !== 'object') continue;
22
const write = !!value.write;
23
const read = !!value.read || write;
24
if (!read && !write) continue;
25
normalized[key] = { read, write };
26
}
27
28
return normalized;
29
}
30
14
31
// All admin routes require authentication + admin privilege
15
32
router.use(requireAuth, requireAdmin);
16
33
@@ -50,9 +67,10 @@ router.post('/users', (req, res) =>
50
67
const exists = db.prepare('SELECT id FROM users WHERE username = ? COLLATE NOCASE').get([username]);
51
68
if (exists) return res.status(409).json({ error: 'Username already exists.' });
52
69
70
const normalizedPermissions = normalizePermissions(permissions);
53
71
const hash = bcrypt.hashSync(password, BCRYPT_ROUNDS);
54
72
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)').run(
55
[username, hash, isAdmin ? 1 : 0, JSON.stringify(permissions || {})]
73
[username, hash, isAdmin ? 1 : 0, JSON.stringify(normalizedPermissions)]
56
74
);
57
75
58
76
res.status(201).json({ ok: true });
@@ -95,7 +113,8 @@ router.patch('/users/:id', (req, res) =>
95
113
96
114
if (permissions !== undefined)
97
115
{
98
db.prepare('UPDATE users SET permissions = ? WHERE id = ?').run([JSON.stringify(permissions), user.id]);
116
const normalizedPermissions = normalizePermissions(permissions);
117
db.prepare('UPDATE users SET permissions = ? WHERE id = ?').run([JSON.stringify(normalizedPermissions), user.id]);
99
118
}
100
119
101
120
res.json({ ok: true });
@@ -11,6 +11,23 @@ const { loadConfig, saveConfig, getEffectivePaths } = require('../config');11
11
12
const BCRYPT_ROUNDS = 12;12
const BCRYPT_ROUNDS = 12;13
13
14
function normalizePermissions (permissions)15
{16
if (!permissions || typeof permissions !== 'object') return {};17
18
const normalized = {};19
for (const [key, value] of Object.entries(permissions))20
{21
if (!value || typeof value !== 'object') continue;22
const write = !!value.write;23
const read = !!value.read || write;24
if (!read && !write) continue;25
normalized[key] = { read, write };26
}27
28
return normalized;29
}30
14
// All admin routes require authentication + admin privilege31
// All admin routes require authentication + admin privilege15
router.use(requireAuth, requireAdmin);32
router.use(requireAuth, requireAdmin);16
33
@@ -50,9 +67,10 @@ router.post('/users', (req, res) =>50
const exists = db.prepare('SELECT id FROM users WHERE username = ? COLLATE NOCASE').get([username]);67
const exists = db.prepare('SELECT id FROM users WHERE username = ? COLLATE NOCASE').get([username]);51
if (exists) return res.status(409).json({ error: 'Username already exists.' });68
if (exists) return res.status(409).json({ error: 'Username already exists.' });52
69
70
const normalizedPermissions = normalizePermissions(permissions);53
const hash = bcrypt.hashSync(password, BCRYPT_ROUNDS);71
const hash = bcrypt.hashSync(password, BCRYPT_ROUNDS);54
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)').run(72
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)').run(55
[username, hash, isAdmin ? 1 : 0, JSON.stringify(permissions || {})]73
[username, hash, isAdmin ? 1 : 0, JSON.stringify(normalizedPermissions)]56
);74
);57
75
58
res.status(201).json({ ok: true });76
res.status(201).json({ ok: true });@@ -95,7 +113,8 @@ router.patch('/users/:id', (req, res) =>95
113
96
if (permissions !== undefined)114
if (permissions !== undefined)97
{115
{98
db.prepare('UPDATE users SET permissions = ? WHERE id = ?').run([JSON.stringify(permissions), user.id]);116
const normalizedPermissions = normalizePermissions(permissions);117
db.prepare('UPDATE users SET permissions = ? WHERE id = ?').run([JSON.stringify(normalizedPermissions), user.id]);99
}118
}100
119
101
res.json({ ok: true });120
res.json({ ok: true });@@ -194,6 +194,75 @@ router.get('/roots', requireAuth, (req, res) =>
194
194
res.json({ roots: readable });
195
195
});
196
196
197
// ---------------------------------------------------------------------------
198
// GET /api/files/root-access?rootPath=<absolute-root-path>
199
// Returns users that can access a configured root and their mode (R / R+W).
200
// ---------------------------------------------------------------------------
201
router.get('/root-access', requireAuth, (req, res) =>
202
{
203
const rootPath = String(req.query.rootPath || '').trim();
204
if (!rootPath)
205
{
206
return res.status(400).json({ error: 'rootPath is required.' });
207
}
208
209
const config = loadConfig();
210
const roots = getEffectivePaths(config.paths || []);
211
const info = resolveRoot(rootPath, roots);
212
if (!info) return res.status(403).json({ error: 'Access denied.' });
213
if (!sameResolvedPath(rootPath, info.root))
214
{
215
return res.status(400).json({ error: 'rootPath must be an exact configured root.' });
216
}
217
if (!canRead(req.user, info.label))
218
{
219
return res.status(403).json({ error: 'Access denied.' });
220
}
221
222
const db = getDb();
223
const rows = db.prepare('SELECT username, is_admin, permissions FROM users').all();
224
const users = [];
225
226
for (const row of rows)
227
{
228
if (row.is_admin === 1)
229
{
230
users.push({ username: row.username, mode: 'R+W' });
231
continue;
232
}
233
234
let permissions = {};
235
try
236
{
237
permissions = JSON.parse(row.permissions || '{}');
238
} catch
239
{
240
permissions = {};
241
}
242
243
const perm = permissions[info.label];
244
if (!perm || typeof perm !== 'object') continue;
245
const canWriteRoot = !!perm.write;
246
const canReadRoot = !!perm.read || canWriteRoot;
247
if (!canReadRoot) continue;
248
users.push({ username: row.username, mode: canWriteRoot ? 'R+W' : 'R' });
249
}
250
251
users.sort((a, b) => String(a.username).localeCompare(String(b.username)));
252
253
const rootAliases = rootAliasesFromConfig(config);
254
const alias = String(rootAliases[path.resolve(info.root)] || '').trim();
255
res.json({
256
root: {
257
path: info.root,
258
label: alias || info.label,
259
originalName: info.label,
260
alias: alias || null,
261
},
262
users,
263
});
264
});
265
197
266
// ---------------------------------------------------------------------------
198
267
// POST /api/files/root-alias
199
268
// Body: { rootPath: <absolute-root-path>, alias: <display-alias> }
@@ -194,6 +194,75 @@ router.get('/roots', requireAuth, (req, res) =>194
res.json({ roots: readable });194
res.json({ roots: readable });195
});195
});196
196
197
// ---------------------------------------------------------------------------198
// GET /api/files/root-access?rootPath=<absolute-root-path>199
// Returns users that can access a configured root and their mode (R / R+W).200
// ---------------------------------------------------------------------------201
router.get('/root-access', requireAuth, (req, res) =>202
{203
const rootPath = String(req.query.rootPath || '').trim();204
if (!rootPath)205
{206
return res.status(400).json({ error: 'rootPath is required.' });207
}208
209
const config = loadConfig();210
const roots = getEffectivePaths(config.paths || []);211
const info = resolveRoot(rootPath, roots);212
if (!info) return res.status(403).json({ error: 'Access denied.' });213
if (!sameResolvedPath(rootPath, info.root))214
{215
return res.status(400).json({ error: 'rootPath must be an exact configured root.' });216
}217
if (!canRead(req.user, info.label))218
{219
return res.status(403).json({ error: 'Access denied.' });220
}221
222
const db = getDb();223
const rows = db.prepare('SELECT username, is_admin, permissions FROM users').all();224
const users = [];225
226
for (const row of rows)227
{228
if (row.is_admin === 1)229
{230
users.push({ username: row.username, mode: 'R+W' });231
continue;232
}233
234
let permissions = {};235
try236
{237
permissions = JSON.parse(row.permissions || '{}');238
} catch239
{240
permissions = {};241
}242
243
const perm = permissions[info.label];244
if (!perm || typeof perm !== 'object') continue;245
const canWriteRoot = !!perm.write;246
const canReadRoot = !!perm.read || canWriteRoot;247
if (!canReadRoot) continue;248
users.push({ username: row.username, mode: canWriteRoot ? 'R+W' : 'R' });249
}250
251
users.sort((a, b) => String(a.username).localeCompare(String(b.username)));252
253
const rootAliases = rootAliasesFromConfig(config);254
const alias = String(rootAliases[path.resolve(info.root)] || '').trim();255
res.json({256
root: {257
path: info.root,258
label: alias || info.label,259
originalName: info.label,260
alias: alias || null,261
},262
users,263
});264
});265
197
// ---------------------------------------------------------------------------266
// ---------------------------------------------------------------------------198
// POST /api/files/root-alias267
// POST /api/files/root-alias199
// Body: { rootPath: <absolute-root-path>, alias: <display-alias> }268
// Body: { rootPath: <absolute-root-path>, alias: <display-alias> }@@ -172,6 +172,21 @@ describe('POST /api/admin/users', () =>
172
172
});
173
173
expect(status).toBe(400);
174
174
});
175
176
test('normalizes permissions so write implies read on create', async () =>
177
{
178
const { status } = await req('POST', '/api/admin/users', {
179
username: 'dora',
180
password: 'dora-pass1',
181
isAdmin: false,
182
permissions: { data: { read: false, write: true } },
183
});
184
expect(status).toBe(201);
185
186
const { body } = await req('GET', '/api/admin/users');
187
const dora = body.users.find(u => u.username === 'dora');
188
expect(dora.permissions).toMatchObject({ data: { read: true, write: true } });
189
});
175
190
});
176
191
177
192
describe('PATCH /api/admin/users/:id', () =>
@@ -198,6 +213,18 @@ describe('PATCH /api/admin/users/:id', () =>
198
213
const { status } = await req('PATCH', '/api/admin/users/99999', { isAdmin: false });
199
214
expect(status).toBe(404);
200
215
});
216
217
test('normalizes permissions so write implies read on update', async () =>
218
{
219
const { status } = await req('PATCH', `/api/admin/users/${bobId}`, {
220
permissions: { data: { read: false, write: true } },
221
});
222
expect(status).toBe(200);
223
224
const { body } = await req('GET', '/api/admin/users');
225
const bob = body.users.find(u => u.id === bobId);
226
expect(bob.permissions).toMatchObject({ data: { read: true, write: true } });
227
});
201
228
});
202
229
203
230
describe('DELETE /api/admin/users/:id', () =>
@@ -172,6 +172,21 @@ describe('POST /api/admin/users', () =>172
});172
});173
expect(status).toBe(400);173
expect(status).toBe(400);174
});174
});175
176
test('normalizes permissions so write implies read on create', async () =>177
{178
const { status } = await req('POST', '/api/admin/users', {179
username: 'dora',180
password: 'dora-pass1',181
isAdmin: false,182
permissions: { data: { read: false, write: true } },183
});184
expect(status).toBe(201);185
186
const { body } = await req('GET', '/api/admin/users');187
const dora = body.users.find(u => u.username === 'dora');188
expect(dora.permissions).toMatchObject({ data: { read: true, write: true } });189
});175
});190
});176
191
177
describe('PATCH /api/admin/users/:id', () =>192
describe('PATCH /api/admin/users/:id', () =>@@ -198,6 +213,18 @@ describe('PATCH /api/admin/users/:id', () =>198
const { status } = await req('PATCH', '/api/admin/users/99999', { isAdmin: false });213
const { status } = await req('PATCH', '/api/admin/users/99999', { isAdmin: false });199
expect(status).toBe(404);214
expect(status).toBe(404);200
});215
});216
217
test('normalizes permissions so write implies read on update', async () =>218
{219
const { status } = await req('PATCH', `/api/admin/users/${bobId}`, {220
permissions: { data: { read: false, write: true } },221
});222
expect(status).toBe(200);223
224
const { body } = await req('GET', '/api/admin/users');225
const bob = body.users.find(u => u.id === bobId);226
expect(bob.permissions).toMatchObject({ data: { read: true, write: true } });227
});201
});228
});202
229
203
describe('DELETE /api/admin/users/:id', () =>230
describe('DELETE /api/admin/users/:id', () =>@@ -22,6 +22,13 @@ jest.mock('../server/db', () =>
22
22
{
23
23
db = new Database(':memory:');
24
24
db.exec(`
25
CREATE TABLE IF NOT EXISTS users (
26
id INTEGER PRIMARY KEY AUTOINCREMENT,
27
username TEXT UNIQUE NOT NULL,
28
password_hash TEXT NOT NULL,
29
is_admin INTEGER NOT NULL DEFAULT 0,
30
permissions TEXT NOT NULL DEFAULT '{}'
31
);
25
32
CREATE TABLE IF NOT EXISTS file_meta (
26
33
file_path TEXT PRIMARY KEY,
27
34
uploader TEXT NOT NULL DEFAULT '',
@@ -107,6 +114,7 @@ beforeEach(() =>
107
114
mockThumbPath = null;
108
115
const db = getDb();
109
116
db.prepare('DELETE FROM file_meta').run([]);
117
db.prepare('DELETE FROM users').run([]);
110
118
});
111
119
112
120
function req (method, routePath, body)
@@ -292,3 +300,38 @@ describe('GET /api/files/thumbnail', () =>
292
300
expect(response.body.toString('utf8')).toBe('webp-bytes');
293
301
});
294
302
});
303
304
describe('GET /api/files/root-access', () =>
305
{
306
test('returns users with R/R+W modes for an exact root path', async () =>
307
{
308
const label = path.basename(rootDir);
309
const db = getDb();
310
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')
311
.run(['admin', 'x', 1, '{}']);
312
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')
313
.run(['alice', 'x', 0, JSON.stringify({ [label]: { read: true, write: false } })]);
314
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')
315
.run(['bob', 'x', 0, JSON.stringify({ [label]: { read: true, write: true } })]);
316
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')
317
.run(['charlie', 'x', 0, JSON.stringify({ other: { read: true, write: false } })]);
318
319
const { status, body } = await req('GET', `/api/files/root-access?rootPath=${encodeURIComponent(rootDir)}`);
320
expect(status).toBe(200);
321
expect(body.root).toMatchObject({ path: rootDir, originalName: label });
322
expect(body.users).toEqual([
323
{ username: 'admin', mode: 'R+W' },
324
{ username: 'alice', mode: 'R' },
325
{ username: 'bob', mode: 'R+W' },
326
]);
327
});
328
329
test('rejects non-exact nested root paths', async () =>
330
{
331
const nested = path.join(rootDir, 'sub');
332
fs.mkdirSync(nested, { recursive: true });
333
334
const { status } = await req('GET', `/api/files/root-access?rootPath=${encodeURIComponent(nested)}`);
335
expect(status).toBe(400);
336
});
337
});
@@ -22,6 +22,13 @@ jest.mock('../server/db', () =>22
{22
{23
db = new Database(':memory:');23
db = new Database(':memory:');24
db.exec(`24
db.exec(`25
CREATE TABLE IF NOT EXISTS users (26
id INTEGER PRIMARY KEY AUTOINCREMENT,27
username TEXT UNIQUE NOT NULL,28
password_hash TEXT NOT NULL,29
is_admin INTEGER NOT NULL DEFAULT 0,30
permissions TEXT NOT NULL DEFAULT '{}'31
);25
CREATE TABLE IF NOT EXISTS file_meta (32
CREATE TABLE IF NOT EXISTS file_meta (26
file_path TEXT PRIMARY KEY,33
file_path TEXT PRIMARY KEY,27
uploader TEXT NOT NULL DEFAULT '',34
uploader TEXT NOT NULL DEFAULT '',@@ -107,6 +114,7 @@ beforeEach(() =>107
mockThumbPath = null;114
mockThumbPath = null;108
const db = getDb();115
const db = getDb();109
db.prepare('DELETE FROM file_meta').run([]);116
db.prepare('DELETE FROM file_meta').run([]);117
db.prepare('DELETE FROM users').run([]);110
});118
});111
119
112
function req (method, routePath, body)120
function req (method, routePath, body)@@ -292,3 +300,38 @@ describe('GET /api/files/thumbnail', () =>292
expect(response.body.toString('utf8')).toBe('webp-bytes');300
expect(response.body.toString('utf8')).toBe('webp-bytes');293
});301
});294
});302
});303
304
describe('GET /api/files/root-access', () =>305
{306
test('returns users with R/R+W modes for an exact root path', async () =>307
{308
const label = path.basename(rootDir);309
const db = getDb();310
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')311
.run(['admin', 'x', 1, '{}']);312
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')313
.run(['alice', 'x', 0, JSON.stringify({ [label]: { read: true, write: false } })]);314
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')315
.run(['bob', 'x', 0, JSON.stringify({ [label]: { read: true, write: true } })]);316
db.prepare('INSERT INTO users (username, password_hash, is_admin, permissions) VALUES (?, ?, ?, ?)')317
.run(['charlie', 'x', 0, JSON.stringify({ other: { read: true, write: false } })]);318
319
const { status, body } = await req('GET', `/api/files/root-access?rootPath=${encodeURIComponent(rootDir)}`);320
expect(status).toBe(200);321
expect(body.root).toMatchObject({ path: rootDir, originalName: label });322
expect(body.users).toEqual([323
{ username: 'admin', mode: 'R+W' },324
{ username: 'alice', mode: 'R' },325
{ username: 'bob', mode: 'R+W' },326
]);327
});328
329
test('rejects non-exact nested root paths', async () =>330
{331
const nested = path.join(rootDir, 'sub');332
fs.mkdirSync(nested, { recursive: true });333
334
const { status } = await req('GET', `/api/files/root-access?rootPath=${encodeURIComponent(nested)}`);335
expect(status).toBe(400);336
});337
});@@ -16,6 +16,8 @@ describe('page load smoke test', () =>
16
16
let listFixture;
17
17
let spaceFixture;
18
18
let meFixture;
19
let thumbnailStatusFixture;
20
let rootAccessFixture;
19
21
20
22
beforeEach(() =>
21
23
{
@@ -35,6 +37,8 @@ describe('page load smoke test', () =>
35
37
'/data': { usedBytes: 0, freeBytes: 1024 * 1024 },
36
38
};
37
39
meFixture = { username: 'tester', isAdmin: false, permissions: {} };
40
thumbnailStatusFixture = {};
41
rootAccessFixture = {};
38
42
});
39
43
40
44
beforeAll(async () =>
@@ -62,6 +66,21 @@ describe('page load smoke test', () =>
62
66
const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };
63
67
res.json(stats);
64
68
});
69
app.get('/api/files/thumbnail', (req, res) =>
70
{
71
const file = String(req.query.file || '');
72
const status = Number(thumbnailStatusFixture[file] || 200);
73
if (status === 404)
74
{
75
return res.status(404).json({ error: 'Thumbnail not ready.' });
76
}
77
res.type('image/webp').send('thumb');
78
});
79
app.get('/api/files/root-access', (req, res) =>
80
{
81
const rootPath = String(req.query.rootPath || '');
82
res.json({ users: rootAccessFixture[rootPath] || [] });
83
});
65
84
app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));
66
85
app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));
67
86
@@ -236,6 +255,12 @@ describe('page load smoke test', () =>
236
255
'/data-a': { usedBytes: 1024, freeBytes: 2048 },
237
256
'/data-b': { usedBytes: 2048, freeBytes: 1024 },
238
257
};
258
rootAccessFixture = {
259
'/data-a': [
260
{ username: 'alice', mode: 'R' },
261
{ username: 'bob', mode: 'R+W' },
262
],
263
};
239
264
240
265
const { dom, runtimeErrors } = await bootClient({
241
266
savedSession: {
@@ -258,6 +283,9 @@ describe('page load smoke test', () =>
258
283
expect(sidebarText).toContain('Shared');
259
284
expect(sidebarText).toContain('Original name');
260
285
expect(sidebarText).toContain('data-a');
286
expect(sidebarText).toContain('Access');
287
expect(sidebarText).toContain('alice R');
288
expect(sidebarText).toContain('bob R+W');
261
289
262
290
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);
263
291
expect(actionButtons).toContain('Rename');
@@ -266,4 +294,51 @@ describe('page load smoke test', () =>
266
294
267
295
dom.window.close();
268
296
});
297
298
test('base-level root sidebar shows access list with no item selected', async () =>
299
{
300
rootAccessFixture = {
301
'/data': [
302
{ username: 'tim', mode: 'R+W' },
303
{ username: 'guest', mode: 'R' },
304
],
305
};
306
307
const { dom, runtimeErrors } = await bootClient();
308
expect(runtimeErrors).toEqual([]);
309
310
await new Promise(resolve => dom.window.setTimeout(resolve, 80));
311
const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;
312
expect(sidebarText).toContain('Access');
313
expect(sidebarText).toContain('tim R+W');
314
expect(sidebarText).toContain('guest R');
315
316
dom.window.close();
317
});
318
319
test('shows pending icon spinner when image thumbnail cache is not ready', async () =>
320
{
321
listFixture = {
322
'/data': [
323
{
324
name: 'photo.png',
325
path: '/data/photo.png',
326
isDir: false,
327
size: 1024,
328
mtime: Date.now(),
329
},
330
],
331
};
332
thumbnailStatusFixture['/data/photo.png'] = 404;
333
334
const { dom, runtimeErrors } = await bootClient();
335
expect(runtimeErrors).toEqual([]);
336
337
await new Promise(resolve => dom.window.setTimeout(resolve, 80));
338
const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');
339
expect(icon).toBeTruthy();
340
expect(icon.classList.contains('thumb-pending')).toBe(true);
341
342
dom.window.close();
343
});
269
344
});
@@ -16,6 +16,8 @@ describe('page load smoke test', () =>16
let listFixture;16
let listFixture;17
let spaceFixture;17
let spaceFixture;18
let meFixture;18
let meFixture;19
let thumbnailStatusFixture;20
let rootAccessFixture;19
21
20
beforeEach(() =>22
beforeEach(() =>21
{23
{@@ -35,6 +37,8 @@ describe('page load smoke test', () =>35
'/data': { usedBytes: 0, freeBytes: 1024 * 1024 },37
'/data': { usedBytes: 0, freeBytes: 1024 * 1024 },36
};38
};37
meFixture = { username: 'tester', isAdmin: false, permissions: {} };39
meFixture = { username: 'tester', isAdmin: false, permissions: {} };40
thumbnailStatusFixture = {};41
rootAccessFixture = {};38
});42
});39
43
40
beforeAll(async () =>44
beforeAll(async () =>@@ -62,6 +66,21 @@ describe('page load smoke test', () =>62
const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };66
const stats = spaceFixture[dir] || { usedBytes: 0, freeBytes: null };63
res.json(stats);67
res.json(stats);64
});68
});69
app.get('/api/files/thumbnail', (req, res) =>70
{71
const file = String(req.query.file || '');72
const status = Number(thumbnailStatusFixture[file] || 200);73
if (status === 404)74
{75
return res.status(404).json({ error: 'Thumbnail not ready.' });76
}77
res.type('image/webp').send('thumb');78
});79
app.get('/api/files/root-access', (req, res) =>80
{81
const rootPath = String(req.query.rootPath || '');82
res.json({ users: rootAccessFixture[rootPath] || [] });83
});65
app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));84
app.post('/api/auth/logout', (req, res) => res.json({ ok: true }));66
app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));85
app.get('*', (req, res) => res.sendFile(path.join(publicDir, 'index.html')));67
86
@@ -236,6 +255,12 @@ describe('page load smoke test', () =>236
'/data-a': { usedBytes: 1024, freeBytes: 2048 },255
'/data-a': { usedBytes: 1024, freeBytes: 2048 },237
'/data-b': { usedBytes: 2048, freeBytes: 1024 },256
'/data-b': { usedBytes: 2048, freeBytes: 1024 },238
};257
};258
rootAccessFixture = {259
'/data-a': [260
{ username: 'alice', mode: 'R' },261
{ username: 'bob', mode: 'R+W' },262
],263
};239
264
240
const { dom, runtimeErrors } = await bootClient({265
const { dom, runtimeErrors } = await bootClient({241
savedSession: {266
savedSession: {@@ -258,6 +283,9 @@ describe('page load smoke test', () =>258
expect(sidebarText).toContain('Shared');283
expect(sidebarText).toContain('Shared');259
expect(sidebarText).toContain('Original name');284
expect(sidebarText).toContain('Original name');260
expect(sidebarText).toContain('data-a');285
expect(sidebarText).toContain('data-a');286
expect(sidebarText).toContain('Access');287
expect(sidebarText).toContain('alice R');288
expect(sidebarText).toContain('bob R+W');261
289
262
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);290
const actionButtons = Array.from(dom.window.document.querySelectorAll('#sidebar-actions button')).map(b => b.textContent);263
expect(actionButtons).toContain('Rename');291
expect(actionButtons).toContain('Rename');@@ -266,4 +294,51 @@ describe('page load smoke test', () =>266
294
267
dom.window.close();295
dom.window.close();268
});296
});297
298
test('base-level root sidebar shows access list with no item selected', async () =>299
{300
rootAccessFixture = {301
'/data': [302
{ username: 'tim', mode: 'R+W' },303
{ username: 'guest', mode: 'R' },304
],305
};306
307
const { dom, runtimeErrors } = await bootClient();308
expect(runtimeErrors).toEqual([]);309
310
await new Promise(resolve => dom.window.setTimeout(resolve, 80));311
const sidebarText = dom.window.document.getElementById('sidebar-meta').textContent;312
expect(sidebarText).toContain('Access');313
expect(sidebarText).toContain('tim R+W');314
expect(sidebarText).toContain('guest R');315
316
dom.window.close();317
});318
319
test('shows pending icon spinner when image thumbnail cache is not ready', async () =>320
{321
listFixture = {322
'/data': [323
{324
name: 'photo.png',325
path: '/data/photo.png',326
isDir: false,327
size: 1024,328
mtime: Date.now(),329
},330
],331
};332
thumbnailStatusFixture['/data/photo.png'] = 404;333
334
const { dom, runtimeErrors } = await bootClient();335
expect(runtimeErrors).toEqual([]);336
337
await new Promise(resolve => dom.window.setTimeout(resolve, 80));338
const icon = dom.window.document.querySelector('.icon[data-preview-path="/data/photo.png"]');339
expect(icon).toBeTruthy();340
expect(icon.classList.contains('thumb-pending')).toBe(true);341
342
dom.window.close();343
});269
});344
});