pithos/hosted/test/public-page.test.js
Local Dev 7fa7f71be4 pithos-hosted: public folders by name, as pages, at navigate.st/s3
Public files were addressed by a 32-character account id, and a public
folder answered with JSON, so a link was unusable to send to anyone.
Accounts that signed up with a BNS name can now be addressed by it
(/p/alice.x/<drive>/<folder>/), a public folder opened in a browser is a
page with its files, small pictures and a player (tools still get JSON),
and every link and redirect on it is relative so navigate.st/s3/ serves
the same pages. Pithos shows the navigate.st/s3 address when a folder is
made public.
2026-10-04 16:10:11 +02:00

28 lines
1.5 KiB
JavaScript

// Public folder pages are served at /p/<who>/<drive>/<path>/ and also as
// navigate.st/s3/…, so every link in them must be relative to the folder.
import test from 'node:test';
import assert from 'node:assert/strict';
import { folderPage } from '../server.js';
test('folder page links are relative, names escaped, media playable', () => {
const html = folderPage({
owner: 'alice.x', bucket: 'music-house', key: 'Deep/Night/',
listing: { folders: ['Remixes/'], files: [{ name: 'A <i>song & co.mp3', size: 9_437_184 }, { name: 'cover.jpg', size: 2048 }, { name: 'notes.txt', size: 12 }], next: null },
});
assert.match(html, /<a href="Remixes\/">/);
assert.match(html, /href="A%20%3Ci%3Esong%20%26%20co\.mp3"/);
assert.match(html, /A &lt;i&gt;song &amp; co\.mp3/);
assert.doesNotMatch(html, /<i>song/);
assert.match(html, /data-kind="audio"/);
assert.match(html, /<img loading="lazy" src="cover\.jpg"/);
// Breadcrumbs climb with ../ only: drive root is two levels up.
assert.match(html, /<a href="\.\.\/\.\.\/">music-house<\/a> \/ <a href="\.\.\/">Deep<\/a> \/ <span>Night<\/span>/);
assert.doesNotMatch(html, /href="\/p\//);
});
test('drive root page has no stray parents', () => {
const html = folderPage({ owner: '0123', bucket: 'd', key: '', listing: { folders: [], files: [], next: 'tok/en' } });
assert.match(html, /This folder is empty/);
assert.match(html, /href="\?token=tok%2Fen"/);
assert.match(html, /<a href="\.\/">d<\/a>/);
});