@alexsun-top/opencode-chat-room 0.8.0 → 0.8.1
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/CHANGELOG.md +29 -0
- package/LICENSE +2 -2
- package/README.md +38 -6
- package/README.zh-CN.md +38 -6
- package/cli.ts +27 -1
- package/dist/cli.js +5074 -3212
- package/package.json +23 -3
- package/packages/chat-room-channeld/README.md +98 -25
- package/packages/chat-room-channeld/dist/feishu-adapter.js +912 -149
- package/packages/chat-room-channeld/src/adapter.ts +36 -2
- package/packages/chat-room-channeld/src/config.ts +63 -1
- package/packages/chat-room-channeld/src/delivery.ts +6 -1
- package/packages/chat-room-channeld/src/feishu-adapter.ts +122 -292
- package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
- package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
- package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
- package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
- package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
- package/packages/chat-room-channeld/src/host.ts +120 -2
- package/packages/chat-room-channeld/src/inbound.ts +26 -0
- package/packages/chat-room-channeld/src/state.ts +17 -0
- package/packages/chat-room-channeld/src/stats.ts +43 -1
- package/server/admin-state.ts +13 -13
- package/server/app.ts +95 -0
- package/server/assets/NOTICE.txt +2 -1
- package/server/assets/base.css +15 -9
- package/server/assets/chat/announcements.js +70 -7
- package/server/assets/chat/doc-preview.js +184 -35
- package/server/assets/chat/events.js +3 -0
- package/server/assets/chat/files.js +46 -4
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/integration-editor.js +163 -0
- package/server/assets/chat/integration-values.js +124 -0
- package/server/assets/chat/integrations.js +498 -0
- package/server/assets/chat/locales/de.js +40 -4
- package/server/assets/chat/locales/es.js +40 -4
- package/server/assets/chat/locales/fr.js +40 -4
- package/server/assets/chat/locales/it.js +40 -4
- package/server/assets/chat/locales/ja.js +40 -4
- package/server/assets/chat/locales/ko.js +40 -4
- package/server/assets/chat/markdown.js +22 -8
- package/server/assets/chat/messages.js +5 -5
- package/server/assets/chat/office-preview.js +69 -0
- package/server/assets/chat/panels.js +36 -0
- package/server/assets/chat/recall.js +58 -7
- package/server/assets/chat/receipts.js +15 -3
- package/server/assets/chat/reminders.js +69 -8
- package/server/assets/chat/resource-format.js +11 -0
- package/server/assets/chat/settings.js +30 -2
- package/server/assets/chat/side-pane.js +1 -2
- package/server/assets/chat/state.js +93 -10
- package/server/assets/chat/system-events.js +32 -0
- package/server/assets/chat/system-messages.js +23 -14
- package/server/assets/chat/task-row.js +0 -6
- package/server/assets/chat/tasks.js +121 -33
- package/server/assets/code-highlight.css +55 -32
- package/server/assets/conversation.css +123 -23
- package/server/assets/doc-preview.css +35 -3
- package/server/assets/files.css +5 -0
- package/server/assets/fluent-icons.svg +2 -0
- package/server/assets/monaco/LICENSE +21 -0
- package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
- package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
- package/server/assets/monaco/editor.worker.js +45 -0
- package/server/assets/monaco/integration-rules.css +1 -0
- package/server/assets/monaco/integration-rules.js +1297 -0
- package/server/assets/monaco/json.worker.js +77 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
- package/server/assets/office/docx.bundle.js +33 -0
- package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
- package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
- package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
- package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
- package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
- package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
- package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
- package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
- package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
- package/server/assets/office/pptx.bundle.js +104 -0
- package/server/assets/office/xlsx.bundle.js +141 -0
- package/server/assets/recall.css +5 -4
- package/server/assets/responsive.css +50 -11
- package/server/assets/settings.css +73 -1
- package/server/assets/tasks.css +57 -7
- package/server/channel-integration.ts +519 -0
- package/server/channel-settings.ts +77 -0
- package/server/channels.ts +261 -18
- package/server/chat-server.ts +32 -580
- package/server/chat.html +187 -21
- package/server/http-server.ts +3 -182
- package/server/resource-routes.ts +16 -16
- package/server/routes/inbox.ts +100 -0
- package/server/routes/pages.ts +83 -0
- package/server/routes/questions.ts +39 -0
- package/server/routes/room-actions.ts +162 -0
- package/server/routes/rooms.ts +160 -0
- package/server/startup.ts +84 -0
- package/server/sw.js +4 -0
- package/server/task-routes.ts +1 -1
- package/src/center/center-client.ts +2 -10
- package/src/config/file-config.ts +7 -54
- package/src/platform/http-server.ts +182 -0
- package/src/protocol/addressing.ts +21 -0
- package/src/protocol/config.ts +58 -0
- package/src/protocol/room.ts +51 -0
- package/src/rooms/resources.ts +26 -16
- package/src/rooms/room-service.ts +2 -48
- package/src/rooms/storage.ts +329 -0
- package/src/rooms/tasks.ts +21 -5
- package/src/runtime/watch.ts +1 -1
- package/src/state/pg-database.ts +183 -0
- package/src/state/pg-migrate.ts +175 -0
- package/src/state/pg-sql.mjs +175 -0
- package/src/state/pg-worker.mjs +148 -0
- package/src/state/sqlite-announcements.ts +25 -0
- package/src/state/sqlite-database.ts +121 -0
- package/src/state/sqlite-legacy.ts +90 -0
- package/src/state/sqlite-members.ts +155 -0
- package/src/state/sqlite-messages.ts +288 -0
- package/src/state/sqlite-resources.ts +39 -0
- package/src/state/sqlite-rooms.ts +87 -0
- package/src/state/sqlite-schema.ts +80 -0
- package/src/state/sqlite-state-store.ts +33 -0
- package/src/state/sqlite-state.ts +15 -897
- package/src/state/sqlite-tasks.ts +65 -0
- package/src/state/sqlite-transaction.ts +13 -0
- package/src/state/sqlite.ts +21 -1
- package/src/state/store.ts +5 -1
- package/src/tui/app.mjs +32 -19
- package/src/tui/config.mjs +12 -4
- package/src/tui/i18n.mjs +38 -0
- package/src/tui/info-app.mjs +50 -51
- package/src/tui/info-content.mjs +79 -44
- package/src/tui/join-app.mjs +9 -9
- package/src/tui/locales/en.mjs +349 -0
- package/src/tui/locales/zh-CN.mjs +349 -0
- package/src/tui/main.mjs +85 -37
- package/src/tui/markdown.mjs +3 -2
- package/src/tui/mentions.mjs +3 -1
- package/src/tui/message-app.mjs +22 -21
- package/src/tui/message-view.mjs +2 -1
- package/src/tui/palette-app.mjs +9 -8
- package/src/tui/palette.mjs +30 -24
- package/src/tui/prefs.mjs +92 -0
- package/src/tui/reminder-app.mjs +18 -17
- package/src/tui/room-settings-app.mjs +30 -28
- package/src/tui/settings-app.mjs +153 -0
- package/src/tui/ui-content.mjs +65 -86
- package/src/tui/ui-help.mjs +73 -0
- package/src/tui/ui-overlay-view.mjs +23 -7
- package/src/tui/ui-suggest.mjs +6 -5
- package/src/tui/ui-theme.mjs +37 -33
- package/src/tui/ui-view.mjs +22 -7
- package/src/tui/ui.mjs +15 -3
- package/src/web/editor.worker.ts +1 -0
- package/src/web/integration-rules-editor.ts +439 -0
- package/src/web/integration-rules.ts +22 -0
- package/src/web/integration-schema.ts +228 -0
- package/src/web/json.worker.ts +1 -0
- package/src/web/office-viewer.ts +221 -0
package/server/chat.html
CHANGED
|
@@ -10,11 +10,15 @@
|
|
|
10
10
|
<link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png">
|
|
11
11
|
<meta name="theme-color" content="#f3f1ea">
|
|
12
12
|
<script>
|
|
13
|
-
// Resolve the saved theme before the first paint
|
|
13
|
+
// Resolve the saved theme and outer window frame before the first paint.
|
|
14
14
|
try {
|
|
15
15
|
var savedTheme = localStorage.getItem("chat.theme");
|
|
16
16
|
document.documentElement.dataset.theme = ["light", "dark", "forest", "sand"].includes(savedTheme) ? savedTheme : "system";
|
|
17
17
|
} catch { document.documentElement.dataset.theme = "system"; }
|
|
18
|
+
document.documentElement.dataset.windowFrame = "framed";
|
|
19
|
+
try {
|
|
20
|
+
if (localStorage.getItem("chat.windowFrame") === "borderless") document.documentElement.dataset.windowFrame = "borderless";
|
|
21
|
+
} catch { /* A blocked localStorage keeps the framed default. */ }
|
|
18
22
|
</script>
|
|
19
23
|
<meta name="mobile-web-app-capable" content="yes">
|
|
20
24
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
@@ -35,7 +39,7 @@
|
|
|
35
39
|
<link rel="stylesheet" href="/assets/doc-preview.css?v={{version}}">
|
|
36
40
|
<link rel="stylesheet" href="/assets/diagram-viewer.css?v={{version}}">
|
|
37
41
|
</head>
|
|
38
|
-
<body data-channeld="{{channeld}}">
|
|
42
|
+
<body data-channeld="{{channeld}}" data-integrations-admin="{{integrationsAdmin}}">
|
|
39
43
|
|
|
40
44
|
<main id="app">
|
|
41
45
|
<section id="restoreView" class="restore-view" role="status" aria-live="polite">
|
|
@@ -152,6 +156,10 @@
|
|
|
152
156
|
<svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-circle_half_fill-24"></use></svg>
|
|
153
157
|
<span data-i18n="settingsAppearance">Appearance</span>
|
|
154
158
|
</button>
|
|
159
|
+
<button id="settingsTabIntegrations" class="settings-tab" type="button" role="tab" aria-selected="false" aria-controls="settingsPanelIntegrations" tabindex="-1" data-settings-tab="integrations">
|
|
160
|
+
<svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-plug_connected-24"></use></svg>
|
|
161
|
+
<span data-i18n="settingsIntegrations">Integrations</span>
|
|
162
|
+
</button>
|
|
155
163
|
<button id="settingsTabConnection" class="settings-tab" type="button" role="tab" aria-selected="false" aria-controls="settingsPanelConnection" tabindex="-1" data-settings-tab="connection">
|
|
156
164
|
<svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-plug_connected-24"></use></svg>
|
|
157
165
|
<span data-i18n="settingsConnection">Connection</span>
|
|
@@ -225,6 +233,91 @@
|
|
|
225
233
|
</label>
|
|
226
234
|
</div>
|
|
227
235
|
</fieldset>
|
|
236
|
+
<div class="settings-row">
|
|
237
|
+
<div class="settings-copy">
|
|
238
|
+
<label class="settings-label" for="inWindowFrame"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-options-24"></use></svg><span data-i18n="windowFrameLabel">Window frame</span></label>
|
|
239
|
+
<p id="windowFrameHint" class="settings-hint" data-i18n="windowFrameHint">Framed keeps the inset card; Borderless fills the window.</p>
|
|
240
|
+
</div>
|
|
241
|
+
<select id="inWindowFrame" class="input settings-select" aria-describedby="windowFrameHint">
|
|
242
|
+
<option value="framed" data-i18n="windowFrameFramed" selected>Framed</option>
|
|
243
|
+
<option value="borderless" data-i18n="windowFrameBorderless">Borderless</option>
|
|
244
|
+
</select>
|
|
245
|
+
</div>
|
|
246
|
+
<fieldset class="settings-block panel-mode-block">
|
|
247
|
+
<legend class="settings-label"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-options-24"></use></svg><span data-i18n="settingsPanelMode">Tool windows</span></legend>
|
|
248
|
+
<p class="settings-hint" data-i18n="settingsPanelModeHint">Choose how each room tool opens on wide screens. Narrow or short windows always use a dialog.</p>
|
|
249
|
+
<div class="panel-mode-grid">
|
|
250
|
+
<label class="panel-mode-row"><span data-i18n="announcements">Announcements</span><select class="input settings-select" data-panel-mode="announcements"><option value="dialog" data-i18n="panelModeDialog">Dialog</option><option value="pane" data-i18n="panelModePane">Side pane</option></select></label>
|
|
251
|
+
<label class="panel-mode-row"><span data-i18n="filesTitle">Files</span><select class="input settings-select" data-panel-mode="files"><option value="dialog" data-i18n="panelModeDialog">Dialog</option><option value="pane" data-i18n="panelModePane">Side pane</option></select></label>
|
|
252
|
+
<label class="panel-mode-row"><span data-i18n="tasksTitle">Tasks</span><select class="input settings-select" data-panel-mode="tasks"><option value="dialog" data-i18n="panelModeDialog">Dialog</option><option value="pane" data-i18n="panelModePane">Side pane</option></select></label>
|
|
253
|
+
<label class="panel-mode-row"><span data-i18n="reminders">Reminders</span><select class="input settings-select" data-panel-mode="reminders"><option value="dialog" data-i18n="panelModeDialog">Dialog</option><option value="pane" data-i18n="panelModePane">Side pane</option></select></label>
|
|
254
|
+
</div>
|
|
255
|
+
</fieldset>
|
|
256
|
+
</section>
|
|
257
|
+
<section id="settingsPanelIntegrations" class="settings-panel integration-panel" role="tabpanel" aria-labelledby="settingsTabIntegrations" hidden>
|
|
258
|
+
<div class="integration-lead">
|
|
259
|
+
<p class="settings-hint" data-i18n="integrationsHint">Connect rooms with external platforms through uploaded plugins. Secret values stay on the server.</p>
|
|
260
|
+
<button id="btnRefreshIntegrations" class="btn ghost small" type="button" data-i18n="refreshQuestions">Refresh</button>
|
|
261
|
+
</div>
|
|
262
|
+
<p id="integrationStatus" class="hint" role="status" aria-live="polite"></p>
|
|
263
|
+
<p id="integrationError" class="alert integration-error" role="alert" hidden></p>
|
|
264
|
+
<p id="integrationExternalNotice" class="integration-external-notice" data-i18n="integrationsExternalConfig" role="status" hidden>This integration uses an external configuration file. Edit that file, or disable it before saving managed settings.</p>
|
|
265
|
+
<div class="settings-row integration-enable-row">
|
|
266
|
+
<div class="settings-copy">
|
|
267
|
+
<label class="settings-label" for="inIntegrationsEnabled"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-plug_connected-24"></use></svg><span data-i18n="integrationsEnable">Enable integrations</span></label>
|
|
268
|
+
<p class="settings-hint" data-i18n="integrationsEnableHint">Starts or stops the integration runtime immediately.</p>
|
|
269
|
+
</div>
|
|
270
|
+
<input id="inIntegrationsEnabled" class="settings-switch" type="checkbox" role="switch">
|
|
271
|
+
</div>
|
|
272
|
+
<section class="integration-section" aria-labelledby="integrationAccountsHeading">
|
|
273
|
+
<header class="integration-section-head">
|
|
274
|
+
<h3 id="integrationAccountsHeading" data-i18n="integrationsAccounts">Accounts</h3>
|
|
275
|
+
<button id="btnAddIntegrationAccount" class="btn ghost small" type="button" data-i18n="integrationsAddAccount">Add account</button>
|
|
276
|
+
</header>
|
|
277
|
+
<ul id="integrationAccounts" class="integration-accounts"></ul>
|
|
278
|
+
<p id="integrationAccountsEmpty" class="hint" data-i18n="integrationsEmptyAccounts" hidden>No accounts yet.</p>
|
|
279
|
+
</section>
|
|
280
|
+
<section class="integration-section" aria-labelledby="integrationPluginsHeading">
|
|
281
|
+
<header class="integration-section-head">
|
|
282
|
+
<h3 id="integrationPluginsHeading" data-i18n="integrationsPlugins">Plugins</h3>
|
|
283
|
+
<button id="btnUploadPlugin" class="btn ghost small" type="button" data-i18n="integrationsUploadPlugin">Upload plugin</button>
|
|
284
|
+
</header>
|
|
285
|
+
<ul id="integrationPlugins" class="integration-plugins"></ul>
|
|
286
|
+
<p id="integrationPluginsEmpty" class="hint" data-i18n="integrationsEmptyPlugins" hidden>No plugins uploaded yet.</p>
|
|
287
|
+
</section>
|
|
288
|
+
<section class="integration-section integration-rules-section" aria-labelledby="integrationRulesHeading">
|
|
289
|
+
<header class="integration-section-head">
|
|
290
|
+
<h3 id="integrationRulesHeading" data-i18n="integrationsRules">Outbound rules</h3>
|
|
291
|
+
<div id="integrationRulesFormat" class="integration-format-toggle" role="group" aria-label="Rules format" data-i18n-aria-label="integrationsRulesFormat" hidden>
|
|
292
|
+
<button id="integrationRulesFormatJson" class="integration-format-btn" type="button" data-format="json" aria-pressed="true">JSON</button>
|
|
293
|
+
<button id="integrationRulesFormatYaml" class="integration-format-btn" type="button" data-format="yaml" aria-pressed="false">YAML</button>
|
|
294
|
+
</div>
|
|
295
|
+
</header>
|
|
296
|
+
<p class="settings-hint" data-i18n="integrationsRulesHint">Outbound rules forward room events to connected accounts. Use JSON or YAML; each target must use an existing account.</p>
|
|
297
|
+
<div id="integrationRulesEditor" class="integration-rules-editor" aria-label="Outbound rules editor" data-i18n-aria-label="integrationsRules" hidden></div>
|
|
298
|
+
<textarea id="integrationRules" class="input integration-rules" rows="8" spellcheck="false" aria-describedby="integrationRulesError"></textarea>
|
|
299
|
+
<p id="integrationRulesFallback" class="settings-hint" data-i18n="integrationsEditorUnavailable" hidden></p>
|
|
300
|
+
<p id="integrationRulesError" class="hint integration-field-error" role="alert" hidden></p>
|
|
301
|
+
<ul id="integrationRulesErrorList" class="integration-rule-errors" aria-label="Outbound rule errors" hidden></ul>
|
|
302
|
+
</section>
|
|
303
|
+
<section class="integration-section integration-rules-section" aria-labelledby="integrationInboundHeading">
|
|
304
|
+
<header class="integration-section-head">
|
|
305
|
+
<h3 id="integrationInboundHeading" data-i18n="integrationsInboundRules">Inbound routes</h3>
|
|
306
|
+
<div id="integrationInboundFormat" class="integration-format-toggle" role="group" aria-label="Rules format" data-i18n-aria-label="integrationsRulesFormat" hidden>
|
|
307
|
+
<button id="integrationInboundFormatJson" class="integration-format-btn" type="button" data-format="json" aria-pressed="true">JSON</button>
|
|
308
|
+
<button id="integrationInboundFormatYaml" class="integration-format-btn" type="button" data-format="yaml" aria-pressed="false">YAML</button>
|
|
309
|
+
</div>
|
|
310
|
+
</header>
|
|
311
|
+
<p class="settings-hint" data-i18n="integrationsInboundHint">Inbound routes bring external messages into a room. Each route needs a configured account and a room.</p>
|
|
312
|
+
<div id="integrationInboundEditor" class="integration-rules-editor" aria-label="Inbound routes editor" data-i18n-aria-label="integrationsInboundRules" hidden></div>
|
|
313
|
+
<textarea id="integrationInbound" class="input integration-rules" rows="6" spellcheck="false" aria-describedby="integrationInboundError"></textarea>
|
|
314
|
+
<p id="integrationInboundFallback" class="settings-hint" data-i18n="integrationsEditorUnavailable" hidden></p>
|
|
315
|
+
<p id="integrationInboundError" class="hint integration-field-error" role="alert" hidden></p>
|
|
316
|
+
<ul id="integrationInboundErrorList" class="integration-rule-errors" aria-label="Inbound route errors" hidden></ul>
|
|
317
|
+
</section>
|
|
318
|
+
<div class="integration-actions">
|
|
319
|
+
<button id="btnSaveIntegrations" class="btn primary small" type="button" data-i18n="integrationsSave">Save integrations</button>
|
|
320
|
+
</div>
|
|
228
321
|
</section>
|
|
229
322
|
<section id="settingsPanelConnection" class="settings-panel" role="tabpanel" aria-labelledby="settingsTabConnection" hidden>
|
|
230
323
|
<div class="settings-row settings-row-stack">
|
|
@@ -243,6 +336,48 @@
|
|
|
243
336
|
</div>
|
|
244
337
|
</div>
|
|
245
338
|
</dialog>
|
|
339
|
+
<dialog id="integrationAccountDialog" class="admin-dialog integration-dialog" aria-labelledby="integrationAccountHeading">
|
|
340
|
+
<header class="admin-dialog-head"><h2 id="integrationAccountHeading" data-i18n="integrationsAccountTitle">Integration account</h2><button id="btnCloseIntegrationAccount" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button></header>
|
|
341
|
+
<form id="integrationAccountForm" class="integration-form" novalidate>
|
|
342
|
+
<p id="integrationAccountError" class="alert integration-error" role="alert" hidden></p>
|
|
343
|
+
<label class="field"><span class="field-label" data-i18n="integrationsAccountId">Account ID</span><input id="integrationAccountId" class="input" maxlength="128" autocomplete="off" required></label>
|
|
344
|
+
<label class="field"><span class="field-label" data-i18n="integrationsPlugin">Plugin</span><select id="integrationAccountPlugin" class="input" required></select></label>
|
|
345
|
+
<label class="field"><span class="field-label" data-i18n="integrationsPlatform">Platform</span><input id="integrationAccountPlatform" class="input" readonly></label>
|
|
346
|
+
<fieldset class="field integration-env-field">
|
|
347
|
+
<legend class="field-label" data-i18n="integrationsEnv">Environment values</legend>
|
|
348
|
+
<div id="integrationAccountEnv" class="integration-env-rows"></div>
|
|
349
|
+
<div class="integration-env-actions">
|
|
350
|
+
<button id="btnAddAccountEnv" class="btn ghost small" type="button" data-i18n="integrationsAddEnv">Add variable</button>
|
|
351
|
+
<button id="btnClearAccountEnv" class="btn ghost small" type="button" data-i18n="integrationsClearEnv">Clear stored values</button>
|
|
352
|
+
</div>
|
|
353
|
+
<p id="integrationAccountEnvNote" class="hint integration-env-note" hidden></p>
|
|
354
|
+
<p class="hint" data-i18n="integrationsEnvHint">Leave all values blank to keep the stored set. Entering a value replaces it.</p>
|
|
355
|
+
</fieldset>
|
|
356
|
+
<div class="announcement-actions">
|
|
357
|
+
<button id="btnSaveIntegrationAccount" class="btn primary small" type="submit" data-i18n="save">Save</button>
|
|
358
|
+
<button id="btnCancelIntegrationAccount" class="btn ghost small" type="button" data-i18n="cancel">Cancel</button>
|
|
359
|
+
</div>
|
|
360
|
+
</form>
|
|
361
|
+
</dialog>
|
|
362
|
+
<dialog id="integrationPluginDialog" class="admin-dialog integration-dialog integration-plugin-dialog" aria-labelledby="integrationPluginHeading">
|
|
363
|
+
<header class="admin-dialog-head"><h2 id="integrationPluginHeading" data-i18n="integrationsUploadPlugin">Upload plugin</h2><button id="btnCloseIntegrationPlugin" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button></header>
|
|
364
|
+
<form id="integrationPluginForm" class="integration-form" novalidate>
|
|
365
|
+
<p id="integrationPluginError" class="alert integration-error" role="alert" hidden></p>
|
|
366
|
+
<label class="field"><span class="field-label" data-i18n="integrationsPluginFile">Choose a JS file</span><input id="integrationPluginFile" class="input" type="file" accept=".js,.mjs,.cjs"></label>
|
|
367
|
+
<label class="field"><span class="field-label" data-i18n="integrationsPluginName">Plugin name</span><input id="integrationPluginName" class="input" maxlength="128" autocomplete="off" placeholder="adapter.js"></label>
|
|
368
|
+
<label class="field"><span class="field-label" data-i18n="integrationsPlatform">Platform</span><input id="integrationPluginPlatform" class="input" maxlength="128" autocomplete="off"></label>
|
|
369
|
+
<label class="field"><span class="field-label" data-i18n="integrationsPluginSource">JavaScript source</span><textarea id="integrationPluginSource" class="input integration-source" rows="8" spellcheck="false" placeholder="Paste plugin JavaScript (max 256 KiB)" data-i18n-placeholder="integrationsPluginPaste"></textarea></label>
|
|
370
|
+
<fieldset class="field integration-env-field">
|
|
371
|
+
<legend class="field-label" data-i18n="integrationsEnv">Environment values</legend>
|
|
372
|
+
<div id="integrationPluginEnv" class="integration-env-rows"></div>
|
|
373
|
+
<button id="btnAddPluginEnv" class="btn ghost small" type="button" data-i18n="integrationsAddEnv">Add variable</button>
|
|
374
|
+
</fieldset>
|
|
375
|
+
<div class="announcement-actions">
|
|
376
|
+
<button id="btnSaveIntegrationPlugin" class="btn primary small" type="submit" data-i18n="integrationsUpload">Upload plugin</button>
|
|
377
|
+
<button id="btnCancelIntegrationPlugin" class="btn ghost small" type="button" data-i18n="cancel">Cancel</button>
|
|
378
|
+
</div>
|
|
379
|
+
</form>
|
|
380
|
+
</dialog>
|
|
246
381
|
|
|
247
382
|
<!-- Shared room workspace. -->
|
|
248
383
|
<section id="chatView" class="view" hidden>
|
|
@@ -355,7 +490,7 @@
|
|
|
355
490
|
</footer>
|
|
356
491
|
</form>
|
|
357
492
|
</dialog>
|
|
358
|
-
<dialog id="filesDialog" class="admin-dialog files-dialog" aria-labelledby="filesHeading">
|
|
493
|
+
<dialog id="filesDialog" class="admin-dialog files-dialog pane-surface" aria-labelledby="filesHeading">
|
|
359
494
|
<header class="files-head">
|
|
360
495
|
<div class="files-heading">
|
|
361
496
|
<p class="files-eyebrow" data-i18n="filesEyebrow">Room files</p>
|
|
@@ -383,7 +518,7 @@
|
|
|
383
518
|
<p class="hint files-hint" data-i18n="filesHint">Preview images, audio, and video. Download any file.</p>
|
|
384
519
|
</footer>
|
|
385
520
|
</dialog>
|
|
386
|
-
<dialog id="tasksDialog" class="admin-dialog tasks-dialog" aria-labelledby="tasksHeading">
|
|
521
|
+
<dialog id="tasksDialog" class="admin-dialog tasks-dialog pane-surface" aria-labelledby="tasksHeading">
|
|
387
522
|
<header class="tasks-head">
|
|
388
523
|
<div class="tasks-heading">
|
|
389
524
|
<p class="tasks-eyebrow"><span data-i18n="tasksEyebrow">Room tasks</span><span id="tasksRoomName" class="tasks-room-name"></span></p>
|
|
@@ -417,6 +552,7 @@
|
|
|
417
552
|
<button id="btnRetryTasks" class="btn ghost small" type="button" data-i18n="retry">Retry</button>
|
|
418
553
|
</div>
|
|
419
554
|
<div class="tasks-scroll">
|
|
555
|
+
<p id="tasksLimitNotice" class="tasks-limit-notice" role="status" hidden></p>
|
|
420
556
|
<details id="taskCreateDetails" class="task-create">
|
|
421
557
|
<summary class="task-create-summary"><span data-i18n="tasksCreate">Add task</span></summary>
|
|
422
558
|
<form id="taskCreateForm" class="task-create-form" novalidate>
|
|
@@ -459,6 +595,46 @@
|
|
|
459
595
|
<p id="tasksEmpty" class="hint tasks-empty" hidden></p>
|
|
460
596
|
</div>
|
|
461
597
|
</dialog>
|
|
598
|
+
<dialog id="announcementsDialog" class="admin-dialog announcements-dialog pane-surface" aria-labelledby="announcementHeading">
|
|
599
|
+
<header class="admin-dialog-head announcements-dialog-head">
|
|
600
|
+
<h2 id="announcementHeading" tabindex="-1" data-i18n="announcements">Announcements</h2>
|
|
601
|
+
<div class="admin-dialog-actions">
|
|
602
|
+
<button type="button" id="btnNewAnnouncement" class="btn primary small" aria-haspopup="dialog" data-i18n="announcementNew">New announcement</button>
|
|
603
|
+
<button type="button" id="btnRefreshAnnouncements" class="question-refresh" data-i18n="refreshQuestions">Refresh</button>
|
|
604
|
+
<button id="btnCloseAnnouncements" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button>
|
|
605
|
+
</div>
|
|
606
|
+
</header>
|
|
607
|
+
<div class="announcements-body">
|
|
608
|
+
<p id="announcementStatus" class="hint" role="status" aria-live="polite"></p>
|
|
609
|
+
<ul id="announcementList" class="announcement-list" aria-label="Announcements" data-i18n-aria-label="announcements"></ul>
|
|
610
|
+
</div>
|
|
611
|
+
</dialog>
|
|
612
|
+
<dialog id="remindersDialog" class="admin-dialog reminders-dialog pane-surface" aria-labelledby="reminderHeading">
|
|
613
|
+
<header class="admin-dialog-head reminders-dialog-head">
|
|
614
|
+
<h2 id="reminderHeading" tabindex="-1" data-i18n="reminders">Reminders</h2>
|
|
615
|
+
<div class="admin-dialog-actions">
|
|
616
|
+
<button type="button" id="btnNewReminder" class="btn primary small" data-i18n="reminderCreate">Create reminder</button>
|
|
617
|
+
<button type="button" id="btnRefreshReminders" class="question-refresh" data-i18n="refreshQuestions">Refresh</button>
|
|
618
|
+
<button id="btnCloseReminders" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button>
|
|
619
|
+
</div>
|
|
620
|
+
</header>
|
|
621
|
+
<div class="reminders-body">
|
|
622
|
+
<p id="reminderStatus" class="hint" role="status" aria-live="polite"></p>
|
|
623
|
+
<ul id="reminderList" class="reminder-list"></ul>
|
|
624
|
+
</div>
|
|
625
|
+
</dialog>
|
|
626
|
+
<dialog id="taskEditDialog" class="admin-dialog task-edit-dialog" aria-labelledby="taskEditHeading">
|
|
627
|
+
<header class="admin-dialog-head">
|
|
628
|
+
<h2 id="taskEditHeading" data-i18n="tasksEditHeading">Edit task</h2>
|
|
629
|
+
<div class="admin-dialog-actions">
|
|
630
|
+
<button id="btnCloseTaskEdit" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button>
|
|
631
|
+
</div>
|
|
632
|
+
</header>
|
|
633
|
+
<div class="task-edit-body">
|
|
634
|
+
<p id="taskEditError" class="alert task-edit-error" role="alert" hidden><span id="taskEditErrorText"></span></p>
|
|
635
|
+
<div id="taskEditFormHost"></div>
|
|
636
|
+
</div>
|
|
637
|
+
</dialog>
|
|
462
638
|
<dialog id="reminderDialog" class="admin-dialog reminder-dialog" aria-labelledby="reminderDialogHeading">
|
|
463
639
|
<header class="admin-dialog-head"><h2 id="reminderDialogHeading" data-i18n="reminderCreate">Create reminder</h2><div class="admin-dialog-actions"><button id="btnCloseReminder" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button></div></header>
|
|
464
640
|
<form id="reminderForm" class="admin-guide reminder-form">
|
|
@@ -508,13 +684,6 @@
|
|
|
508
684
|
<div id="questionReply" class="question-reply" hidden></div>
|
|
509
685
|
</section>
|
|
510
686
|
</div>
|
|
511
|
-
<div class="anchor">
|
|
512
|
-
<button class="chip" type="button" id="btnReminders" aria-haspopup="true" aria-expanded="false" aria-controls="reminderPanel"><svg class="fluent-icon action-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-alert-24"></use></svg><span class="action-label" data-i18n="reminders">Reminders</span></button>
|
|
513
|
-
<section class="panel reminder-panel" id="reminderPanel" aria-labelledby="reminderHeading" hidden>
|
|
514
|
-
<div class="announcement-head"><h3 id="reminderHeading" tabindex="-1" data-i18n="reminders">Reminders</h3><div class="reminder-tools"><button type="button" id="btnNewReminder" class="btn primary small" data-i18n="reminderCreate">Create reminder</button><button type="button" id="btnRefreshReminders" class="question-refresh" data-i18n="refreshQuestions">Refresh</button></div></div>
|
|
515
|
-
<p id="reminderStatus" class="hint" role="status" aria-live="polite"></p><ul id="reminderList" class="reminder-list"></ul>
|
|
516
|
-
</section>
|
|
517
|
-
</div>
|
|
518
687
|
<div class="anchor">
|
|
519
688
|
<button class="chip" type="button" id="btnMembers" aria-label="Members" data-i18n-aria-label="members" aria-haspopup="true" aria-expanded="false"><svg class="fluent-icon action-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-people-24"></use></svg><span class="action-label" data-i18n="members">Members</span><span id="joinRequestBadge" class="question-badge join-request-badge" aria-hidden="true" hidden><span id="joinRequestBadgeCount"></span></span></button>
|
|
520
689
|
<div class="panel" id="memberPanel" hidden>
|
|
@@ -536,18 +705,14 @@
|
|
|
536
705
|
<div class="anchor room-options-anchor">
|
|
537
706
|
<button class="chip" type="button" id="btnRoomOptions" aria-haspopup="true" aria-expanded="false" aria-controls="roomOptions"><svg class="fluent-icon action-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-more_horizontal-24"></use></svg><span class="action-label" data-i18n="roomOptions">Options</span></button>
|
|
538
707
|
<div class="panel room-options-panel" id="roomOptions" hidden>
|
|
539
|
-
<button class="menu-action" type="button" id="btnAnnouncements" aria-controls="
|
|
540
|
-
<button class="menu-action files-menu-action" type="button" id="btnFiles"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-folder-24"></use></svg><span data-i18n="filesTitle">Files</span></button>
|
|
541
|
-
<button class="menu-action" type="button" id="btnTasks"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-checkmark-24"></use></svg><span data-i18n="tasksTitle">Tasks</span></button>
|
|
708
|
+
<button class="menu-action" type="button" id="btnAnnouncements" aria-haspopup="dialog" aria-controls="announcementsDialog"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-megaphone-24"></use></svg><span data-i18n="announcements">Announcements</span></button>
|
|
709
|
+
<button class="menu-action files-menu-action" type="button" id="btnFiles" aria-haspopup="dialog" aria-controls="filesDialog"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-folder-24"></use></svg><span data-i18n="filesTitle">Files</span></button>
|
|
710
|
+
<button class="menu-action" type="button" id="btnTasks" aria-haspopup="dialog" aria-controls="tasksDialog"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-checkmark-24"></use></svg><span data-i18n="tasksTitle">Tasks</span></button>
|
|
711
|
+
<button class="menu-action" type="button" id="btnReminders" aria-haspopup="dialog" aria-controls="remindersDialog"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-alert-24"></use></svg><span data-i18n="reminders">Reminders</span></button>
|
|
542
712
|
<button class="menu-action" type="button" id="btnEditRoom"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-edit-24"></use></svg><span data-i18n="editRoom">Edit room</span></button>
|
|
543
713
|
<button class="menu-action" type="button" id="btnLeave"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-arrow_exit-24"></use></svg><span data-i18n="leave">Leave room</span></button>
|
|
544
714
|
<button class="menu-action danger-text" type="button" id="btnDeleteRoom"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-delete-24"></use></svg><span data-i18n="deleteRoom">Delete room</span></button>
|
|
545
715
|
</div>
|
|
546
|
-
<section class="panel announcement-panel" id="announcementPanel" aria-labelledby="announcementHeading" hidden>
|
|
547
|
-
<div class="announcement-head"><h3 id="announcementHeading" tabindex="-1" data-i18n="announcements">Announcements</h3><div class="announcement-tools"><button type="button" id="btnNewAnnouncement" class="btn primary small" aria-haspopup="dialog" data-i18n="announcementNew">New announcement</button><button type="button" id="btnRefreshAnnouncements" class="question-refresh" data-i18n="refreshQuestions">Refresh</button></div></div>
|
|
548
|
-
<p id="announcementStatus" class="hint" role="status" aria-live="polite"></p>
|
|
549
|
-
<ul id="announcementList" class="announcement-list" aria-label="Announcements" data-i18n-aria-label="announcements"></ul>
|
|
550
|
-
</section>
|
|
551
716
|
</div>
|
|
552
717
|
</div>
|
|
553
718
|
</header>
|
|
@@ -615,7 +780,8 @@
|
|
|
615
780
|
<p class="doc-preview-meta"><span id="docPreviewSize"></span><span id="docPreviewLanguage" class="doc-preview-language" hidden></span><span id="docPreviewStatus" role="status" aria-live="polite"></span></p>
|
|
616
781
|
</div>
|
|
617
782
|
<div class="doc-preview-actions">
|
|
618
|
-
<button id="
|
|
783
|
+
<button id="btnDocPreviewFullscreen" class="btn ghost small doc-preview-fullscreen-toggle" type="button" aria-label="Full screen" title="Full screen" data-i18n-aria-label="docPreviewFullscreen" data-i18n-title="docPreviewFullscreen"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-arrow_maximize-24"></use></svg></button>
|
|
784
|
+
<button id="btnDocPreviewDownload" class="btn ghost small doc-preview-download" type="button" aria-label="Download" data-i18n-aria-label="resourceDownload"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-arrow_download-24"></use></svg></button>
|
|
619
785
|
<button id="btnCloseDocPreview" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button>
|
|
620
786
|
</div>
|
|
621
787
|
</header>
|
|
@@ -727,7 +893,7 @@
|
|
|
727
893
|
<section class="keys-section">
|
|
728
894
|
<h3 data-i18n="shortcutsSearch">Search and commands</h3>
|
|
729
895
|
<ul class="keys-list">
|
|
730
|
-
<li><span class="keys-combo"><kbd class="keys-key shortcut-mod">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">Space</kbd></span><span class="keys-sep">/</span><span class="keys-combo"><kbd class="keys-key">Ctrl</kbd><span class="keys-sep">+</span><kbd class="keys-key">P</kbd></span><span data-i18n="shortcutsOpenPalette">Open search and commands</span></li>
|
|
896
|
+
<li><span class="keys-group"><span class="keys-combo"><kbd class="keys-key shortcut-mod">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">Space</kbd></span><span class="keys-sep">/</span><span class="keys-combo"><kbd class="keys-key">Ctrl</kbd><span class="keys-sep">+</span><kbd class="keys-key">P</kbd></span></span><span data-i18n="shortcutsOpenPalette">Open search and commands</span></li>
|
|
731
897
|
</ul>
|
|
732
898
|
</section>
|
|
733
899
|
<section class="keys-section">
|
package/server/http-server.ts
CHANGED
|
@@ -1,182 +1,3 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
import { Buffer } from "node:buffer";
|
|
5
|
-
import { Readable } from "node:stream";
|
|
6
|
-
import { pipeline } from "node:stream/promises";
|
|
7
|
-
|
|
8
|
-
export type ServerOptions = {
|
|
9
|
-
hostname: string;
|
|
10
|
-
port: number;
|
|
11
|
-
fetch(request: Request): Response | Promise<Response>;
|
|
12
|
-
maxRequestBodySize?: number;
|
|
13
|
-
idleTimeout?: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type StartedServer = {
|
|
17
|
-
port: number;
|
|
18
|
-
close(): Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const hopByHop = new Set(["connection", "keep-alive", "proxy-connection", "te", "trailer", "transfer-encoding", "upgrade"]);
|
|
22
|
-
|
|
23
|
-
function requestURL(req: IncomingMessage, hostname: string, port: number): string {
|
|
24
|
-
const path = req.url ?? "/";
|
|
25
|
-
if (/^https?:\/\//i.test(path)) return path;
|
|
26
|
-
const host = req.headers.host ?? (hostname.includes(":") ? `[${hostname}]:${port}` : `${hostname}:${port}`);
|
|
27
|
-
return `http://${host}${path}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function requestHeaders(req: IncomingMessage): Headers {
|
|
31
|
-
const headers = new Headers();
|
|
32
|
-
const raw = req.rawHeaders;
|
|
33
|
-
for (let i = 0; i + 1 < raw.length; i += 2) {
|
|
34
|
-
const name = raw[i]!.toLowerCase();
|
|
35
|
-
if (!hopByHop.has(name)) headers.append(name, raw[i + 1]!);
|
|
36
|
-
}
|
|
37
|
-
return headers;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function sendJson(res: ServerResponse, status: number, message: string): void {
|
|
41
|
-
if (res.headersSent || res.destroyed) {
|
|
42
|
-
res.destroy();
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const body = JSON.stringify({ error: message });
|
|
46
|
-
res.writeHead(status, { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) });
|
|
47
|
-
res.end(body);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// The response must reach the client before the unread request body is
|
|
51
|
-
// discarded, so destroy only after the 413 has been flushed to the socket.
|
|
52
|
-
function rejectTooLarge(req: IncomingMessage, res: ServerResponse): void {
|
|
53
|
-
res.setHeader("Connection", "close");
|
|
54
|
-
res.once("finish", () => req.destroy());
|
|
55
|
-
sendJson(res, 413, "request body too large");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function discardBody(response: Response): Promise<void> {
|
|
59
|
-
try { await response.body?.cancel(); } catch { /* A locked or already-consumed body needs no cleanup. */ }
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function writeResponse(res: ServerResponse, response: Response, method: string): Promise<void> {
|
|
63
|
-
const headers: Record<string, string | string[]> = {};
|
|
64
|
-
response.headers.forEach((value, name) => {
|
|
65
|
-
if (name !== "set-cookie") headers[name] = value;
|
|
66
|
-
});
|
|
67
|
-
const cookies = response.headers.getSetCookie?.() ?? [];
|
|
68
|
-
if (cookies.length) headers["set-cookie"] = cookies;
|
|
69
|
-
res.writeHead(response.status, headers);
|
|
70
|
-
if (method === "HEAD" || response.status === 204 || response.status === 304 || !response.body) {
|
|
71
|
-
await discardBody(response);
|
|
72
|
-
res.end();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// pipeline destroys the web stream (and so cancels the source) when the
|
|
76
|
-
// client disconnects, which is the abort propagation we need here.
|
|
77
|
-
await pipeline(Readable.fromWeb(response.body as unknown as import("node:stream/web").ReadableStream), res);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function serve(
|
|
81
|
-
req: IncomingMessage,
|
|
82
|
-
res: ServerResponse,
|
|
83
|
-
hostname: string,
|
|
84
|
-
port: number,
|
|
85
|
-
handler: ServerOptions["fetch"],
|
|
86
|
-
maxBody: number,
|
|
87
|
-
): Promise<void> {
|
|
88
|
-
const abort = new AbortController();
|
|
89
|
-
const onAborted = () => abort.abort();
|
|
90
|
-
req.once("aborted", onAborted);
|
|
91
|
-
req.once("error", onAborted);
|
|
92
|
-
const method = req.method ?? "GET";
|
|
93
|
-
let tooLarge = false;
|
|
94
|
-
let body: ReadableStream<Uint8Array> | undefined;
|
|
95
|
-
try {
|
|
96
|
-
const declared = Number(req.headers["content-length"]);
|
|
97
|
-
if (Number.isFinite(declared) && declared > maxBody) {
|
|
98
|
-
rejectTooLarge(req, res);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (method !== "GET" && method !== "HEAD") {
|
|
102
|
-
let received = 0;
|
|
103
|
-
body = (Readable.toWeb(req) as unknown as ReadableStream<Uint8Array>).pipeThrough(new TransformStream<Uint8Array, Uint8Array>({
|
|
104
|
-
transform(chunk, controller) {
|
|
105
|
-
received += chunk.byteLength;
|
|
106
|
-
if (received > maxBody) {
|
|
107
|
-
tooLarge = true;
|
|
108
|
-
controller.error(new Error("request body too large"));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
controller.enqueue(chunk);
|
|
112
|
-
},
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
const request = new Request(requestURL(req, hostname, port), {
|
|
116
|
-
method,
|
|
117
|
-
headers: requestHeaders(req),
|
|
118
|
-
body,
|
|
119
|
-
signal: abort.signal,
|
|
120
|
-
...(body ? { duplex: "half" } : {}),
|
|
121
|
-
} as RequestInit);
|
|
122
|
-
const response = await handler(request);
|
|
123
|
-
if (tooLarge) {
|
|
124
|
-
await discardBody(response);
|
|
125
|
-
rejectTooLarge(req, res);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
await writeResponse(res, response, method);
|
|
129
|
-
} catch {
|
|
130
|
-
if (tooLarge) {
|
|
131
|
-
rejectTooLarge(req, res);
|
|
132
|
-
} else if (!abort.signal.aborted && !res.headersSent) {
|
|
133
|
-
sendJson(res, 500, "internal server error");
|
|
134
|
-
} else if (!res.destroyed) {
|
|
135
|
-
res.destroy();
|
|
136
|
-
}
|
|
137
|
-
} finally {
|
|
138
|
-
req.off("aborted", onAborted);
|
|
139
|
-
req.off("error", onAborted);
|
|
140
|
-
// A handler may answer without reading the request (for example a 401);
|
|
141
|
-
// cancel the stream so the remaining body is not buffered in memory.
|
|
142
|
-
if (body) void body.cancel().catch(() => {});
|
|
143
|
-
else if (!req.readableEnded) req.resume();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export async function startServer(options: ServerOptions): Promise<StartedServer> {
|
|
148
|
-
const maxBody = options.maxRequestBodySize ?? Infinity;
|
|
149
|
-
const server = createServer((req, res) => {
|
|
150
|
-
void serve(req, res, options.hostname, options.port, options.fetch, maxBody);
|
|
151
|
-
});
|
|
152
|
-
// Bun's idleTimeout is socket inactivity, not a total request deadline: a
|
|
153
|
-
// slow upload must not be cut by either Node timer.
|
|
154
|
-
if (options.idleTimeout && options.idleTimeout > 0) server.timeout = options.idleTimeout * 1000;
|
|
155
|
-
server.requestTimeout = 0;
|
|
156
|
-
await new Promise<void>((resolve, reject) => {
|
|
157
|
-
const onError = (error: Error) => reject(error);
|
|
158
|
-
server.once("error", onError);
|
|
159
|
-
server.listen(options.port, options.hostname, () => {
|
|
160
|
-
server.off("error", onError);
|
|
161
|
-
resolve();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
const address = server.address();
|
|
165
|
-
const port = typeof address === "object" && address ? address.port : options.port;
|
|
166
|
-
let closing: Promise<void> | undefined;
|
|
167
|
-
return {
|
|
168
|
-
port,
|
|
169
|
-
close() {
|
|
170
|
-
closing ??= new Promise<void>((resolve) => {
|
|
171
|
-
if (!server.listening) {
|
|
172
|
-
resolve();
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
server.close(() => resolve());
|
|
176
|
-
server.closeIdleConnections();
|
|
177
|
-
server.closeAllConnections();
|
|
178
|
-
});
|
|
179
|
-
return closing;
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
}
|
|
1
|
+
// Compatibility shim: the HTTP adapter lives in src/platform so src code never
|
|
2
|
+
// imports from server/. Existing server-side imports may keep this path.
|
|
3
|
+
export * from "../src/platform/http-server.ts";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { stat } from "node:fs/promises";
|
|
3
|
-
import { Readable } from "node:stream";
|
|
4
|
-
import { deleteResource, findResource, listRoomResources, maxResourceBytes, resourcePath, uploadResource, type Resource } from "../src/rooms/resources.ts";
|
|
1
|
+
import { deleteResource, findResource, listRoomResources, maxResourceBytes, openResource, uploadResource, type Resource } from "../src/rooms/resources.ts";
|
|
5
2
|
import { readState } from "../src/state/store.ts";
|
|
6
3
|
import { isRoomAdmin, isUser } from "./room-owner.ts";
|
|
7
4
|
|
|
@@ -77,23 +74,26 @@ export async function resourceRoutes(req: Request, url: URL): Promise<Response |
|
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
async function content(req: Request, resource: Resource): Promise<Response> {
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
// The database row is authoritative for size and Range validation; storage
|
|
78
|
+
// streams exactly the validated window.
|
|
79
|
+
const size = resource.size;
|
|
82
80
|
const range = req.headers.get("range");
|
|
83
|
-
if (range &&
|
|
84
|
-
if (
|
|
85
|
-
let start = 0, end =
|
|
81
|
+
if (range && size === 0) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": "bytes */0" } });
|
|
82
|
+
if (size === 0) return new Response(null, { headers: { ...safeHeaders, "Content-Type": resource.mimeType, "Content-Disposition": contentDisposition(resource.name, false), "Content-Length": "0" } });
|
|
83
|
+
let start = 0, end = size - 1, status = 200;
|
|
86
84
|
if (range) {
|
|
87
85
|
const match = range.match(/^bytes=(\d*)-(\d*)$/);
|
|
88
|
-
if (!match || (!match[1] && !match[2])) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${
|
|
89
|
-
if (!match[1]) { const suffix = Number(match[2]); if (!Number.isSafeInteger(suffix) || suffix <= 0) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${
|
|
90
|
-
else { start = Number(match[1]); if (!Number.isSafeInteger(start)) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${
|
|
91
|
-
if (match[1] && match[2]) { const requestedEnd = Number(match[2]); if (!Number.isSafeInteger(requestedEnd)) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${
|
|
92
|
-
if (start >=
|
|
86
|
+
if (!match || (!match[1] && !match[2])) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${size}` } });
|
|
87
|
+
if (!match[1]) { const suffix = Number(match[2]); if (!Number.isSafeInteger(suffix) || suffix <= 0) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${size}` } }); start = Math.max(0, size - suffix); }
|
|
88
|
+
else { start = Number(match[1]); if (!Number.isSafeInteger(start)) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${size}` } }); }
|
|
89
|
+
if (match[1] && match[2]) { const requestedEnd = Number(match[2]); if (!Number.isSafeInteger(requestedEnd)) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${size}` } }); end = Math.min(requestedEnd, end); }
|
|
90
|
+
if (start >= size || end < start) return new Response(null, { status: 416, headers: { ...safeHeaders, "Content-Range": `bytes */${size}` } });
|
|
93
91
|
status = 206;
|
|
94
92
|
}
|
|
93
|
+
const opened = await openResource(resource, status === 206 ? start : undefined, status === 206 ? end : undefined);
|
|
94
|
+
if (!opened) return json({ error: "resource not found" }, 404);
|
|
95
95
|
const inline = /^(image\/(png|jpeg|gif|webp)|audio\/(mpeg|ogg|wav)|video\/(mp4|webm))$/.test(resource.mimeType);
|
|
96
96
|
const headers = new Headers({ ...safeHeaders, "Content-Type": resource.mimeType, "Content-Disposition": contentDisposition(resource.name, inline), "Content-Length": String(end - start + 1) });
|
|
97
|
-
if (status === 206) headers.set("Content-Range", `bytes ${start}-${end}/${
|
|
98
|
-
return new Response(
|
|
97
|
+
if (status === 206) headers.set("Content-Range", `bytes ${start}-${end}/${size}`);
|
|
98
|
+
return new Response(opened.stream, { status, headers });
|
|
99
99
|
}
|