javascript-solid-server 0.0.202 → 0.0.204
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +17 -0
- package/package.json +2 -1
- package/src/mashlib/index.js +12 -6
- package/src/storage/filesystem.js +7 -0
- package/src/utils/url.js +10 -15
- package/test/filesystem-symlink.test.js +90 -0
- package/test/url.test.js +22 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(gh issue *)",
|
|
5
|
+
"Bash(sort -t: -k3 -n)",
|
|
6
|
+
"Bash(sed -n '1,30p' docs/features/overview.md)",
|
|
7
|
+
"Bash(npm run *)",
|
|
8
|
+
"Bash(git add *)",
|
|
9
|
+
"Bash(git commit -q -m 'docs: add Account Management page with API endpoints \\(#23\\) *)",
|
|
10
|
+
"Bash(git push *)",
|
|
11
|
+
"Bash(gh pr create --title 'docs: Account Management page \\(change password, backup/export, delete\\) — closes #23' --body ' *)",
|
|
12
|
+
"Bash(gh pr *)",
|
|
13
|
+
"Bash(git checkout *)",
|
|
14
|
+
"Bash(git pull *)"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "javascript-solid-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.204",
|
|
4
4
|
"description": "A minimal, fast Solid server",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"fs-extra": "^11.2.0",
|
|
37
37
|
"jose": "^6.1.3",
|
|
38
38
|
"microfed": "^0.0.14",
|
|
39
|
+
"mime-types": "^2.1.35",
|
|
39
40
|
"n3": "^1.26.0",
|
|
40
41
|
"oidc-provider": "^9.6.0",
|
|
41
42
|
"sql.js": "^1.13.0",
|
package/src/mashlib/index.js
CHANGED
|
@@ -356,8 +356,12 @@ export function shouldServeMashlib(request, mashlibEnabled, contentType) {
|
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
-
//
|
|
360
|
-
|
|
359
|
+
// Serve the mashlib shell only for content types that have a pane to
|
|
360
|
+
// render them. RDF + markdown + playlists, plus any single audio type
|
|
361
|
+
// (the audio pane). Do NOT add video/image types here until panes exist
|
|
362
|
+
// for them — wrapping them would show "No data found" instead of the
|
|
363
|
+
// browser's native inline render. See #533.
|
|
364
|
+
const viewableTypes = [
|
|
361
365
|
'text/turtle',
|
|
362
366
|
'application/ld+json',
|
|
363
367
|
'application/json',
|
|
@@ -365,13 +369,15 @@ export function shouldServeMashlib(request, mashlibEnabled, contentType) {
|
|
|
365
369
|
'application/n-triples',
|
|
366
370
|
'application/rdf+xml',
|
|
367
371
|
'text/markdown',
|
|
368
|
-
'
|
|
369
|
-
'application/vnd.apple.mpegurl',
|
|
370
|
-
'audio/x-scpls'
|
|
372
|
+
'application/vnd.apple.mpegurl'
|
|
371
373
|
];
|
|
372
374
|
|
|
373
375
|
const baseType = contentType.split(';')[0].trim().toLowerCase();
|
|
374
|
-
|
|
376
|
+
// Any audio/* type (mpeg, ogg, wave, x-flac, mpegurl playlists, ...) has a
|
|
377
|
+
// pane (audio or playlist), so match the whole family rather than enumerate
|
|
378
|
+
// the exact spellings the mime-types db happens to use.
|
|
379
|
+
if (baseType.startsWith('audio/')) return true;
|
|
380
|
+
return viewableTypes.includes(baseType);
|
|
375
381
|
}
|
|
376
382
|
|
|
377
383
|
/**
|
|
@@ -181,6 +181,13 @@ export async function listContainer(urlPath) {
|
|
|
181
181
|
};
|
|
182
182
|
try {
|
|
183
183
|
const stat = await fs.stat(path.join(filePath, entry.name));
|
|
184
|
+
// Dirent.isDirectory() uses lstat semantics, so it is false for
|
|
185
|
+
// *any* symlink — even one targeting a directory. Reclassify from
|
|
186
|
+
// the dereferenced stat so symlinked directories list as containers
|
|
187
|
+
// (trailing slash + ldp:BasicContainer), matching how they behave
|
|
188
|
+
// on a direct GET. A dangling symlink throws here and keeps the
|
|
189
|
+
// lstat-based isDirectory: false. (#531)
|
|
190
|
+
if (entry.isSymbolicLink()) result.isDirectory = stat.isDirectory();
|
|
184
191
|
result.size = stat.size;
|
|
185
192
|
result.modified = stat.mtime.toISOString();
|
|
186
193
|
} catch { /* stat failed, skip metadata */ }
|
package/src/utils/url.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import * as mime from 'mime-types';
|
|
2
3
|
|
|
3
4
|
// Base directory for storing all pods
|
|
4
5
|
// Use a getter function to read env var at runtime (not import time)
|
|
@@ -218,28 +219,19 @@ function getPodNameFromPath(urlPath) {
|
|
|
218
219
|
*/
|
|
219
220
|
export function getContentType(filePath) {
|
|
220
221
|
const ext = path.extname(filePath).toLowerCase();
|
|
221
|
-
|
|
222
|
+
|
|
223
|
+
// Solid-specific overrides — types the `mime-types` db doesn't know, or
|
|
224
|
+
// where Solid semantics differ. Checked before falling back to mime-types
|
|
225
|
+
// (which covers the long tail: audio/video/fonts/archives/office/etc.).
|
|
226
|
+
const overrides = {
|
|
222
227
|
'.jsonld': 'application/ld+json',
|
|
223
|
-
'.json': 'application/json',
|
|
224
|
-
'.html': 'text/html',
|
|
225
|
-
'.txt': 'text/plain',
|
|
226
|
-
'.css': 'text/css',
|
|
227
|
-
'.js': 'application/javascript',
|
|
228
|
-
'.png': 'image/png',
|
|
229
|
-
'.jpg': 'image/jpeg',
|
|
230
|
-
'.jpeg': 'image/jpeg',
|
|
231
|
-
'.gif': 'image/gif',
|
|
232
|
-
'.svg': 'image/svg+xml',
|
|
233
|
-
'.pdf': 'application/pdf',
|
|
234
228
|
'.ttl': 'text/turtle',
|
|
235
229
|
'.n3': 'text/n3',
|
|
236
230
|
'.nt': 'application/n-triples',
|
|
237
231
|
'.rdf': 'application/rdf+xml',
|
|
238
232
|
'.nq': 'application/n-quads',
|
|
239
233
|
'.trig': 'application/trig',
|
|
240
|
-
'.md': 'text/markdown',
|
|
241
234
|
'.m3u': 'audio/mpegurl',
|
|
242
|
-
'.m3u8': 'application/vnd.apple.mpegurl',
|
|
243
235
|
'.pls': 'audio/x-scpls',
|
|
244
236
|
// Solid ACL/meta as extensions (e.g. publicTypeIndex.jsonld.acl)
|
|
245
237
|
'.acl': 'application/ld+json',
|
|
@@ -255,7 +247,10 @@ export function getContentType(filePath) {
|
|
|
255
247
|
const base = path.basename(filePath);
|
|
256
248
|
if (base === '.acl' || base === '.meta') return 'application/ld+json';
|
|
257
249
|
|
|
258
|
-
|
|
250
|
+
// Overrides first, then the comprehensive mime-types database (as CSS and
|
|
251
|
+
// NSS do), then octet-stream. This is what makes audio/video/etc. resolve
|
|
252
|
+
// to a real type instead of forcing a download. See #533.
|
|
253
|
+
return overrides[ext] || mime.lookup(filePath) || 'application/octet-stream';
|
|
259
254
|
}
|
|
260
255
|
|
|
261
256
|
/**
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for #531 — listContainer misclassified symlinked
|
|
3
|
+
* directories as plain resources.
|
|
4
|
+
*
|
|
5
|
+
* `fs.readdir(dir, { withFileTypes: true })` returns Dirents with lstat
|
|
6
|
+
* semantics, so `Dirent.isDirectory()` is false for ANY symlink — even one
|
|
7
|
+
* pointing at a directory. listContainer relied on that flag, so a symlinked
|
|
8
|
+
* sub-directory was listed without a trailing slash and typed ldp:Resource
|
|
9
|
+
* instead of ldp:BasicContainer, making it unbrowsable in container listings
|
|
10
|
+
* (while a direct GET, which dereferences, worked fine).
|
|
11
|
+
*
|
|
12
|
+
* The fix reclassifies symlink entries from the dereferenced fs.stat() that
|
|
13
|
+
* listContainer already performs for size/mtime.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, before, after } from 'node:test';
|
|
17
|
+
import assert from 'node:assert';
|
|
18
|
+
import fs from 'fs-extra';
|
|
19
|
+
import os from 'os';
|
|
20
|
+
import path from 'path';
|
|
21
|
+
import { listContainer } from '../src/storage/filesystem.js';
|
|
22
|
+
|
|
23
|
+
let TEST_ROOT;
|
|
24
|
+
let originalDataRoot;
|
|
25
|
+
|
|
26
|
+
describe('listContainer — symlink classification (#531)', () => {
|
|
27
|
+
before(async () => {
|
|
28
|
+
originalDataRoot = process.env.DATA_ROOT;
|
|
29
|
+
TEST_ROOT = await fs.mkdtemp(path.join(os.tmpdir(), 'jss-symlink-'));
|
|
30
|
+
process.env.DATA_ROOT = TEST_ROOT;
|
|
31
|
+
|
|
32
|
+
// The container being listed.
|
|
33
|
+
const box = path.join(TEST_ROOT, 'box');
|
|
34
|
+
await fs.ensureDir(box);
|
|
35
|
+
|
|
36
|
+
// Real entries.
|
|
37
|
+
await fs.ensureDir(path.join(box, 'realdir'));
|
|
38
|
+
await fs.writeFile(path.join(box, 'realfile.txt'), 'hi');
|
|
39
|
+
|
|
40
|
+
// Symlink targets live outside the container (and outside DATA_ROOT) to
|
|
41
|
+
// mirror the real-world case of linking external content into a pod.
|
|
42
|
+
const targetDir = path.join(TEST_ROOT, 'external-dir');
|
|
43
|
+
const targetFile = path.join(TEST_ROOT, 'external-file.txt');
|
|
44
|
+
await fs.ensureDir(targetDir);
|
|
45
|
+
await fs.writeFile(targetFile, 'external');
|
|
46
|
+
|
|
47
|
+
await fs.symlink(targetDir, path.join(box, 'linkdir'));
|
|
48
|
+
await fs.symlink(targetFile, path.join(box, 'linkfile.txt'));
|
|
49
|
+
// Dangling symlink — target does not exist.
|
|
50
|
+
await fs.symlink(path.join(TEST_ROOT, 'nope'), path.join(box, 'broken'));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
after(async () => {
|
|
54
|
+
if (originalDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
55
|
+
else process.env.DATA_ROOT = originalDataRoot;
|
|
56
|
+
await fs.remove(TEST_ROOT);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('classifies a symlink-to-directory as a directory', async () => {
|
|
60
|
+
const entries = await listContainer('box');
|
|
61
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
62
|
+
|
|
63
|
+
assert.strictEqual(byName.linkdir.isDirectory, true,
|
|
64
|
+
'symlinked directory should be listed as a container');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('keeps a symlink-to-file as a non-directory', async () => {
|
|
68
|
+
const entries = await listContainer('box');
|
|
69
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
70
|
+
|
|
71
|
+
assert.strictEqual(byName['linkfile.txt'].isDirectory, false,
|
|
72
|
+
'symlinked file should remain a resource');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('does not regress real directories and files', async () => {
|
|
76
|
+
const entries = await listContainer('box');
|
|
77
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
78
|
+
|
|
79
|
+
assert.strictEqual(byName.realdir.isDirectory, true);
|
|
80
|
+
assert.strictEqual(byName['realfile.txt'].isDirectory, false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('treats a dangling symlink as a non-directory (stat throws)', async () => {
|
|
84
|
+
const entries = await listContainer('box');
|
|
85
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
86
|
+
|
|
87
|
+
assert.strictEqual(byName.broken.isDirectory, false,
|
|
88
|
+
'a dangling symlink keeps the lstat-based isDirectory: false');
|
|
89
|
+
});
|
|
90
|
+
});
|
package/test/url.test.js
CHANGED
|
@@ -94,7 +94,28 @@ describe('getContentType', () => {
|
|
|
94
94
|
assert.strictEqual(getContentType('/x/card.ttl'), 'text/turtle');
|
|
95
95
|
});
|
|
96
96
|
it('falls back to application/octet-stream for unknown extensions', () => {
|
|
97
|
-
|
|
97
|
+
// .zzz is not in the mime-types db (unlike .xyz → chemical/x-xyz)
|
|
98
|
+
assert.strictEqual(getContentType('/x/file.zzz'), 'application/octet-stream');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('media types via mime-types db (#533)', () => {
|
|
103
|
+
it('maps .mp3 → audio/mpeg (was octet-stream → forced download)', () => {
|
|
104
|
+
assert.strictEqual(getContentType('/music/song.mp3'), 'audio/mpeg');
|
|
105
|
+
});
|
|
106
|
+
it('maps common audio extensions to audio/*', () => {
|
|
107
|
+
for (const f of ['a.ogg', 'a.wav', 'a.m4a', 'a.flac', 'a.opus', 'a.aac']) {
|
|
108
|
+
assert.ok(getContentType(f).startsWith('audio/'), f + ' should be audio/*, got ' + getContentType(f));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
it('maps video and other common types', () => {
|
|
112
|
+
assert.strictEqual(getContentType('v.mp4'), 'video/mp4');
|
|
113
|
+
assert.strictEqual(getContentType('d.pdf'), 'application/pdf');
|
|
114
|
+
});
|
|
115
|
+
it('keeps Solid overrides ahead of the mime-types db', () => {
|
|
116
|
+
assert.strictEqual(getContentType('card.ttl'), 'text/turtle');
|
|
117
|
+
assert.strictEqual(getContentType('x.jsonld'), 'application/ld+json');
|
|
118
|
+
assert.strictEqual(getContentType('p.m3u'), 'audio/mpegurl');
|
|
98
119
|
});
|
|
99
120
|
});
|
|
100
121
|
|