@celljs/ta-relay 4.24.0 → 4.25.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/README.en.md +6 -6
- package/README.md +6 -6
- package/esm/common/index.d.ts +5 -0
- package/esm/common/index.js +5 -0
- package/esm/common/relay-accounts.d.ts +2 -0
- package/esm/common/relay-accounts.js +21 -0
- package/esm/common/relay-blobs.d.ts +2 -0
- package/esm/common/relay-blobs.js +1 -0
- package/esm/common/relay-content-origin.d.ts +44 -0
- package/esm/common/relay-content-origin.js +67 -0
- package/esm/common/relay-content.d.ts +2 -0
- package/esm/common/relay-content.js +12 -2
- package/esm/common/relay-friends.js +1 -1
- package/esm/common/relay-hub-util.js +1 -1
- package/esm/common/relay-hub.js +4 -4
- package/esm/common/relay-hubs-admins.js +3 -3
- package/esm/common/relay-hubs.js +5 -5
- package/esm/common/relay-info.d.ts +11 -1
- package/esm/common/relay-info.js +20 -2
- package/esm/common/relay-moderation-client.d.ts +32 -0
- package/esm/common/relay-moderation-client.js +51 -0
- package/esm/common/relay-moderation-door.d.ts +24 -0
- package/esm/common/relay-moderation-door.js +48 -0
- package/esm/common/relay-moderation-policy.d.ts +78 -0
- package/esm/common/relay-moderation-policy.js +59 -0
- package/esm/common/relay-moderation.d.ts +165 -0
- package/esm/common/relay-moderation.js +464 -0
- package/esm/common/relay-protocol.d.ts +5 -1
- package/esm/common/relay-protocol.js +4 -0
- package/esm/common/relay-room-app.d.ts +5 -0
- package/esm/common/relay-room-app.js +8 -0
- package/esm/node/relay-chat-files.js +1 -1
- package/esm/node/relay-server-accounts.d.ts +2 -0
- package/esm/node/relay-server-accounts.js +4 -0
- package/esm/node/relay-server-gate.d.ts +39 -0
- package/esm/node/relay-server-gate.js +124 -0
- package/esm/node/relay-server-web.d.ts +5 -0
- package/esm/node/relay-server-web.js +28 -0
- package/esm/node/relay-server.d.ts +9 -2
- package/esm/node/relay-server.js +40 -47
- package/esm/node/relay-store.d.ts +4 -0
- package/esm/node/relay-store.js +2 -0
- package/esm/viewer/viewer-i18n.d.ts +25 -0
- package/esm/viewer/viewer-i18n.js +132 -32
- package/esm/viewer/viewer-style.d.ts +1 -1
- package/esm/viewer/viewer-style.js +13 -0
- package/esm/viewer/viewer.js +127 -6
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +5 -0
- package/lib/common/relay-accounts.d.ts +2 -0
- package/lib/common/relay-accounts.js +21 -0
- package/lib/common/relay-blobs.d.ts +2 -0
- package/lib/common/relay-blobs.js +1 -0
- package/lib/common/relay-content-origin.d.ts +45 -0
- package/lib/common/relay-content-origin.js +71 -0
- package/lib/common/relay-content.d.ts +2 -0
- package/lib/common/relay-content.js +12 -2
- package/lib/common/relay-friends.js +1 -1
- package/lib/common/relay-hub-util.js +1 -1
- package/lib/common/relay-hub.js +4 -4
- package/lib/common/relay-hubs-admins.js +3 -3
- package/lib/common/relay-hubs.js +5 -5
- package/lib/common/relay-info.d.ts +11 -1
- package/lib/common/relay-info.js +20 -2
- package/lib/common/relay-moderation-client.d.ts +33 -0
- package/lib/common/relay-moderation-client.js +54 -0
- package/lib/common/relay-moderation-door.d.ts +25 -0
- package/lib/common/relay-moderation-door.js +51 -0
- package/lib/common/relay-moderation-policy.d.ts +79 -0
- package/lib/common/relay-moderation-policy.js +62 -0
- package/lib/common/relay-moderation.d.ts +166 -0
- package/lib/common/relay-moderation.js +468 -0
- package/lib/common/relay-protocol.d.ts +5 -1
- package/lib/common/relay-protocol.js +4 -0
- package/lib/common/relay-room-app.d.ts +5 -0
- package/lib/common/relay-room-app.js +8 -0
- package/lib/node/relay-chat-files.js +1 -1
- package/lib/node/relay-server-accounts.d.ts +2 -0
- package/lib/node/relay-server-accounts.js +4 -0
- package/lib/node/relay-server-gate.d.ts +40 -0
- package/lib/node/relay-server-gate.js +128 -0
- package/lib/node/relay-server-web.d.ts +6 -0
- package/lib/node/relay-server-web.js +31 -0
- package/lib/node/relay-server.d.ts +9 -2
- package/lib/node/relay-server.js +39 -46
- package/lib/node/relay-store.d.ts +4 -0
- package/lib/node/relay-store.js +2 -0
- package/lib/viewer/viewer-i18n.d.ts +25 -0
- package/lib/viewer/viewer-i18n.js +132 -32
- package/lib/viewer/viewer-style.d.ts +1 -1
- package/lib/viewer/viewer-style.js +13 -0
- package/lib/viewer/viewer.js +127 -6
- package/package.json +3 -3
- package/viewer/join.html +5 -5
- package/viewer/page.html +25 -12
- package/viewer/room.html +4 -4
|
@@ -12,6 +12,11 @@ export declare const ROOM_APP_STALE_MS: number;
|
|
|
12
12
|
export declare namespace RoomAppUtil {
|
|
13
13
|
/** What others wrote, which a model reads inside tags: no tags of its own. */
|
|
14
14
|
function quote(text: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* What others wrote, as the words of a message that the user reads too, drawn as Markdown: quoted, and a picture it
|
|
17
|
+
* names (``) shown as written, never loaded from where they chose.
|
|
18
|
+
*/
|
|
19
|
+
function shown(text: string): string;
|
|
15
20
|
/**
|
|
16
21
|
* What others said to the room since `since`: not by the user, not too long ago, not to someone in particular (@ a
|
|
17
22
|
* person, a double or an agent: theirs to answer), not said by a double or an agent.
|
|
@@ -20,6 +20,14 @@ var RoomAppUtil;
|
|
|
20
20
|
return text.replace(/</g, '<').replace(/>/g, '>');
|
|
21
21
|
}
|
|
22
22
|
RoomAppUtil.quote = quote;
|
|
23
|
+
/**
|
|
24
|
+
* What others wrote, as the words of a message that the user reads too, drawn as Markdown: quoted, and a picture it
|
|
25
|
+
* names (``) shown as written, never loaded from where they chose.
|
|
26
|
+
*/
|
|
27
|
+
function shown(text) {
|
|
28
|
+
return quote(text).replace(/!\[/g, '!\\[');
|
|
29
|
+
}
|
|
30
|
+
RoomAppUtil.shown = shown;
|
|
23
31
|
/**
|
|
24
32
|
* What others said to the room since `since`: not by the user, not too long ago, not to someone in particular (@ a
|
|
25
33
|
* person, a double or an agent: theirs to answer), not said by a double or an agent.
|
|
@@ -10,6 +10,8 @@ export declare class RelayServerAccounts {
|
|
|
10
10
|
constructor(data: string | undefined, options?: Pick<RelayAccountsOptions, 'authenticate' | 'issue'> & {
|
|
11
11
|
providers?: RelayAccountProvider[];
|
|
12
12
|
});
|
|
13
|
+
/** The account of a bearer token (RelayAccounts.whoIs). */
|
|
14
|
+
whoIs(authorization: string): Promise<import(".").AccountName | undefined>;
|
|
13
15
|
/** Answers a request of RELAY_ACCOUNT_PATH; never throws, an unhandled rejection would end the relay. */
|
|
14
16
|
serve(request: IncomingMessage, response: ServerResponse): void;
|
|
15
17
|
protected answer(request: IncomingMessage, response: ServerResponse): Promise<void>;
|
|
@@ -20,6 +20,10 @@ class RelayServerAccounts {
|
|
|
20
20
|
const providers = (_a = options.providers) !== null && _a !== void 0 ? _a : (options.authenticate ? [] : [new relay_accounts_1.RelayGitHubAccounts()]);
|
|
21
21
|
this.accounts = new relay_accounts_1.RelayAccounts({ book: account => books.book(account), providers, authenticate: options.authenticate, issue: options.issue });
|
|
22
22
|
}
|
|
23
|
+
/** The account of a bearer token (RelayAccounts.whoIs). */
|
|
24
|
+
whoIs(authorization) {
|
|
25
|
+
return this.accounts.whoIs(authorization);
|
|
26
|
+
}
|
|
23
27
|
/** Answers a request of RELAY_ACCOUNT_PATH; never throws, an unhandled rejection would end the relay. */
|
|
24
28
|
serve(request, response) {
|
|
25
29
|
this.answer(request, response).catch(() => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { type RelayAccountWho, RelayModeration, type RelayModerationStorage } from '../common/relay-moderation';
|
|
3
|
+
export interface RelayServerGateOptions {
|
|
4
|
+
content?: string;
|
|
5
|
+
adminToken?: string;
|
|
6
|
+
/** The account of a bearer token (the account service of the relay). */
|
|
7
|
+
whoIs(authorization: string): Promise<RelayAccountWho | undefined>;
|
|
8
|
+
/** Whether this secret is the one a computer holds its id with. */
|
|
9
|
+
holds(host: string, secret: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* What `ta relay` answers before anything else (docs/design/ta-link.md 2.10): by the domain a request came to, its own
|
|
13
|
+
* or that of content; the reports of links and the operator's blocks.
|
|
14
|
+
*/
|
|
15
|
+
export declare class RelayServerGate {
|
|
16
|
+
protected readonly options: RelayServerGateOptions;
|
|
17
|
+
protected readonly moderation: RelayModeration;
|
|
18
|
+
constructor(storage: RelayModerationStorage, options: RelayServerGateOptions);
|
|
19
|
+
/** The address a request reached the relay at, by its Host. */
|
|
20
|
+
static urlOf(request: IncomingMessage): URL;
|
|
21
|
+
/** Whether it answered the request: not on this domain, sent to the domain of content, a report, the operator's. */
|
|
22
|
+
answer(request: IncomingMessage, response: ServerResponse): boolean;
|
|
23
|
+
/** What the policy needs an account for, as /v1/info says it. */
|
|
24
|
+
needsAccount(): Promise<{
|
|
25
|
+
needsAccount?: string[];
|
|
26
|
+
}>;
|
|
27
|
+
/** Whether a WebSocket to this path has no place on the domain it came to. */
|
|
28
|
+
refuses(request: IncomingMessage): boolean;
|
|
29
|
+
static headersOf(request: IncomingMessage): Headers;
|
|
30
|
+
/** Why a viewer of a link of this host is refused (RelayModeration.viewer); the pages of the relay in a browser by their Origin. */
|
|
31
|
+
refusesViewer(request: IncomingMessage, host: string): Promise<number | undefined>;
|
|
32
|
+
/** Why a copy is not kept: where links need an account, the one who puts it names theirs (`x-ta-account`). */
|
|
33
|
+
refusesCopy(request: IncomingMessage): Promise<number | undefined>;
|
|
34
|
+
/** The status a copy is refused with: read, when its share is blocked (410); put, by none or a sanctioned account where links need one (451). */
|
|
35
|
+
refusesBlob(request: IncomingMessage, share: string): Promise<number | undefined>;
|
|
36
|
+
protected moderate(request: IncomingMessage, response: ServerResponse): Promise<void>;
|
|
37
|
+
/** The body of a request, or undefined past `max` bytes: the rest is read and dropped. */
|
|
38
|
+
static body(request: IncomingMessage, max: number): Promise<Buffer<ArrayBuffer> | undefined>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=relay-server-gate.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayServerGate = void 0;
|
|
4
|
+
const relay_content_origin_1 = require("../common/relay-content-origin");
|
|
5
|
+
const relay_moderation_1 = require("../common/relay-moderation");
|
|
6
|
+
const relay_moderation_door_1 = require("../common/relay-moderation-door");
|
|
7
|
+
const relay_spot_1 = require("../common/relay-spot");
|
|
8
|
+
/**
|
|
9
|
+
* What `ta relay` answers before anything else (docs/design/ta-link.md 2.10): by the domain a request came to, its own
|
|
10
|
+
* or that of content; the reports of links and the operator's blocks.
|
|
11
|
+
*/
|
|
12
|
+
class RelayServerGate {
|
|
13
|
+
constructor(storage, options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.moderation = new relay_moderation_1.RelayModeration(storage);
|
|
16
|
+
}
|
|
17
|
+
/** The address a request reached the relay at, by its Host. */
|
|
18
|
+
static urlOf(request) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
return new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', `http://${(_b = request.headers.host) !== null && _b !== void 0 ? _b : 'relay'}`);
|
|
21
|
+
}
|
|
22
|
+
/** Whether it answered the request: not on this domain, sent to the domain of content, a report, the operator's. */
|
|
23
|
+
answer(request, response) {
|
|
24
|
+
const url = RelayServerGate.urlOf(request);
|
|
25
|
+
const route = relay_content_origin_1.RelayContentOrigin.route(url, this.options.content);
|
|
26
|
+
if (route.kind === 'redirect') {
|
|
27
|
+
response.writeHead(308, { location: route.location }).end();
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (route.kind === 'refuse') {
|
|
31
|
+
response.writeHead(404, { 'content-type': 'text/plain' }).end('Not found.\n');
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (!relay_moderation_door_1.RelayModerationDoor.handles(url.pathname)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
this.moderate(request, response).catch(() => {
|
|
38
|
+
if (!response.headersSent) {
|
|
39
|
+
response.writeHead(400);
|
|
40
|
+
}
|
|
41
|
+
response.end();
|
|
42
|
+
});
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/** What the policy needs an account for, as /v1/info says it. */
|
|
46
|
+
async needsAccount() {
|
|
47
|
+
const needs = (await this.moderation.policy()).needsAccount;
|
|
48
|
+
return needs.length ? { needsAccount: needs } : {};
|
|
49
|
+
}
|
|
50
|
+
/** Whether a WebSocket to this path has no place on the domain it came to. */
|
|
51
|
+
refuses(request) {
|
|
52
|
+
return relay_content_origin_1.RelayContentOrigin.route(RelayServerGate.urlOf(request), this.options.content).kind === 'refuse';
|
|
53
|
+
}
|
|
54
|
+
static headersOf(request) {
|
|
55
|
+
const headers = new Headers();
|
|
56
|
+
for (const [name, value] of Object.entries(request.headers)) {
|
|
57
|
+
if (typeof value === 'string') {
|
|
58
|
+
headers.set(name, value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return headers;
|
|
62
|
+
}
|
|
63
|
+
/** Why a viewer of a link of this host is refused (RelayModeration.viewer); the pages of the relay in a browser by their Origin. */
|
|
64
|
+
refusesViewer(request, host) {
|
|
65
|
+
var _a;
|
|
66
|
+
const own = `http://${(_a = request.headers.host) !== null && _a !== void 0 ? _a : 'relay'}`;
|
|
67
|
+
const browser = relay_moderation_door_1.RelayModerationDoor.browser({ headers: RelayServerGate.headersOf(request) }, [this.options.content, own]);
|
|
68
|
+
return this.moderation.viewer(host, browser);
|
|
69
|
+
}
|
|
70
|
+
/** Why a copy is not kept: where links need an account, the one who puts it names theirs (`x-ta-account`). */
|
|
71
|
+
async refusesCopy(request) {
|
|
72
|
+
const header = request.headers['x-ta-account'];
|
|
73
|
+
const who = typeof header === 'string' ? await this.options.whoIs(header) : undefined;
|
|
74
|
+
return this.moderation.viewer('', true, who);
|
|
75
|
+
}
|
|
76
|
+
/** The status a copy is refused with: read, when its share is blocked (410); put, by none or a sanctioned account where links need one (451). */
|
|
77
|
+
async refusesBlob(request, share) {
|
|
78
|
+
if (request.method === 'GET') {
|
|
79
|
+
return (await this.moderation.blocked(undefined, share)) ? 410 : undefined;
|
|
80
|
+
}
|
|
81
|
+
return request.method === 'PUT' && (await this.refusesCopy(request)) ? 451 : undefined;
|
|
82
|
+
}
|
|
83
|
+
async moderate(request, response) {
|
|
84
|
+
var _a;
|
|
85
|
+
const body = await RelayServerGate.body(request, 16 * 1024);
|
|
86
|
+
if (!body) {
|
|
87
|
+
response.writeHead(413, { connection: 'close' }).end('Too large.\n');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const method = (_a = request.method) !== null && _a !== void 0 ? _a : 'GET';
|
|
91
|
+
const outer = new Request(`http://relay${request.url}`, {
|
|
92
|
+
method,
|
|
93
|
+
headers: RelayServerGate.headersOf(request),
|
|
94
|
+
body: method === 'GET' || method === 'HEAD' ? undefined : body,
|
|
95
|
+
});
|
|
96
|
+
const answer = await relay_moderation_door_1.RelayModerationDoor.handle(outer, relay_spot_1.RelaySpotTries.keyOf(request.socket.remoteAddress), {
|
|
97
|
+
whoIs: authorization => this.options.whoIs(authorization),
|
|
98
|
+
holds: async (host, secret) => this.options.holds(host, secret),
|
|
99
|
+
moderate: (inner, address, who) => this.moderation.handle(inner, address, this.options.adminToken || undefined, who),
|
|
100
|
+
});
|
|
101
|
+
response.writeHead(answer.status, Object.fromEntries(answer.headers));
|
|
102
|
+
response.end(Buffer.from(await answer.arrayBuffer()));
|
|
103
|
+
}
|
|
104
|
+
/** The body of a request, or undefined past `max` bytes: the rest is read and dropped. */
|
|
105
|
+
static body(request, max) {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
const chunks = [];
|
|
108
|
+
let size = 0;
|
|
109
|
+
request.on('data', (chunk) => {
|
|
110
|
+
if (size < 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
size += chunk.length;
|
|
114
|
+
if (size > max) {
|
|
115
|
+
size = -1;
|
|
116
|
+
chunks.length = 0;
|
|
117
|
+
resolve(undefined);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
chunks.push(chunk);
|
|
121
|
+
});
|
|
122
|
+
request.on('end', () => size >= 0 && resolve(Buffer.concat(chunks)));
|
|
123
|
+
request.on('error', reject);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.RelayServerGate = RelayServerGate;
|
|
128
|
+
//# sourceMappingURL=relay-server-gate.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ServerResponse } from 'node:http';
|
|
2
|
+
/** Ta's web page as `ta relay` serves it under RELAY_WEB_PATH, from a directory of its files. */
|
|
3
|
+
export declare namespace RelayServerWeb {
|
|
4
|
+
function serve(dir: string | undefined, path: string, response: ServerResponse): void;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=relay-server-web.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayServerWeb = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const relay_team_1 = require("../common/relay-team");
|
|
7
|
+
const relay_web_1 = require("../common/relay-web");
|
|
8
|
+
/** Ta's web page as `ta relay` serves it under RELAY_WEB_PATH, from a directory of its files. */
|
|
9
|
+
var RelayServerWeb;
|
|
10
|
+
(function (RelayServerWeb) {
|
|
11
|
+
function serve(dir, path, response) {
|
|
12
|
+
var _a;
|
|
13
|
+
if (path === relay_team_1.RELAY_WEB_PATH.slice(0, -1)) {
|
|
14
|
+
response.writeHead(308, { location: relay_team_1.RELAY_WEB_PATH });
|
|
15
|
+
response.end();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const file = relay_web_1.RelayWebUtil.file(path);
|
|
19
|
+
const full = file && dir ? (0, node_path_1.join)(dir, file) : undefined;
|
|
20
|
+
if (!file || !full || !((_a = (0, node_fs_1.statSync)(full, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile())) {
|
|
21
|
+
response.writeHead(404, { 'content-type': 'text/plain' });
|
|
22
|
+
response.end('Not found.\n');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const body = (0, node_fs_1.readFileSync)(full);
|
|
26
|
+
response.writeHead(200, relay_web_1.RelayWebUtil.headers(file));
|
|
27
|
+
response.end(file === 'index.html' ? relay_web_1.RelayWebUtil.index(body.toString('utf8')) : body);
|
|
28
|
+
}
|
|
29
|
+
RelayServerWeb.serve = serve;
|
|
30
|
+
})(RelayServerWeb || (exports.RelayServerWeb = RelayServerWeb = {}));
|
|
31
|
+
//# sourceMappingURL=relay-server-web.js.map
|
|
@@ -11,6 +11,7 @@ import { RelaySpot, type RelaySpotSocket, type RelaySpotWho } from '../common/re
|
|
|
11
11
|
import { FileRelayStorage } from './relay-file-storage';
|
|
12
12
|
import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage';
|
|
13
13
|
import { RelayServerAccounts } from './relay-server-accounts';
|
|
14
|
+
import { RelayServerGate } from './relay-server-gate';
|
|
14
15
|
export interface RelayServerOptions {
|
|
15
16
|
host?: string;
|
|
16
17
|
port?: number;
|
|
@@ -39,6 +40,13 @@ export interface RelayServerOptions {
|
|
|
39
40
|
* operator set it (`ta relay` reads TA_MEDIA_DAYS and TA_MEDIA_MAX_MB, a day by default, none with 0); none here unless given.
|
|
40
41
|
*/
|
|
41
42
|
media?: RelayMedia;
|
|
43
|
+
/**
|
|
44
|
+
* The domain links of content open at (RelayInfo.content, docs/design/ta-link.md 2.10), reaching this relay too
|
|
45
|
+
* (`TA_CONTENT_ORIGIN`); none: links open on its own.
|
|
46
|
+
*/
|
|
47
|
+
content?: string;
|
|
48
|
+
/** What the operator reads the reports and blocks with (RELAY_MODERATION_PATH, `TA_ADMIN_TOKEN`); none: no one. */
|
|
49
|
+
adminToken?: string;
|
|
42
50
|
}
|
|
43
51
|
interface Room {
|
|
44
52
|
secretHash: string;
|
|
@@ -84,6 +92,7 @@ export declare class RelayServer {
|
|
|
84
92
|
protected readonly spotAddresses: WeakMap<WebSocketConnection, string>;
|
|
85
93
|
protected server?: Server;
|
|
86
94
|
protected readonly accounts: RelayServerAccounts;
|
|
95
|
+
protected readonly gate: RelayServerGate;
|
|
87
96
|
constructor(options?: RelayServerOptions);
|
|
88
97
|
/** What it is part of, and whether it runs and can keep what it holds: for anyone, and the probes of a platform. */
|
|
89
98
|
protected describe(path: string, request: IncomingMessage, response: ServerResponse): void;
|
|
@@ -100,8 +109,6 @@ export declare class RelayServer {
|
|
|
100
109
|
};
|
|
101
110
|
protected claimsFile(): string;
|
|
102
111
|
protected saveClaims(): void;
|
|
103
|
-
/** The body of a request, or undefined past `max` bytes: the rest is read and dropped. */
|
|
104
|
-
protected static body(request: IncomingMessage, max: number): Promise<Buffer<ArrayBuffer> | undefined>;
|
|
105
112
|
protected upgrade(request: IncomingMessage, socket: Duplex, head: Buffer): void;
|
|
106
113
|
/** The first host to come with an id keeps it, for as long as the relay runs, or for good with `data`. */
|
|
107
114
|
protected openHost(id: string, secret: string, connection: WebSocketConnection): void;
|
package/lib/node/relay-server.js
CHANGED
|
@@ -15,10 +15,11 @@ const relay_protocol_1 = require("../common/relay-protocol");
|
|
|
15
15
|
const relay_room_1 = require("../common/relay-room");
|
|
16
16
|
const relay_spot_1 = require("../common/relay-spot");
|
|
17
17
|
const relay_team_1 = require("../common/relay-team");
|
|
18
|
-
const relay_web_1 = require("../common/relay-web");
|
|
19
18
|
const relay_file_storage_1 = require("./relay-file-storage");
|
|
20
19
|
const relay_memory_storage_1 = require("./relay-memory-storage");
|
|
21
20
|
const relay_server_accounts_1 = require("./relay-server-accounts");
|
|
21
|
+
const relay_server_gate_1 = require("./relay-server-gate");
|
|
22
|
+
const relay_server_web_1 = require("./relay-server-web");
|
|
22
23
|
const relay_viewer_1 = require("./relay-viewer");
|
|
23
24
|
const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
|
|
24
25
|
const peer = (connection) => ({ send: text => connection.send(text), close: (code, reason) => connection.close(code, reason) });
|
|
@@ -41,6 +42,20 @@ class RelayServer {
|
|
|
41
42
|
/** The address each connection to a spot came from. */
|
|
42
43
|
this.spotAddresses = new WeakMap();
|
|
43
44
|
this.accounts = new relay_server_accounts_1.RelayServerAccounts(options.data, { providers: options.accounts });
|
|
45
|
+
this.gate = new relay_server_gate_1.RelayServerGate(options.data ? new relay_file_storage_1.FileRelayStorage((0, node_path_1.join)(options.data, 'moderation')) : new relay_memory_storage_1.MemoryBlobStorage(), {
|
|
46
|
+
// Read as they are each time: a test sets the domain of content once it knows its port.
|
|
47
|
+
get content() {
|
|
48
|
+
return options.content;
|
|
49
|
+
},
|
|
50
|
+
adminToken: options.adminToken,
|
|
51
|
+
whoIs: authorization => this.accounts.whoIs(authorization),
|
|
52
|
+
holds: (host, secret) => {
|
|
53
|
+
var _a;
|
|
54
|
+
var _b;
|
|
55
|
+
const hash = (_b = (_a = this.rooms.get(host)) === null || _a === void 0 ? void 0 : _a.secretHash) !== null && _b !== void 0 ? _b : this.claims.get(host);
|
|
56
|
+
return !!hash && RelayServer.same(hash, (0, node_crypto_1.createHash)('sha256').update(secret).digest('base64url'));
|
|
57
|
+
},
|
|
58
|
+
});
|
|
44
59
|
if (options.data) {
|
|
45
60
|
(0, node_fs_1.mkdirSync)(options.data, { recursive: true, mode: 0o700 });
|
|
46
61
|
try {
|
|
@@ -90,15 +105,20 @@ class RelayServer {
|
|
|
90
105
|
const server = (0, node_http_1.createServer)((request, response) => {
|
|
91
106
|
var _a;
|
|
92
107
|
const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split(/[?#]/)[0];
|
|
108
|
+
if (this.gate.answer(request, response)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
93
111
|
if (path === deployment_protocol_1.TA_WELL_KNOWN_PATH || path === '/healthz' || path === '/readyz') {
|
|
94
112
|
this.describe(path, request, response);
|
|
95
113
|
return;
|
|
96
114
|
}
|
|
97
115
|
if (path === relay_info_1.RELAY_INFO_PATH) {
|
|
98
116
|
// Without a directory for its data, rooms and copies live in memory: gone when the relay restarts.
|
|
99
|
-
const info = relay_info_1.RelayInfoUtil.of(!!this.options.data, this.options.media);
|
|
100
|
-
|
|
101
|
-
|
|
117
|
+
const info = relay_info_1.RelayInfoUtil.of(!!this.options.data, this.options.media, relay_info_1.RelayInfoUtil.origin(this.options.content));
|
|
118
|
+
void this.gate.needsAccount().then(needs => {
|
|
119
|
+
response.writeHead(200, { 'content-type': 'application/json', 'access-control-allow-origin': '*', 'cache-control': 'no-store' });
|
|
120
|
+
response.end(JSON.stringify({ ...info, ...needs }));
|
|
121
|
+
});
|
|
102
122
|
return;
|
|
103
123
|
}
|
|
104
124
|
if (path.startsWith(relay_account_1.RELAY_ACCOUNT_PATH)) {
|
|
@@ -157,22 +177,7 @@ class RelayServer {
|
|
|
157
177
|
}
|
|
158
178
|
/** A file of Ta's web page (RelayWebUtil), from the directory of the options. */
|
|
159
179
|
web(path, response) {
|
|
160
|
-
|
|
161
|
-
if (path === relay_team_1.RELAY_WEB_PATH.slice(0, -1)) {
|
|
162
|
-
response.writeHead(308, { location: relay_team_1.RELAY_WEB_PATH });
|
|
163
|
-
response.end();
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const file = relay_web_1.RelayWebUtil.file(path);
|
|
167
|
-
const full = file && this.options.web ? (0, node_path_1.join)(this.options.web, file) : undefined;
|
|
168
|
-
if (!file || !full || !((_a = (0, node_fs_1.statSync)(full, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile())) {
|
|
169
|
-
response.writeHead(404, { 'content-type': 'text/plain' });
|
|
170
|
-
response.end('Not found.\n');
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const body = (0, node_fs_1.readFileSync)(full);
|
|
174
|
-
response.writeHead(200, relay_web_1.RelayWebUtil.headers(file));
|
|
175
|
-
response.end(file === 'index.html' ? relay_web_1.RelayWebUtil.index(body.toString('utf8')) : body);
|
|
180
|
+
relay_server_web_1.RelayServerWeb.serve(this.options.web, path, response);
|
|
176
181
|
}
|
|
177
182
|
close() {
|
|
178
183
|
var _a, _b, _c, _d, _e;
|
|
@@ -210,8 +215,13 @@ class RelayServer {
|
|
|
210
215
|
response.writeHead(404).end();
|
|
211
216
|
return;
|
|
212
217
|
}
|
|
218
|
+
const refused = media ? undefined : await this.gate.refusesBlob(request, id);
|
|
219
|
+
if (refused) {
|
|
220
|
+
response.writeHead(refused, { 'access-control-allow-origin': '*' }).end('Refused by the operator of the relay.\n');
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
213
223
|
const limits = media && relay_blobs_1.RelayBlobsUtil.limitsOf(media);
|
|
214
|
-
const read = await
|
|
224
|
+
const read = await relay_server_gate_1.RelayServerGate.body(request, (_a = limits === null || limits === void 0 ? void 0 : limits.bytes) !== null && _a !== void 0 ? _a : relay_blobs_1.RelayBlobs.MAX_BYTES);
|
|
215
225
|
if (!read) {
|
|
216
226
|
// Refused before it is all in memory, whatever its content-length said.
|
|
217
227
|
response.writeHead(413, { connection: 'close' }).end('Too large.\n');
|
|
@@ -272,28 +282,6 @@ class RelayServer {
|
|
|
272
282
|
(0, node_fs_1.writeFileSync)(`${file}.tmp`, JSON.stringify(Object.fromEntries(this.claims)), { mode: 0o600 });
|
|
273
283
|
(0, node_fs_1.renameSync)(`${file}.tmp`, file);
|
|
274
284
|
}
|
|
275
|
-
/** The body of a request, or undefined past `max` bytes: the rest is read and dropped. */
|
|
276
|
-
static body(request, max) {
|
|
277
|
-
return new Promise((resolve, reject) => {
|
|
278
|
-
const chunks = [];
|
|
279
|
-
let size = 0;
|
|
280
|
-
request.on('data', (chunk) => {
|
|
281
|
-
if (size < 0) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
size += chunk.length;
|
|
285
|
-
if (size > max) {
|
|
286
|
-
size = -1;
|
|
287
|
-
chunks.length = 0;
|
|
288
|
-
resolve(undefined);
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
chunks.push(chunk);
|
|
292
|
-
});
|
|
293
|
-
request.on('end', () => size >= 0 && resolve(Buffer.concat(chunks)));
|
|
294
|
-
request.on('error', reject);
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
285
|
upgrade(request, socket, head) {
|
|
298
286
|
var _a, _b, _c;
|
|
299
287
|
const url = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://relay');
|
|
@@ -302,6 +290,10 @@ class RelayServer {
|
|
|
302
290
|
websocket_connection_1.WebSocketConnection.refuse(socket, checked.status, checked.message);
|
|
303
291
|
return;
|
|
304
292
|
}
|
|
293
|
+
if (this.gate.refuses(request)) {
|
|
294
|
+
websocket_connection_1.WebSocketConnection.refuse(socket, 404, 'Not found.');
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
305
297
|
if (url.pathname.startsWith(relay_protocol_1.RELAY_HUB_PATH)) {
|
|
306
298
|
const id = url.pathname.slice(relay_protocol_1.RELAY_HUB_PATH.length);
|
|
307
299
|
if (!relay_protocol_1.RELAY_ID.test(id)) {
|
|
@@ -337,10 +329,11 @@ class RelayServer {
|
|
|
337
329
|
const connection = websocket_connection_1.WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
|
|
338
330
|
if (path === relay_protocol_1.RELAY_HOST_PATH) {
|
|
339
331
|
this.openHost(id, (_c = url.searchParams.get('secret')) !== null && _c !== void 0 ? _c : '', connection);
|
|
332
|
+
return;
|
|
340
333
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
334
|
+
void this.gate
|
|
335
|
+
.refusesViewer(request, id)
|
|
336
|
+
.then(code => (code ? connection.close(code, 'Blocked by the operator of the relay.') : this.openClient(id, connection)));
|
|
344
337
|
}
|
|
345
338
|
/** The first host to come with an id keeps it, for as long as the relay runs, or for good with `data`. */
|
|
346
339
|
openHost(id, secret, connection) {
|
|
@@ -38,6 +38,8 @@ export interface RelayContentShare extends RelayContentHeader {
|
|
|
38
38
|
id: string;
|
|
39
39
|
/** The relay of its link and its offline copy; none: RelayConfig.url. */
|
|
40
40
|
relay?: string;
|
|
41
|
+
/** The domain of content of that relay its link opens at (RelayInfo.content), as the relay said when shared; none: the relay's own. */
|
|
42
|
+
page?: string;
|
|
41
43
|
access: RelayContentAccess;
|
|
42
44
|
/** base64url, 32 bytes: what the content is sealed with (with a password, derived from it and the key of the link). */
|
|
43
45
|
key: string;
|
|
@@ -71,6 +73,8 @@ export interface RelayContentInput extends RelayContentHeader {
|
|
|
71
73
|
offline?: boolean;
|
|
72
74
|
/** The relay of its link (relays.json's `share`); default the relay of the devices. */
|
|
73
75
|
relay?: string;
|
|
76
|
+
/** Its domain of content (RelayInfo.content). */
|
|
77
|
+
page?: string;
|
|
74
78
|
/** For `people`: the Ta friends it is shared with, and this Ta's identity. */
|
|
75
79
|
people?: RelayPublicIdentity[];
|
|
76
80
|
identity?: RelayIdentity;
|
package/lib/node/relay-store.js
CHANGED
|
@@ -93,6 +93,7 @@ class RelayStore {
|
|
|
93
93
|
const content = {
|
|
94
94
|
id,
|
|
95
95
|
relay,
|
|
96
|
+
...(input.page ? { page: input.page } : {}),
|
|
96
97
|
kind: input.kind,
|
|
97
98
|
title: input.title,
|
|
98
99
|
createdAt: input.createdAt,
|
|
@@ -118,6 +119,7 @@ class RelayStore {
|
|
|
118
119
|
var _b;
|
|
119
120
|
return {
|
|
120
121
|
relay: RelayStore.relayOf(content, config),
|
|
122
|
+
...(content.page ? { page: content.page } : {}),
|
|
121
123
|
host: (_b = (_a = config.host) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '',
|
|
122
124
|
share: content.id,
|
|
123
125
|
key: content.linkKey,
|
|
@@ -14,13 +14,22 @@ declare const zh: {
|
|
|
14
14
|
wrong: string;
|
|
15
15
|
busy: string;
|
|
16
16
|
gone: string;
|
|
17
|
+
goneHint: string;
|
|
17
18
|
offline: string;
|
|
19
|
+
offlineHint: string;
|
|
18
20
|
self: string;
|
|
21
|
+
selfHint: string;
|
|
19
22
|
people: string;
|
|
23
|
+
peopleHint: string;
|
|
20
24
|
invalid: string;
|
|
25
|
+
invalidHint: string;
|
|
21
26
|
timeout: string;
|
|
27
|
+
timeoutHint: string;
|
|
22
28
|
large: string;
|
|
29
|
+
largeHint: string;
|
|
23
30
|
failed: string;
|
|
31
|
+
failedHint: string;
|
|
32
|
+
retry: string;
|
|
24
33
|
you: string;
|
|
25
34
|
ta: string;
|
|
26
35
|
outputsOmitted: string;
|
|
@@ -48,6 +57,22 @@ declare const zh: {
|
|
|
48
57
|
webSearch: string;
|
|
49
58
|
script: string;
|
|
50
59
|
use: string;
|
|
60
|
+
report: string;
|
|
61
|
+
reportTitle: string;
|
|
62
|
+
reportHint: string;
|
|
63
|
+
reasonPhishing: string;
|
|
64
|
+
reasonMalware: string;
|
|
65
|
+
reasonSexual: string;
|
|
66
|
+
reasonIllegal: string;
|
|
67
|
+
reasonHarassment: string;
|
|
68
|
+
reasonOther: string;
|
|
69
|
+
reportNote: string;
|
|
70
|
+
reportWithLink: string;
|
|
71
|
+
send: string;
|
|
72
|
+
cancel: string;
|
|
73
|
+
reportSent: string;
|
|
74
|
+
reportFailed: string;
|
|
75
|
+
blocked: string;
|
|
51
76
|
};
|
|
52
77
|
export type ViewerText = keyof typeof zh;
|
|
53
78
|
/** The words of each language of Ta, checked by scripts/check-i18n.ts. */
|