@zmskco/dsh-notebook 0.1.0 → 0.3.0
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/LICENSE +23 -23
- package/README.md +29 -75
- package/assets/material-icons/LICENSE.txt +8 -0
- package/assets/material-icons/NOTICE.md +13 -0
- package/cordis.patch.yml +4 -2
- package/icon.png +0 -0
- package/lib/client.js +6803 -261
- package/lib/http/api.js +69 -14
- package/lib/index.js +19 -8
- package/lib/story/bootstrap.js +4 -9
- package/lib/story/manuscript.js +137 -14
- package/lib/story/project.js +263 -30
- package/lib/story/readme.js +9 -9
- package/lib/story/root.js +12 -9
- package/lib/story/sandbox.js +33 -106
- package/lib/story/workspace.js +1 -15
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +94 -89
- package/icon.svg +0 -9
- package/lib/config.js +0 -43
- package/lib/http/media.js +0 -187
- package/lib/render/backend.js +0 -247
- package/lib/render/jobs.js +0 -267
- package/lib/render/png.js +0 -125
- package/lib/tools.js +0 -341
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "Notebook",
|
|
4
|
-
"description": "A markdown notebook for the workspace: file tree, WYSIWYG editing, autosave and an embedded AI chat."
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Notebook",
|
|
4
|
+
"description": "A markdown notebook for the workspace: file tree, WYSIWYG editing, autosave and an embedded AI chat."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "笔记本",
|
|
4
|
-
"description": "工作区里的 markdown 笔记本:目录树、所见即所得编辑、自动保存与内嵌 AI 对话。"
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "笔记本",
|
|
4
|
+
"description": "工作区里的 markdown 笔记本:目录树、所见即所得编辑、自动保存与内嵌 AI 对话。"
|
|
5
|
+
}
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,89 +1,94 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zmskco/dsh-notebook",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "笔记本 (Notebook) — a markdown notebook for the DeepSeek Harness workspace: file tree, WYSIWYG editor, autosave and an embedded AI chat.",
|
|
5
|
-
"icon": "./icon.
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/zmskco/dsh-notebook.git"
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://github.com/zmskco/dsh-notebook#readme",
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/zmskco/dsh-notebook/issues"
|
|
13
|
-
},
|
|
14
|
-
"type": "module",
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"main": "lib/index.js",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": "./lib/index.js",
|
|
19
|
-
"./client": "./lib/client.js",
|
|
20
|
-
"./locale/*.json": "./locale/*.json",
|
|
21
|
-
"./icon
|
|
22
|
-
"./
|
|
23
|
-
"./
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"lib/
|
|
28
|
-
"lib
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"prosemirror-
|
|
80
|
-
"prosemirror-
|
|
81
|
-
"prosemirror-
|
|
82
|
-
"prosemirror-
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@zmskco/dsh-notebook",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "笔记本 (Notebook) — a markdown notebook for the DeepSeek Harness workspace: file tree, WYSIWYG editor, autosave and an embedded AI chat.",
|
|
5
|
+
"icon": "./icon.png",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/zmskco/dsh-notebook.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/zmskco/dsh-notebook#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/zmskco/dsh-notebook/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"main": "lib/index.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./lib/index.js",
|
|
19
|
+
"./client": "./lib/client.js",
|
|
20
|
+
"./locale/*.json": "./locale/*.json",
|
|
21
|
+
"./icon": "./icon.png",
|
|
22
|
+
"./icon.png": "./icon.png",
|
|
23
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"lib/index.js",
|
|
28
|
+
"lib/client.js",
|
|
29
|
+
"lib/**/*.js",
|
|
30
|
+
"cordis.patch.yml",
|
|
31
|
+
"locale/*.json",
|
|
32
|
+
"icon.png",
|
|
33
|
+
"assets/material-icons/LICENSE.txt",
|
|
34
|
+
"assets/material-icons/NOTICE.md",
|
|
35
|
+
"LICENSE",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"keywords": [
|
|
39
|
+
"dsh",
|
|
40
|
+
"deepseek-harness",
|
|
41
|
+
"cordis",
|
|
42
|
+
"bundle",
|
|
43
|
+
"notebook",
|
|
44
|
+
"markdown",
|
|
45
|
+
"editor"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=20",
|
|
49
|
+
"dsh": "^0.2.2-alpha.2"
|
|
50
|
+
},
|
|
51
|
+
"dsh": {
|
|
52
|
+
"bundle": {
|
|
53
|
+
"patch": "./cordis.patch.yml"
|
|
54
|
+
},
|
|
55
|
+
"client": {
|
|
56
|
+
"platform": "web",
|
|
57
|
+
"immediately": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "npm run build:host && npm run build:client && npm run check:client",
|
|
62
|
+
"build:host": "tsc -p tsconfig.host.json",
|
|
63
|
+
"build:client": "tsdown",
|
|
64
|
+
"check:client": "node scripts/check-client.mjs",
|
|
65
|
+
"check:sandbox": "node scripts/check-sandbox.mjs",
|
|
66
|
+
"smoke": "node scripts/smoke-host.mjs",
|
|
67
|
+
"test": "npm run typecheck && npm run check:sandbox && npm run smoke",
|
|
68
|
+
"vendor:icons": "node scripts/vendor-material-icons.mjs",
|
|
69
|
+
"watch:client": "tsdown --watch",
|
|
70
|
+
"watch:host": "tsc -p tsconfig.host.json --watch --preserveWatchOutput",
|
|
71
|
+
"typecheck": "tsc -p tsconfig.host.json --noEmit && tsc -p tsconfig.json",
|
|
72
|
+
"prepare": "pnpm run build",
|
|
73
|
+
"prepublishOnly": "npm run build && npm test",
|
|
74
|
+
"pack:check": "npm pack --dry-run"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@types/node": "^22.10.0",
|
|
78
|
+
"@types/react": "^18.3.0",
|
|
79
|
+
"prosemirror-commands": "^1.7.2",
|
|
80
|
+
"prosemirror-history": "^1.5.1",
|
|
81
|
+
"prosemirror-inputrules": "^1.5.1",
|
|
82
|
+
"prosemirror-keymap": "^1.2.3",
|
|
83
|
+
"prosemirror-model": "^1.25.12",
|
|
84
|
+
"prosemirror-schema-basic": "^1.2.5",
|
|
85
|
+
"prosemirror-schema-list": "^1.5.1",
|
|
86
|
+
"prosemirror-state": "^1.4.4",
|
|
87
|
+
"prosemirror-view": "^1.42.8",
|
|
88
|
+
"tsdown": "^0.22.2",
|
|
89
|
+
"typescript": "^5.7.0"
|
|
90
|
+
},
|
|
91
|
+
"publishConfig": {
|
|
92
|
+
"access": "public"
|
|
93
|
+
}
|
|
94
|
+
}
|
package/icon.svg
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none"
|
|
2
|
-
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
3
|
-
<path d="M2 6h4" />
|
|
4
|
-
<path d="M2 10h4" />
|
|
5
|
-
<path d="M2 14h4" />
|
|
6
|
-
<path d="M2 18h4" />
|
|
7
|
-
<rect width="16" height="20" x="4" y="2" rx="2" />
|
|
8
|
-
<path d="M16 2v20" />
|
|
9
|
-
</svg>
|
package/lib/config.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin configuration: validation and defaults.
|
|
3
|
-
*
|
|
4
|
-
* The plugin exports no `Config` schema, because the schema DSL lives in a DSH
|
|
5
|
-
* package this out-of-checkout bundle does not depend on. Configuration that a
|
|
6
|
-
* profile patch supplies therefore arrives unvalidated, and this module is the
|
|
7
|
-
* replacement: every field is checked once at activation and either accepted or
|
|
8
|
-
* replaced with a default, with a warning naming the field.
|
|
9
|
-
*/
|
|
10
|
-
import { isAbsolute, join, resolve } from 'node:path';
|
|
11
|
-
function optionalString(value) {
|
|
12
|
-
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Resolve the effective configuration.
|
|
16
|
-
* @param raw - the row's `config`, or `undefined` when the row declared none.
|
|
17
|
-
* @param fallbackRoot - default root, already derived from the sandbox boundary.
|
|
18
|
-
* @param warn - sink for rejected fields; the caller supplies the plugin logger.
|
|
19
|
-
* @param workspaceRoot - the sandbox's `workspace-write` boundary, when known.
|
|
20
|
-
* A **relative** `rootDir` resolves against it, so `rootDir: notes` lands
|
|
21
|
-
* inside the one directory the sandbox is guaranteed to permit. Without a
|
|
22
|
-
* boundary a relative path falls back to resolving against `process.cwd()`.
|
|
23
|
-
* @returns the validated configuration.
|
|
24
|
-
*/
|
|
25
|
-
export function resolveConfig(raw, fallbackRoot, warn, workspaceRoot) {
|
|
26
|
-
const input = typeof raw === 'object' && raw !== null ? raw : {};
|
|
27
|
-
const configured = optionalString(input.rootDir);
|
|
28
|
-
let rootDir = fallbackRoot;
|
|
29
|
-
let rootDirOverride = false;
|
|
30
|
-
if (configured !== null) {
|
|
31
|
-
rootDirOverride = true;
|
|
32
|
-
if (isAbsolute(configured))
|
|
33
|
-
rootDir = configured;
|
|
34
|
-
else if (workspaceRoot !== undefined && workspaceRoot.length > 0)
|
|
35
|
-
rootDir = join(workspaceRoot, configured);
|
|
36
|
-
else
|
|
37
|
-
rootDir = resolve(configured);
|
|
38
|
-
}
|
|
39
|
-
else if (input.rootDir !== undefined) {
|
|
40
|
-
warn(`rootDir must be a non-empty string; received ${JSON.stringify(input.rootDir)}, using the workspace`);
|
|
41
|
-
}
|
|
42
|
-
return { rootDir, rootDirOverride };
|
|
43
|
-
}
|
package/lib/http/media.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { NotebookError, asNotebookError } from '../errors.js';
|
|
2
|
-
import { assertRelativePath, assertStoryName } from '../story/paths.js';
|
|
3
|
-
import { statusFor } from './status.js';
|
|
4
|
-
/** Mount point of this plugin's media route. */
|
|
5
|
-
export const MEDIA_PREFIX = '/notebook/media';
|
|
6
|
-
/** Byte ranges above this size are streamed in chunks instead of buffered. */
|
|
7
|
-
const STREAM_THRESHOLD = 4 * 1024 * 1024;
|
|
8
|
-
const CHUNK_SIZE = 1024 * 1024;
|
|
9
|
-
/** Hard cap for one un-ranged response; larger files must be ranged. */
|
|
10
|
-
const MAX_BUFFERED = 64 * 1024 * 1024;
|
|
11
|
-
const CONTENT_TYPES = {
|
|
12
|
-
'.png': 'image/png',
|
|
13
|
-
'.jpg': 'image/jpeg',
|
|
14
|
-
'.jpeg': 'image/jpeg',
|
|
15
|
-
'.webp': 'image/webp',
|
|
16
|
-
'.gif': 'image/gif',
|
|
17
|
-
'.mp4': 'video/mp4',
|
|
18
|
-
'.webm': 'video/webm',
|
|
19
|
-
'.json': 'application/json; charset=utf-8',
|
|
20
|
-
'.md': 'text/markdown; charset=utf-8',
|
|
21
|
-
'.txt': 'text/plain; charset=utf-8',
|
|
22
|
-
};
|
|
23
|
-
function contentTypeFor(path) {
|
|
24
|
-
const dot = path.lastIndexOf('.');
|
|
25
|
-
const extension = dot < 0 ? '' : path.slice(dot).toLowerCase();
|
|
26
|
-
return CONTENT_TYPES[extension] ?? 'application/octet-stream';
|
|
27
|
-
}
|
|
28
|
-
function sendJson(res, status, body) {
|
|
29
|
-
const text = JSON.stringify(body);
|
|
30
|
-
res.statusCode = status;
|
|
31
|
-
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
32
|
-
res.setHeader('content-length', Buffer.byteLength(text));
|
|
33
|
-
res.end(text);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Parse a single-range `Range` header.
|
|
37
|
-
* @param header - the raw header value.
|
|
38
|
-
* @param size - the resource size.
|
|
39
|
-
* @returns the range, or `null` when the header is unsatisfiable.
|
|
40
|
-
*/
|
|
41
|
-
function parseRange(header, size) {
|
|
42
|
-
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
43
|
-
if (match === null)
|
|
44
|
-
return null;
|
|
45
|
-
const rawStart = match[1] ?? '';
|
|
46
|
-
const rawEnd = match[2] ?? '';
|
|
47
|
-
if (rawStart.length === 0 && rawEnd.length === 0)
|
|
48
|
-
return null;
|
|
49
|
-
if (rawStart.length === 0) {
|
|
50
|
-
// Suffix form: the last N bytes.
|
|
51
|
-
const length = Number(rawEnd);
|
|
52
|
-
if (!Number.isFinite(length) || length <= 0 || size === 0)
|
|
53
|
-
return null;
|
|
54
|
-
return { start: Math.max(0, size - length), end: size - 1 };
|
|
55
|
-
}
|
|
56
|
-
const start = Number(rawStart);
|
|
57
|
-
if (!Number.isFinite(start) || start >= size)
|
|
58
|
-
return null;
|
|
59
|
-
const end = rawEnd.length === 0 ? size - 1 : Math.min(Number(rawEnd), size - 1);
|
|
60
|
-
if (!Number.isFinite(end) || end < start)
|
|
61
|
-
return null;
|
|
62
|
-
return { start, end };
|
|
63
|
-
}
|
|
64
|
-
/** Write one buffer, waiting for drain when the socket is saturated. */
|
|
65
|
-
async function writeChunk(res, chunk) {
|
|
66
|
-
if (res.write(chunk))
|
|
67
|
-
return;
|
|
68
|
-
await new Promise((resolve, reject) => {
|
|
69
|
-
const cleanup = () => {
|
|
70
|
-
res.off('drain', onDrain);
|
|
71
|
-
res.off('close', onClose);
|
|
72
|
-
};
|
|
73
|
-
function onDrain() { cleanup(); resolve(); }
|
|
74
|
-
function onClose() { cleanup(); reject(new NotebookError('internal', 'client closed the connection')); }
|
|
75
|
-
res.on('drain', onDrain);
|
|
76
|
-
res.on('close', onClose);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Register the media route on the HTTP carrier.
|
|
81
|
-
* @param deps - carrier, filesystem, trust fence, store and logger.
|
|
82
|
-
* @returns the route disposer.
|
|
83
|
-
*/
|
|
84
|
-
export function registerMediaRoute(deps) {
|
|
85
|
-
const { webServer, fs, connection, roots, log } = deps;
|
|
86
|
-
const handle = async (req, res) => {
|
|
87
|
-
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
88
|
-
res.setHeader('allow', 'GET, HEAD');
|
|
89
|
-
res.statusCode = 405;
|
|
90
|
-
res.end();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const url = new URL(String(req.url), 'http://localhost');
|
|
94
|
-
const pathname = url.pathname;
|
|
95
|
-
const rest = decodeURIComponent(pathname.slice(MEDIA_PREFIX.length).replace(/^\//, ''));
|
|
96
|
-
const segments = rest.split('/');
|
|
97
|
-
const rawProject = segments[0];
|
|
98
|
-
const rawFile = segments.slice(1);
|
|
99
|
-
if (rawProject === undefined || rawFile.length === 0) {
|
|
100
|
-
sendJson(res, 400, { code: 'bad-request', message: `expected ${MEDIA_PREFIX}/<project>/<path>` });
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const projectId = assertStoryName(rawProject);
|
|
104
|
-
const rel = assertRelativePath(rawFile.join('/'));
|
|
105
|
-
// The image URL carries the Session whose workspace holds this project, for
|
|
106
|
-
// the same reason every other route does: the story root is per workspace.
|
|
107
|
-
const { store } = roots(url.searchParams.get('session') ?? undefined);
|
|
108
|
-
const project = await store.open(projectId);
|
|
109
|
-
const target = await store.resolveInside(project, rel);
|
|
110
|
-
const info = await fs.stat(target);
|
|
111
|
-
if (info === undefined || info.type !== 'file') {
|
|
112
|
-
sendJson(res, 404, { code: 'not-found', message: `${rel} does not exist in project ${projectId}` });
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const size = info.size ?? 0;
|
|
116
|
-
res.setHeader('content-type', contentTypeFor(rel));
|
|
117
|
-
res.setHeader('accept-ranges', 'bytes');
|
|
118
|
-
res.setHeader('cache-control', 'no-cache');
|
|
119
|
-
res.setHeader('etag', `"${info.version}"`);
|
|
120
|
-
if (req.headers['if-none-match'] === `"${info.version}"`) {
|
|
121
|
-
res.statusCode = 304;
|
|
122
|
-
res.end();
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const rangeHeader = req.headers.range;
|
|
126
|
-
const hasRange = typeof rangeHeader === 'string' && rangeHeader.length > 0;
|
|
127
|
-
const range = hasRange ? parseRange(rangeHeader, size) : null;
|
|
128
|
-
if (hasRange && range === null) {
|
|
129
|
-
res.statusCode = 416;
|
|
130
|
-
res.setHeader('content-range', `bytes */${String(size)}`);
|
|
131
|
-
res.end();
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const start = range?.start ?? 0;
|
|
135
|
-
const end = range?.end ?? size - 1;
|
|
136
|
-
const length = Math.max(0, end - start + 1);
|
|
137
|
-
if (range !== null) {
|
|
138
|
-
res.statusCode = 206;
|
|
139
|
-
res.setHeader('content-range', `bytes ${String(start)}-${String(end)}/${String(size)}`);
|
|
140
|
-
}
|
|
141
|
-
else if (length > MAX_BUFFERED) {
|
|
142
|
-
// Refuse rather than exhaust memory; a well-behaved client ranges.
|
|
143
|
-
sendJson(res, 413, { code: 'bad-request', message: `${rel} is ${String(size)} bytes; request a byte range` });
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
res.statusCode = 200;
|
|
148
|
-
}
|
|
149
|
-
res.setHeader('content-length', String(length));
|
|
150
|
-
if (req.method === 'HEAD' || length === 0) {
|
|
151
|
-
res.end();
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (length <= STREAM_THRESHOLD) {
|
|
155
|
-
res.end(Buffer.from(await fs.readByteRange(target, { offset: start, length })));
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
for (let offset = start; offset <= end; offset += CHUNK_SIZE) {
|
|
159
|
-
const take = Math.min(CHUNK_SIZE, end - offset + 1);
|
|
160
|
-
await writeChunk(res, await fs.readByteRange(target, { offset, length: take }));
|
|
161
|
-
}
|
|
162
|
-
res.end();
|
|
163
|
-
};
|
|
164
|
-
return webServer.register({
|
|
165
|
-
kind: 'prefix',
|
|
166
|
-
path: MEDIA_PREFIX,
|
|
167
|
-
handler: (req, res) => {
|
|
168
|
-
const rejection = connection.requestRejection({ headers: req.headers });
|
|
169
|
-
if (rejection !== undefined) {
|
|
170
|
-
res.statusCode = rejection;
|
|
171
|
-
res.end();
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
void handle(req, res).catch((error) => {
|
|
175
|
-
const failure = asNotebookError(error);
|
|
176
|
-
log.warn('notebook: media request failed', failure);
|
|
177
|
-
if (res.headersSent)
|
|
178
|
-
res.end();
|
|
179
|
-
else
|
|
180
|
-
sendJson(res, statusFor(failure.code), {
|
|
181
|
-
code: failure.code,
|
|
182
|
-
message: failure.message,
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
}
|