formatting
@@ -1797,16 +1797,16 @@ async function openSidebar (item)
1797
1797
renderSidebarDuplicates(item, null); // show loading state
1798
1798
const selectedPathAtRequest = item.path;
1799
1799
api('GET', `/files/duplicates?file=${encodeURIComponent(item.path)}`)
1800
.then((data) =>
1801
{
1802
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;
1803
renderSidebarDuplicates(item, data ? data.duplicates : []);
1804
})
1805
.catch(() =>
1806
{
1807
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;
1808
renderSidebarDuplicates(item, []);
1809
});
1800
.then((data) =>
1801
{
1802
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;
1803
renderSidebarDuplicates(item, data ? data.duplicates : []);
1804
})
1805
.catch(() =>
1806
{
1807
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;
1808
renderSidebarDuplicates(item, []);
1809
});
1810
1810
1811
1811
// View / download button
1812
1812
const btnDl = document.createElement('button');
@@ -2532,7 +2532,7 @@ async function openFolderIconPicker (item)
2532
2532
const blob = await r.blob();
2533
2533
const url = URL.createObjectURL(blob);
2534
2534
imgEl.src = url;
2535
}).catch(() => {});
2535
}).catch(() => { });
2536
2536
}
2537
2537
}
2538
2538
@@ -2800,8 +2800,8 @@ async function ensureVideoJsLoaded ()
2800
2800
2801
2801
function configureVideoJsBuffering (videojs)
2802
2802
{
2803
if (! VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED)
2804
return;
2803
if (!VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED)
2804
return;
2805
2805
2806
2806
if (!videojs || !videojs.Vhs || videojs.__filemanagerBufferingConfigured) return;
2807
2807
videojs.__filemanagerBufferingConfigured = true;
@@ -1797,16 +1797,16 @@ async function openSidebar (item)1797
renderSidebarDuplicates(item, null); // show loading state1797
renderSidebarDuplicates(item, null); // show loading state1798
const selectedPathAtRequest = item.path;1798
const selectedPathAtRequest = item.path;1799
api('GET', `/files/duplicates?file=${encodeURIComponent(item.path)}`)1799
api('GET', `/files/duplicates?file=${encodeURIComponent(item.path)}`)1800
.then((data) =>1800
.then((data) =>1801
{1801
{1802
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;1802
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;1803
renderSidebarDuplicates(item, data ? data.duplicates : []);1803
renderSidebarDuplicates(item, data ? data.duplicates : []);1804
})1804
})1805
.catch(() =>1805
.catch(() =>1806
{1806
{1807
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;1807
if (!STATE.selectedItem || STATE.selectedItem.path !== selectedPathAtRequest) return;1808
renderSidebarDuplicates(item, []);1808
renderSidebarDuplicates(item, []);1809
});1809
});1810
1810
1811
// View / download button1811
// View / download button1812
const btnDl = document.createElement('button');1812
const btnDl = document.createElement('button');@@ -2532,7 +2532,7 @@ async function openFolderIconPicker (item)2532
const blob = await r.blob();2532
const blob = await r.blob();2533
const url = URL.createObjectURL(blob);2533
const url = URL.createObjectURL(blob);2534
imgEl.src = url;2534
imgEl.src = url;2535
}).catch(() => {});2535
}).catch(() => { });2536
}2536
}2537
}2537
}2538
2538
@@ -2800,8 +2800,8 @@ async function ensureVideoJsLoaded ()2800
2800
2801
function configureVideoJsBuffering (videojs)2801
function configureVideoJsBuffering (videojs)2802
{2802
{2803
if (! VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED)2803
if (!VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED)2804
return;2804
return;2805
2805
2806
if (!videojs || !videojs.Vhs || videojs.__filemanagerBufferingConfigured) return;2806
if (!videojs || !videojs.Vhs || videojs.__filemanagerBufferingConfigured) return;2807
videojs.__filemanagerBufferingConfigured = true;2807
videojs.__filemanagerBufferingConfigured = true;@@ -327,8 +327,13 @@ button.danger:hover {
327
327
}
328
328
329
329
@keyframes icon-thumb-spin {
330
from { transform: translate(-50%, -50%) rotate(0deg); }
331
to { transform: translate(-50%, -50%) rotate(360deg); }
330
from {
331
transform: translate(-50%, -50%) rotate(0deg);
332
}
333
334
to {
335
transform: translate(-50%, -50%) rotate(360deg);
336
}
332
337
}
333
338
334
339
.file-item .icon svg {
@@ -327,8 +327,13 @@ button.danger:hover {327
}
327
}
328
328
329
@keyframes icon-thumb-spin {
329
@keyframes icon-thumb-spin {
330
from { transform: translate(-50%, -50%) rotate(0deg); }
330
from {
331
to { transform: translate(-50%, -50%) rotate(360deg); }
331
transform: translate(-50%, -50%) rotate(0deg);
332
}
333
334
to {
335
transform: translate(-50%, -50%) rotate(360deg);
336
}
332
}
337
}
333
338
334
.file-item .icon svg {
339
.file-item .icon svg {
@@ -284,7 +284,7 @@ function abortMultipartUpload (routePath, file)
284
284
});
285
285
}
286
286
287
async function waitFor(predicate, timeoutMs = 500)
287
async function waitFor (predicate, timeoutMs = 500)
288
288
{
289
289
const start = Date.now();
290
290
while (Date.now() - start < timeoutMs)
@@ -389,88 +389,88 @@ describe('POST /api/files/move', () =>
389
389
expect(body.error).toMatch(/folder into itself/i);
390
390
});
391
391
392
test('overwrites an existing destination when conflict strategy is overwrite', async () =>
393
{
394
const sourceFile = path.join(rootDir, 'source.txt');
395
const destinationDir = path.join(rootDir, 'dest');
396
fs.mkdirSync(destinationDir);
397
fs.writeFileSync(sourceFile, 'new-content');
398
fs.writeFileSync(path.join(destinationDir, 'source.txt'), 'old-content');
399
400
const { status, body } = await req('POST', '/api/files/move', {
401
from: sourceFile,
402
toDir: destinationDir,
403
conflict: 'overwrite',
404
});
392
test('overwrites an existing destination when conflict strategy is overwrite', async () =>
393
{
394
const sourceFile = path.join(rootDir, 'source.txt');
395
const destinationDir = path.join(rootDir, 'dest');
396
fs.mkdirSync(destinationDir);
397
fs.writeFileSync(sourceFile, 'new-content');
398
fs.writeFileSync(path.join(destinationDir, 'source.txt'), 'old-content');
405
399
406
expect(status).toBe(200);
407
expect(body.conflictResolution).toBe('overwrite');
408
expect(fs.existsSync(sourceFile)).toBe(false);
409
expect(fs.readFileSync(path.join(destinationDir, 'source.txt'), 'utf8')).toBe('new-content');
400
const { status, body } = await req('POST', '/api/files/move', {
401
from: sourceFile,
402
toDir: destinationDir,
403
conflict: 'overwrite',
410
404
});
411
405
412
test('renames destination when conflict strategy is rename', async () =>
413
{
414
const sourceFile = path.join(rootDir, 'report.txt');
415
const destinationDir = path.join(rootDir, 'dest');
416
fs.mkdirSync(destinationDir);
417
fs.writeFileSync(sourceFile, 'latest');
418
fs.writeFileSync(path.join(destinationDir, 'report.txt'), 'existing');
419
420
const { status, body } = await req('POST', '/api/files/move', {
421
from: sourceFile,
422
toDir: destinationDir,
423
conflict: 'rename',
424
});
406
expect(status).toBe(200);
407
expect(body.conflictResolution).toBe('overwrite');
408
expect(fs.existsSync(sourceFile)).toBe(false);
409
expect(fs.readFileSync(path.join(destinationDir, 'source.txt'), 'utf8')).toBe('new-content');
410
});
425
411
426
expect(status).toBe(200);
427
expect(body.conflictResolution).toBe('rename');
428
expect(path.basename(body.path)).toBe('report (1).txt');
429
expect(fs.readFileSync(body.path, 'utf8')).toBe('latest');
430
expect(fs.readFileSync(path.join(destinationDir, 'report.txt'), 'utf8')).toBe('existing');
412
test('renames destination when conflict strategy is rename', async () =>
413
{
414
const sourceFile = path.join(rootDir, 'report.txt');
415
const destinationDir = path.join(rootDir, 'dest');
416
fs.mkdirSync(destinationDir);
417
fs.writeFileSync(sourceFile, 'latest');
418
fs.writeFileSync(path.join(destinationDir, 'report.txt'), 'existing');
419
420
const { status, body } = await req('POST', '/api/files/move', {
421
from: sourceFile,
422
toDir: destinationDir,
423
conflict: 'rename',
431
424
});
432
425
433
test('moves a file into My Folder when rename falls back across filesystems', async () =>
426
expect(status).toBe(200);
427
expect(body.conflictResolution).toBe('rename');
428
expect(path.basename(body.path)).toBe('report (1).txt');
429
expect(fs.readFileSync(body.path, 'utf8')).toBe('latest');
430
expect(fs.readFileSync(path.join(destinationDir, 'report.txt'), 'utf8')).toBe('existing');
431
});
432
433
test('moves a file into My Folder when rename falls back across filesystems', async () =>
434
{
435
const sourceFile = path.join(rootDir, 'cross-root.txt');
436
const userFolderBase = fs.mkdtempSync(path.join(os.tmpdir(), 'filemanager-userfolders-'));
437
const userFolder = path.join(userFolderBase, 'alice');
438
439
mockPaths = [rootDir];
440
mockUserPath = userFolderBase;
441
mockUser = {
442
username: 'alice',
443
isAdmin: false,
444
permissions: {
445
[path.basename(rootDir)]: { read: true, write: true },
446
},
447
};
448
449
fs.writeFileSync(sourceFile, 'hello');
450
fs.mkdirSync(userFolder, { recursive: true });
451
452
const originalRenameSync = fs.renameSync;
453
fs.renameSync = (from, to) =>
434
454
{
435
const sourceFile = path.join(rootDir, 'cross-root.txt');
436
const userFolderBase = fs.mkdtempSync(path.join(os.tmpdir(), 'filemanager-userfolders-'));
437
const userFolder = path.join(userFolderBase, 'alice');
438
439
mockPaths = [rootDir];
440
mockUserPath = userFolderBase;
441
mockUser = {
442
username: 'alice',
443
isAdmin: false,
444
permissions: {
445
[path.basename(rootDir)]: { read: true, write: true },
446
},
447
};
448
449
fs.writeFileSync(sourceFile, 'hello');
450
fs.mkdirSync(userFolder, { recursive: true });
451
452
const originalRenameSync = fs.renameSync;
453
fs.renameSync = (from, to) =>
454
{
455
const err = new Error('cross-device move');
456
err.code = 'EXDEV';
457
throw err;
458
};
455
const err = new Error('cross-device move');
456
err.code = 'EXDEV';
457
throw err;
458
};
459
459
460
try
461
{
462
const { status, body } = await req('POST', '/api/files/move', { from: sourceFile, toDir: userFolder });
460
try
461
{
462
const { status, body } = await req('POST', '/api/files/move', { from: sourceFile, toDir: userFolder });
463
463
464
expect(status).toBe(200);
465
expect(body.path).toBe(path.join(userFolder, 'cross-root.txt'));
466
expect(fs.existsSync(sourceFile)).toBe(false);
467
expect(fs.readFileSync(path.join(userFolder, 'cross-root.txt'), 'utf8')).toBe('hello');
468
} finally
469
{
470
fs.renameSync = originalRenameSync;
471
fs.rmSync(userFolderBase, { recursive: true, force: true });
472
}
473
});
464
expect(status).toBe(200);
465
expect(body.path).toBe(path.join(userFolder, 'cross-root.txt'));
466
expect(fs.existsSync(sourceFile)).toBe(false);
467
expect(fs.readFileSync(path.join(userFolder, 'cross-root.txt'), 'utf8')).toBe('hello');
468
} finally
469
{
470
fs.renameSync = originalRenameSync;
471
fs.rmSync(userFolderBase, { recursive: true, force: true });
472
}
473
});
474
474
});
475
475
476
476
describe('root alias endpoints', () =>
@@ -284,7 +284,7 @@ function abortMultipartUpload (routePath, file)284
});284
});285
}285
}286
286
287
async function waitFor(predicate, timeoutMs = 500)287
async function waitFor (predicate, timeoutMs = 500)288
{288
{289
const start = Date.now();289
const start = Date.now();290
while (Date.now() - start < timeoutMs)290
while (Date.now() - start < timeoutMs)@@ -389,88 +389,88 @@ describe('POST /api/files/move', () =>389
expect(body.error).toMatch(/folder into itself/i);389
expect(body.error).toMatch(/folder into itself/i);390
});390
});391
391
392
test('overwrites an existing destination when conflict strategy is overwrite', async () =>392
test('overwrites an existing destination when conflict strategy is overwrite', async () =>393
{393
{394
const sourceFile = path.join(rootDir, 'source.txt');394
const sourceFile = path.join(rootDir, 'source.txt');395
const destinationDir = path.join(rootDir, 'dest');395
const destinationDir = path.join(rootDir, 'dest');396
fs.mkdirSync(destinationDir);396
fs.mkdirSync(destinationDir);397
fs.writeFileSync(sourceFile, 'new-content');397
fs.writeFileSync(sourceFile, 'new-content');398
fs.writeFileSync(path.join(destinationDir, 'source.txt'), 'old-content');398
fs.writeFileSync(path.join(destinationDir, 'source.txt'), 'old-content');399
400
const { status, body } = await req('POST', '/api/files/move', {401
from: sourceFile,402
toDir: destinationDir,403
conflict: 'overwrite',404
});405
399
406
expect(status).toBe(200);400
const { status, body } = await req('POST', '/api/files/move', {407
expect(body.conflictResolution).toBe('overwrite');401
from: sourceFile,408
expect(fs.existsSync(sourceFile)).toBe(false);402
toDir: destinationDir,409
expect(fs.readFileSync(path.join(destinationDir, 'source.txt'), 'utf8')).toBe('new-content');403
conflict: 'overwrite',410
});404
});411
405
412
test('renames destination when conflict strategy is rename', async () =>406
expect(status).toBe(200);413
{407
expect(body.conflictResolution).toBe('overwrite');414
const sourceFile = path.join(rootDir, 'report.txt');408
expect(fs.existsSync(sourceFile)).toBe(false);415
const destinationDir = path.join(rootDir, 'dest');409
expect(fs.readFileSync(path.join(destinationDir, 'source.txt'), 'utf8')).toBe('new-content');416
fs.mkdirSync(destinationDir);410
});417
fs.writeFileSync(sourceFile, 'latest');418
fs.writeFileSync(path.join(destinationDir, 'report.txt'), 'existing');419
420
const { status, body } = await req('POST', '/api/files/move', {421
from: sourceFile,422
toDir: destinationDir,423
conflict: 'rename',424
});425
411
426
expect(status).toBe(200);412
test('renames destination when conflict strategy is rename', async () =>427
expect(body.conflictResolution).toBe('rename');413
{428
expect(path.basename(body.path)).toBe('report (1).txt');414
const sourceFile = path.join(rootDir, 'report.txt');429
expect(fs.readFileSync(body.path, 'utf8')).toBe('latest');415
const destinationDir = path.join(rootDir, 'dest');430
expect(fs.readFileSync(path.join(destinationDir, 'report.txt'), 'utf8')).toBe('existing');416
fs.mkdirSync(destinationDir);417
fs.writeFileSync(sourceFile, 'latest');418
fs.writeFileSync(path.join(destinationDir, 'report.txt'), 'existing');419
420
const { status, body } = await req('POST', '/api/files/move', {421
from: sourceFile,422
toDir: destinationDir,423
conflict: 'rename',431
});424
});432
425
433
test('moves a file into My Folder when rename falls back across filesystems', async () =>426
expect(status).toBe(200);427
expect(body.conflictResolution).toBe('rename');428
expect(path.basename(body.path)).toBe('report (1).txt');429
expect(fs.readFileSync(body.path, 'utf8')).toBe('latest');430
expect(fs.readFileSync(path.join(destinationDir, 'report.txt'), 'utf8')).toBe('existing');431
});432
433
test('moves a file into My Folder when rename falls back across filesystems', async () =>434
{435
const sourceFile = path.join(rootDir, 'cross-root.txt');436
const userFolderBase = fs.mkdtempSync(path.join(os.tmpdir(), 'filemanager-userfolders-'));437
const userFolder = path.join(userFolderBase, 'alice');438
439
mockPaths = [rootDir];440
mockUserPath = userFolderBase;441
mockUser = {442
username: 'alice',443
isAdmin: false,444
permissions: {445
[path.basename(rootDir)]: { read: true, write: true },446
},447
};448
449
fs.writeFileSync(sourceFile, 'hello');450
fs.mkdirSync(userFolder, { recursive: true });451
452
const originalRenameSync = fs.renameSync;453
fs.renameSync = (from, to) =>434
{454
{435
const sourceFile = path.join(rootDir, 'cross-root.txt');455
const err = new Error('cross-device move');436
const userFolderBase = fs.mkdtempSync(path.join(os.tmpdir(), 'filemanager-userfolders-'));456
err.code = 'EXDEV';437
const userFolder = path.join(userFolderBase, 'alice');457
throw err;438
458
};439
mockPaths = [rootDir];440
mockUserPath = userFolderBase;441
mockUser = {442
username: 'alice',443
isAdmin: false,444
permissions: {445
[path.basename(rootDir)]: { read: true, write: true },446
},447
};448
449
fs.writeFileSync(sourceFile, 'hello');450
fs.mkdirSync(userFolder, { recursive: true });451
452
const originalRenameSync = fs.renameSync;453
fs.renameSync = (from, to) =>454
{455
const err = new Error('cross-device move');456
err.code = 'EXDEV';457
throw err;458
};459
459
460
try460
try461
{461
{462
const { status, body } = await req('POST', '/api/files/move', { from: sourceFile, toDir: userFolder });462
const { status, body } = await req('POST', '/api/files/move', { from: sourceFile, toDir: userFolder });463
463
464
expect(status).toBe(200);464
expect(status).toBe(200);465
expect(body.path).toBe(path.join(userFolder, 'cross-root.txt'));465
expect(body.path).toBe(path.join(userFolder, 'cross-root.txt'));466
expect(fs.existsSync(sourceFile)).toBe(false);466
expect(fs.existsSync(sourceFile)).toBe(false);467
expect(fs.readFileSync(path.join(userFolder, 'cross-root.txt'), 'utf8')).toBe('hello');467
expect(fs.readFileSync(path.join(userFolder, 'cross-root.txt'), 'utf8')).toBe('hello');468
} finally468
} finally469
{469
{470
fs.renameSync = originalRenameSync;470
fs.renameSync = originalRenameSync;471
fs.rmSync(userFolderBase, { recursive: true, force: true });471
fs.rmSync(userFolderBase, { recursive: true, force: true });472
}472
}473
});473
});474
});474
});475
475
476
describe('root alias endpoints', () =>476
describe('root alias endpoints', () =>@@ -503,16 +503,16 @@ describe('page load smoke test', () =>
503
503
expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
504
504
expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
505
505
506
let rootIconImage = null;
507
for (let i = 0; i < 10; i++)
508
{
509
const rootIconSvg = rootTile.querySelector('.icon svg');
510
rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
511
if (rootIconImage) break;
512
await new Promise(resolve => dom.window.setTimeout(resolve, 25));
513
}
514
// Root tiles should load folder icon thumbnails in Home view.
515
expect(rootIconImage).toBeTruthy();
506
let rootIconImage = null;
507
for (let i = 0; i < 10; i++)
508
{
509
const rootIconSvg = rootTile.querySelector('.icon svg');
510
rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
511
if (rootIconImage) break;
512
await new Promise(resolve => dom.window.setTimeout(resolve, 25));
513
}
514
// Root tiles should load folder icon thumbnails in Home view.
515
expect(rootIconImage).toBeTruthy();
516
516
517
517
rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
518
518
await new Promise(resolve => dom.window.setTimeout(resolve, 80));
@@ -503,16 +503,16 @@ describe('page load smoke test', () =>503
expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
503
expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Used');
504
expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
504
expect(dom.window.document.getElementById('sidebar-meta').textContent).toContain('Remaining');
505
505
506
let rootIconImage = null;
506
let rootIconImage = null;
507
for (let i = 0; i < 10; i++)
507
for (let i = 0; i < 10; i++)
508
{
508
{
509
const rootIconSvg = rootTile.querySelector('.icon svg');
509
const rootIconSvg = rootTile.querySelector('.icon svg');
510
rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
510
rootIconImage = rootIconSvg ? rootIconSvg.querySelector('image') : null;
511
if (rootIconImage) break;
511
if (rootIconImage) break;
512
await new Promise(resolve => dom.window.setTimeout(resolve, 25));
512
await new Promise(resolve => dom.window.setTimeout(resolve, 25));
513
}
513
}
514
// Root tiles should load folder icon thumbnails in Home view.
514
// Root tiles should load folder icon thumbnails in Home view.
515
expect(rootIconImage).toBeTruthy();
515
expect(rootIconImage).toBeTruthy();
516
516
517
rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
517
rootTile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
518
await new Promise(resolve => dom.window.setTimeout(resolve, 80));
518
await new Promise(resolve => dom.window.setTimeout(resolve, 80));