@fish-under-sea/dsh-client-ui-task-board-fish 1.0.2 → 1.1.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/NOTICE +1 -1
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +4428 -1508
- package/lib/client.js.map +1 -1
- package/lib/index.js +2670 -496
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +130 -19
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +63 -0
- package/lib/types/client/board/AttachmentField.d.ts +70 -0
- package/lib/types/client/board/ExecutionLog.d.ts +24 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/TaskForm.d.ts +4 -0
- package/lib/types/client/board/VerificationReport.d.ts +2 -15
- package/lib/types/client/board/model-options.d.ts +87 -0
- package/lib/types/client/board/preset-label.d.ts +21 -0
- package/lib/types/client/board/preset-roster.d.ts +45 -0
- package/lib/types/client/board/source-group.d.ts +27 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/host-api.d.ts +25 -0
- package/lib/types/client/locales.d.ts +87 -9
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/plugin-card-seat.d.ts +3 -1
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/client/settings-form.d.ts +73 -51
- package/lib/types/core/attachment.d.ts +132 -0
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +57 -8
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +116 -0
- package/lib/types/core/launch-width.d.ts +31 -0
- package/lib/types/core/reasoning-effort.d.ts +57 -0
- package/lib/types/core/session-reuse.d.ts +7 -1
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +100 -37
- package/lib/types/core/tasks.d.ts +94 -10
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-tag.d.ts +36 -0
- package/lib/types/core/use-cases/task-update.d.ts +22 -1
- package/lib/types/core/wire-projection.d.ts +35 -0
- package/lib/types/core/workspace-target.d.ts +23 -3
- package/lib/types/host/attachments.d.ts +250 -0
- package/lib/types/host/extension-registry.d.ts +40 -0
- package/lib/types/host/launch-admission.d.ts +71 -0
- package/lib/types/host-ledger.d.ts +114 -47
- package/lib/types/host-routes.d.ts +63 -0
- package/lib/types/host-runner.d.ts +164 -18
- package/lib/types/host-service.d.ts +182 -46
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +173 -54
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +52 -11
- package/lib/types/tool-surface.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +35 -28
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +385 -111
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/TaskBoardSettingsCard.tsx +332 -37
- package/src/client/board/AttachmentField.tsx +383 -0
- package/src/client/board/EditTaskModal.tsx +63 -0
- package/src/client/board/ExecutionLog.tsx +154 -0
- package/src/client/board/LinkSubtaskModal.tsx +1 -1
- package/src/client/board/NewTaskModal.tsx +154 -45
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TagManagerModal.tsx +151 -2
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/TaskCard.tsx +45 -23
- package/src/client/board/TaskDetail.tsx +468 -258
- package/src/client/board/TaskForm.tsx +19 -4
- package/src/client/board/VerificationReport.tsx +143 -104
- package/src/client/board/model-options.ts +208 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board/task-markdown.module.css +11 -8
- package/src/client/board-settings.module.css +35 -7
- package/src/client/board.module.css +1044 -105
- package/src/client/body-mutations.ts +133 -0
- package/src/client/host-api.ts +70 -0
- package/src/client/index.ts +109 -95
- package/src/client/locales.ts +205 -48
- package/src/client/pending-verify.ts +90 -0
- package/src/client/plugin-card-seat.ts +8 -2
- package/src/client/service.ts +24 -0
- package/src/client/settings-card.module.css +466 -89
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/settings-form.ts +102 -60
- package/src/core/attachment.ts +287 -0
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +90 -11
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +120 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/session-reuse.ts +7 -1
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +19 -1
- package/src/core/subtask.ts +144 -68
- package/src/core/tasks.ts +117 -10
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-tag.ts +56 -0
- package/src/core/use-cases/task-update.ts +33 -5
- package/src/core/wire-projection.ts +81 -0
- package/src/core/workspace-target.ts +27 -3
- package/src/host/agent-tools.ts +33 -21
- package/src/host/attachments.ts +650 -0
- package/src/host/extension-registry.ts +150 -5
- package/src/host/launch-admission.ts +139 -0
- package/src/host-ledger.ts +248 -117
- package/src/host-routes.ts +233 -15
- package/src/host-runner.ts +395 -61
- package/src/host-service.ts +512 -139
- package/src/host-spend.ts +105 -0
- package/src/index.ts +312 -92
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +83 -18
- package/src/tool-surface.ts +1 -0
package/src/host-routes.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
|
3
3
|
import type { WebRoute } from '@deepseek-ai/dsh-host-webserver'
|
|
4
4
|
import type { TaskBoardHostService } from './host-service.ts'
|
|
5
5
|
import { writeJson } from './http.ts'
|
|
6
|
-
import { isLoopbackAddress, isLoopbackRequest } from './loopback.ts'
|
|
6
|
+
import { isForwardedLoopbackRequest, isLoopbackAddress, isLoopbackRequest } from './loopback.ts'
|
|
7
7
|
import { TaskParseError, TASK_PARSE_MAX_INPUT } from './host-ai.ts'
|
|
8
8
|
import {
|
|
9
9
|
parseActionEnvelope,
|
|
@@ -12,18 +12,65 @@ import {
|
|
|
12
12
|
type TaskBoardParseDraft,
|
|
13
13
|
type TaskBoardParseRequest,
|
|
14
14
|
} from './protocol.ts'
|
|
15
|
+
import {
|
|
16
|
+
attachmentErrorStatus,
|
|
17
|
+
effectiveImageByteLimit,
|
|
18
|
+
imageRefOf,
|
|
19
|
+
readRequestBytes,
|
|
20
|
+
requestChunks,
|
|
21
|
+
sanitizeAttachmentName,
|
|
22
|
+
storeFile,
|
|
23
|
+
storeImage,
|
|
24
|
+
TaskBoardAttachmentError,
|
|
25
|
+
type TaskBoardAttachmentStore,
|
|
26
|
+
} from './host/attachments.ts'
|
|
15
27
|
|
|
16
28
|
const ACTION_LIMIT = 64 * 1024
|
|
17
29
|
const IMPORT_LIMIT = 2 * 1024 * 1024
|
|
18
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Comment-frame cadence on the event stream. It keeps the connection alive
|
|
32
|
+
* through intermediaries that would close an idle one; it is not a frame the
|
|
33
|
+
* browser reports to the panel (an SSE comment is invisible to EventSource).
|
|
34
|
+
*/
|
|
35
|
+
export const HEARTBEAT_MS = 15_000
|
|
19
36
|
|
|
20
37
|
/** Header replaced by an authenticated same-host reverse proxy. */
|
|
21
38
|
export const TASK_BOARD_PROXY_TOKEN_HEADER = 'x-dsh-task-board-proxy-token'
|
|
22
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The composition's Host connection service, narrowed to the one check the
|
|
42
|
+
* board bridges: `requestRejection` runs the Host/Origin fence and verifies
|
|
43
|
+
* the authority-bound `dsh-auth-*` browser session minted by the Host. It
|
|
44
|
+
* answers `undefined` only for a request it admits and 401/403 otherwise.
|
|
45
|
+
* Declared structurally, like the official open-in-app routes do, because the
|
|
46
|
+
* service's package is a browser-side dependency this Host half does not
|
|
47
|
+
* import.
|
|
48
|
+
*/
|
|
49
|
+
export interface TaskBoardConnectionTrust {
|
|
50
|
+
requestRejection(request: { readonly headers: IncomingMessage['headers'] }): 401 | 403 | undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
23
53
|
/** Optional authenticated reverse-proxy access layered over the loopback default. */
|
|
24
54
|
export interface TaskBoardRouteAccess {
|
|
25
55
|
trustedProxyHosts?: readonly string[]
|
|
26
56
|
proxyToken?: string
|
|
57
|
+
/**
|
|
58
|
+
/**
|
|
59
|
+
* Whether the operator's own reverse proxy or tunnel may speak for the
|
|
60
|
+
* browser: a forwarded request that landed on this machine's loopback
|
|
61
|
+
* upstream then counts as trustable, still behind the browser same-origin
|
|
62
|
+
* marker. Read at each request (hence the function), so the settings switch
|
|
63
|
+
* binds the next request without re-registering the routes. Absent or false
|
|
64
|
+
* keeps the pre-existing fence exactly as it was (issue #1906).
|
|
65
|
+
*/
|
|
66
|
+
trustForwardedProxy?: () => boolean
|
|
67
|
+
/**
|
|
68
|
+
* Resolves the Host's `connection` service when a request arrives, so a
|
|
69
|
+
* deployment that mounts it after these routes still gains the bridge and a
|
|
70
|
+
* composition that never mounts it keeps the pre-existing fence. Absent means
|
|
71
|
+
* no bridge (issue #1930).
|
|
72
|
+
*/
|
|
73
|
+
connection?: () => TaskBoardConnectionTrust | undefined
|
|
27
74
|
}
|
|
28
75
|
|
|
29
76
|
/**
|
|
@@ -34,11 +81,20 @@ export interface TaskBoardRouteAccess {
|
|
|
34
81
|
*/
|
|
35
82
|
export interface TaskBoardRouteOptions {
|
|
36
83
|
parseTask?: (request: TaskBoardParseRequest, signal: AbortSignal) => Promise<TaskBoardParseDraft>
|
|
84
|
+
/**
|
|
85
|
+
* The official attachment storage, read at request time so a deployment that
|
|
86
|
+
* mounts it after these routes still gains the attachment surface. Absent
|
|
87
|
+
* means this deployment stores no attachments, and every attachment route
|
|
88
|
+
* answers with a typed "storage unavailable" failure.
|
|
89
|
+
*/
|
|
90
|
+
attachments?: () => TaskBoardAttachmentStore | undefined
|
|
37
91
|
}
|
|
38
92
|
|
|
39
93
|
interface ResolvedRouteAccess {
|
|
40
94
|
trustedProxyHosts: ReadonlySet<string>
|
|
41
95
|
proxyToken?: string
|
|
96
|
+
trustForwardedProxy: () => boolean
|
|
97
|
+
connection?: () => TaskBoardConnectionTrust | undefined
|
|
42
98
|
}
|
|
43
99
|
|
|
44
100
|
function parseAuthority(authority: string): { canonical: string; url: URL } | undefined {
|
|
@@ -70,7 +126,12 @@ function resolveAccess(access: TaskBoardRouteAccess): ResolvedRouteAccess {
|
|
|
70
126
|
if (trustedProxyHosts.size > 0 && (access.proxyToken === undefined || access.proxyToken === '')) {
|
|
71
127
|
throw new Error('task-board: authenticated proxy hosts require a non-empty proxy token')
|
|
72
128
|
}
|
|
73
|
-
return {
|
|
129
|
+
return {
|
|
130
|
+
trustedProxyHosts,
|
|
131
|
+
trustForwardedProxy: access.trustForwardedProxy ?? ((): boolean => false),
|
|
132
|
+
...(access.proxyToken === undefined ? {} : { proxyToken: access.proxyToken }),
|
|
133
|
+
...(access.connection === undefined ? {} : { connection: access.connection }),
|
|
134
|
+
}
|
|
74
135
|
}
|
|
75
136
|
|
|
76
137
|
/**
|
|
@@ -146,10 +207,36 @@ function matchesToken(candidate: string | string[] | undefined, expected: string
|
|
|
146
207
|
* tripwire, the socket/Host/origin-equality checks carry the authority).
|
|
147
208
|
* Authenticated proxies must be explicitly allowlisted and replace the
|
|
148
209
|
* internal token header after their own authentication step.
|
|
210
|
+
*
|
|
211
|
+
* A third party's proxy cannot inject that token, so a deployment whose own
|
|
212
|
+
* tunnel dials the loopback upstream (issue #1918) can instead turn on
|
|
213
|
+
* trustForwardedProxy: a forwarded request that landed on this machine
|
|
214
|
+
* (loopback socket AND loopback Host) is then admitted on the same browser
|
|
215
|
+
* marker alone. The switch defaults off, so an unconfigured board keeps
|
|
216
|
+
* refusing every forwarded request (issue #1906).
|
|
217
|
+
*
|
|
218
|
+
* A deployment behind a reverse proxy or ingress that DSH itself serves
|
|
219
|
+
* (`--trusted-host`, TLS terminated at the edge) is admitted by the Host's
|
|
220
|
+
* `connection` service instead: a request whose Host/Origin fence and signed
|
|
221
|
+
* browser session it accepts needs no board-specific allowlist, which is why
|
|
222
|
+
* the check runs first when the service is mounted (issue #1930). The fence
|
|
223
|
+
* below stays untouched as the fallback, so a deployment without the service,
|
|
224
|
+
* and every direct client the service does not admit, keeps exactly the
|
|
225
|
+
* pre-existing decision.
|
|
149
226
|
*/
|
|
150
227
|
export function isTrustedTaskBoardRequest(req: IncomingMessage, access: ResolvedRouteAccess): boolean {
|
|
228
|
+
const connection = access.connection?.()
|
|
229
|
+
if (connection !== undefined && connection.requestRejection(req) === undefined) return true
|
|
151
230
|
if (!browserSameOriginMarker(req)) return false
|
|
152
231
|
if (isLoopbackRequest(req)) return true
|
|
232
|
+
// The tunnel makes the socket and the Host describe the proxy, so the
|
|
233
|
+
// origin-equality check of the direct fence has nothing to compare on this
|
|
234
|
+
// path; the explicit cross-site marker is then the one signal that separates
|
|
235
|
+
// the operator's own page from a third-party page posting through the tunnel,
|
|
236
|
+
// and it is refused instead of being read as a mere tripwire.
|
|
237
|
+
if (access.trustForwardedProxy()
|
|
238
|
+
&& req.headers['sec-fetch-site'] !== 'cross-site'
|
|
239
|
+
&& isForwardedLoopbackRequest(req)) return true
|
|
153
240
|
if (!isLoopbackAddress(req.socket.remoteAddress)) return false
|
|
154
241
|
const host = req.headers.host
|
|
155
242
|
if (typeof host !== 'string') return false
|
|
@@ -172,6 +259,18 @@ async function readBody(req: IncomingMessage): Promise<{ raw: string; value: unk
|
|
|
172
259
|
return { raw, value: JSON.parse(raw) }
|
|
173
260
|
}
|
|
174
261
|
|
|
262
|
+
/**
|
|
263
|
+
* The query parameters of one request, read against a fixed base so a
|
|
264
|
+
* relative request target still parses.
|
|
265
|
+
*/
|
|
266
|
+
function requestQuery(req: IncomingMessage): URLSearchParams {
|
|
267
|
+
try {
|
|
268
|
+
return new URL(req.url ?? '/', 'http://localhost').searchParams
|
|
269
|
+
} catch {
|
|
270
|
+
return new URLSearchParams()
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
175
274
|
export function makeTaskBoardRoutes(
|
|
176
275
|
service: TaskBoardHostService,
|
|
177
276
|
access: TaskBoardRouteAccess = {},
|
|
@@ -208,9 +307,19 @@ export function makeTaskBoardRoutes(
|
|
|
208
307
|
if (parsed.action.kind !== 'import' && Buffer.byteLength(body.raw) > ACTION_LIMIT) {
|
|
209
308
|
return writeJson(res, 413, { ok: false, error: 'body-too-large' }, { 'cache-control': 'no-store' })
|
|
210
309
|
}
|
|
211
|
-
|
|
310
|
+
// The verified path: an action that carries attachments is proven
|
|
311
|
+
// against the official storage BEFORE the ledger commits it, so a
|
|
312
|
+
// spoofed claim can never become a stored fact.
|
|
313
|
+
writeJson(res, 200, await service.applyVerified(parsed.requestId, parsed.action, parsed.initiator), { 'cache-control': 'no-store' })
|
|
212
314
|
} catch (error) {
|
|
213
315
|
const message = error instanceof Error ? error.message : String(error)
|
|
316
|
+
// An attachment failure keeps its own class: a storage that is
|
|
317
|
+
// unavailable answers 503 exactly like the upload route does, instead
|
|
318
|
+
// of being flattened into a generic rejected action.
|
|
319
|
+
if (error instanceof TaskBoardAttachmentError) {
|
|
320
|
+
writeJson(res, attachmentErrorStatus(error.code), { ok: false, code: error.code, error: message }, { 'cache-control': 'no-store' })
|
|
321
|
+
return
|
|
322
|
+
}
|
|
214
323
|
writeJson(res, message === 'body-too-large' ? 413 : 400, { ok: false, error: message }, { 'cache-control': 'no-store' })
|
|
215
324
|
}
|
|
216
325
|
},
|
|
@@ -230,18 +339,48 @@ export function makeTaskBoardRoutes(
|
|
|
230
339
|
'cache-control': 'no-cache',
|
|
231
340
|
connection: 'keep-alive',
|
|
232
341
|
})
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
342
|
+
// The stream is the board's only live signal, so it also has to be able to
|
|
343
|
+
// STOP being one. A connection can stop accepting bytes while neither end
|
|
344
|
+
// has closed it (a half-open socket, an intermediary that stopped
|
|
345
|
+
// reading); from then on every frame is written into nothing, the browser's
|
|
346
|
+
// EventSource sees an open stream that never speaks, and the panel keeps
|
|
347
|
+
// the snapshot it last applied with no error to react to. A failed write is
|
|
348
|
+
// the one report of that state, so it ends the connection here: the browser
|
|
349
|
+
// then reports the closed stream, and a closed stream makes the panel read
|
|
350
|
+
// the state again.
|
|
351
|
+
let heartbeat: ReturnType<typeof setInterval> | undefined
|
|
352
|
+
let release: (() => void) | undefined
|
|
353
|
+
const stop = (): void => {
|
|
354
|
+
if (heartbeat !== undefined) {
|
|
355
|
+
clearInterval(heartbeat)
|
|
356
|
+
heartbeat = undefined
|
|
357
|
+
}
|
|
358
|
+
const unsubscribe = release
|
|
359
|
+
release = undefined
|
|
360
|
+
unsubscribe?.()
|
|
361
|
+
}
|
|
362
|
+
const drop = (): void => {
|
|
363
|
+
if (release === undefined) return
|
|
364
|
+
stop()
|
|
365
|
+
res.destroy()
|
|
236
366
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
367
|
+
const write = (chunk: string): void => {
|
|
368
|
+
if (release === undefined || res.writableEnded || res.destroyed) return
|
|
369
|
+
// The callback is the only place Node reports a write that never landed;
|
|
370
|
+
// its result (backpressure) is not an error and is ignored.
|
|
371
|
+
res.write(chunk, (error) => { if (error !== null && error !== undefined) drop() })
|
|
242
372
|
}
|
|
243
|
-
|
|
244
|
-
|
|
373
|
+
const push = (): void => {
|
|
374
|
+
write(`data: ${JSON.stringify(service.eventPayload())}\n\n`)
|
|
375
|
+
}
|
|
376
|
+
release = service.subscribe(push)
|
|
377
|
+
heartbeat = setInterval(() => { write(': ping\n\n') }, HEARTBEAT_MS)
|
|
378
|
+
req.once('close', stop)
|
|
379
|
+
res.once('close', stop)
|
|
380
|
+
// A reset socket reports the same fact as a failed write. Without this
|
|
381
|
+
// listener Node treats a response error as unhandled, so the connection is
|
|
382
|
+
// released here instead of being left behind.
|
|
383
|
+
res.on('error', () => { drop() })
|
|
245
384
|
push()
|
|
246
385
|
},
|
|
247
386
|
}
|
|
@@ -302,5 +441,84 @@ export function makeTaskBoardRoutes(
|
|
|
302
441
|
}
|
|
303
442
|
},
|
|
304
443
|
}
|
|
305
|
-
|
|
444
|
+
const attachmentUpload: WebRoute = {
|
|
445
|
+
kind: 'exact',
|
|
446
|
+
path: `${TASK_BOARD_API_PREFIX}/attachments/upload`,
|
|
447
|
+
handler: async (req, res): Promise<void> => {
|
|
448
|
+
if (req.method !== 'POST') return writeJson(res, 405, { ok: false, error: 'method-not-allowed' }, { 'cache-control': 'no-store' })
|
|
449
|
+
if (!guard(req, res)) return
|
|
450
|
+
const store = options.attachments?.()
|
|
451
|
+
if (store === undefined) {
|
|
452
|
+
return writeJson(res, 503, { ok: false, code: 'storage-unavailable', error: 'this deployment serves no attachment storage' }, { 'cache-control': 'no-store' })
|
|
453
|
+
}
|
|
454
|
+
const query = requestQuery(req)
|
|
455
|
+
const kind = query.get('kind')
|
|
456
|
+
if (kind !== 'image' && kind !== 'file') {
|
|
457
|
+
return writeJson(res, 400, { ok: false, code: 'invalid-request', error: 'the attachment kind must be image or file' }, { 'cache-control': 'no-store' })
|
|
458
|
+
}
|
|
459
|
+
const name = sanitizeAttachmentName(query.get('name'))
|
|
460
|
+
const mediaType = query.get('mediaType') ?? ''
|
|
461
|
+
try {
|
|
462
|
+
if (kind === 'image') {
|
|
463
|
+
// The declared type is what the storage checks the decoded bytes
|
|
464
|
+
// against, so it is required rather than guessed: a guess would
|
|
465
|
+
// store a mislabelled object or fail with the storage's own
|
|
466
|
+
// mismatch error.
|
|
467
|
+
if (mediaType === '') {
|
|
468
|
+
return writeJson(res, 400, { ok: false, code: 'invalid-request', error: 'an image upload must declare its media type' }, { 'cache-control': 'no-store' })
|
|
469
|
+
}
|
|
470
|
+
const limit = effectiveImageByteLimit(store)
|
|
471
|
+
const bytes = await readRequestBytes(req, limit)
|
|
472
|
+
const attachment = await storeImage(store, bytes, name, mediaType)
|
|
473
|
+
writeJson(res, 200, { ok: true, attachment }, { 'cache-control': 'no-store' })
|
|
474
|
+
return
|
|
475
|
+
}
|
|
476
|
+
const stored = await storeFile(store, requestChunks(req), name, mediaType)
|
|
477
|
+
writeJson(res, 200, { ok: true, attachment: stored.attachment }, { 'cache-control': 'no-store' })
|
|
478
|
+
} catch (error) {
|
|
479
|
+
// The body is drained so the refusal reaches the caller instead of a
|
|
480
|
+
// closed socket.
|
|
481
|
+
req.resume()
|
|
482
|
+
const failure = error instanceof TaskBoardAttachmentError
|
|
483
|
+
? error
|
|
484
|
+
: new TaskBoardAttachmentError('storage-unavailable', 'the attachment storage is unavailable', { cause: error })
|
|
485
|
+
writeJson(res, attachmentErrorStatus(failure.code), { ok: false, code: failure.code, error: failure.message }, { 'cache-control': 'no-store' })
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
}
|
|
489
|
+
const attachmentImage: WebRoute = {
|
|
490
|
+
kind: 'exact',
|
|
491
|
+
path: `${TASK_BOARD_API_PREFIX}/attachments/image`,
|
|
492
|
+
handler: async (req, res): Promise<void> => {
|
|
493
|
+
if (req.method !== 'GET') return writeJson(res, 405, { ok: false, error: 'method-not-allowed' }, { 'cache-control': 'no-store' })
|
|
494
|
+
if (!guard(req, res)) return
|
|
495
|
+
const store = options.attachments?.()
|
|
496
|
+
if (store === undefined) {
|
|
497
|
+
return writeJson(res, 503, { ok: false, code: 'storage-unavailable', error: 'this deployment serves no attachment storage' }, { 'cache-control': 'no-store' })
|
|
498
|
+
}
|
|
499
|
+
const id = requestQuery(req).get('id') ?? ''
|
|
500
|
+
// An image is served only when a card of THIS board references it: an
|
|
501
|
+
// unreferenced identifier must never become a readable object.
|
|
502
|
+
const referenced = service.ledger.allTasks().flatMap(task => task.attachments ?? [])
|
|
503
|
+
.find(attachment => attachment.kind === 'image' && attachment.attachmentId === id)
|
|
504
|
+
if (referenced === undefined) {
|
|
505
|
+
return writeJson(res, 404, { ok: false, code: 'not-found', error: 'no card references this attachment' }, { 'cache-control': 'no-store' })
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
const stored = await store.readImage(imageRefOf(referenced))
|
|
509
|
+
res.writeHead(200, {
|
|
510
|
+
'content-type': stored.ref.mediaType,
|
|
511
|
+
'content-length': String(stored.data.byteLength),
|
|
512
|
+
'cache-control': 'no-store',
|
|
513
|
+
})
|
|
514
|
+
res.end(Buffer.from(stored.data))
|
|
515
|
+
} catch (error) {
|
|
516
|
+
const failure = error instanceof TaskBoardAttachmentError
|
|
517
|
+
? error
|
|
518
|
+
: new TaskBoardAttachmentError('unreadable', 'the stored attachment could not be read back', { cause: error })
|
|
519
|
+
writeJson(res, attachmentErrorStatus(failure.code), { ok: false, code: failure.code, error: failure.message }, { 'cache-control': 'no-store' })
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
}
|
|
523
|
+
return [state, action, events, parse, verification, attachmentUpload, attachmentImage]
|
|
306
524
|
}
|