@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
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { RelayContentOrigin } from '../common/relay-content-origin.js';
|
|
2
|
+
import { RelayModeration } from '../common/relay-moderation.js';
|
|
3
|
+
import { RelayModerationDoor } from '../common/relay-moderation-door.js';
|
|
4
|
+
import { RelaySpotTries } from '../common/relay-spot.js';
|
|
5
|
+
/**
|
|
6
|
+
* What `ta relay` answers before anything else (docs/design/ta-link.md 2.10): by the domain a request came to, its own
|
|
7
|
+
* or that of content; the reports of links and the operator's blocks.
|
|
8
|
+
*/
|
|
9
|
+
export class RelayServerGate {
|
|
10
|
+
constructor(storage, options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.moderation = new RelayModeration(storage);
|
|
13
|
+
}
|
|
14
|
+
/** The address a request reached the relay at, by its Host. */
|
|
15
|
+
static urlOf(request) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
return new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', `http://${(_b = request.headers.host) !== null && _b !== void 0 ? _b : 'relay'}`);
|
|
18
|
+
}
|
|
19
|
+
/** Whether it answered the request: not on this domain, sent to the domain of content, a report, the operator's. */
|
|
20
|
+
answer(request, response) {
|
|
21
|
+
const url = RelayServerGate.urlOf(request);
|
|
22
|
+
const route = RelayContentOrigin.route(url, this.options.content);
|
|
23
|
+
if (route.kind === 'redirect') {
|
|
24
|
+
response.writeHead(308, { location: route.location }).end();
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (route.kind === 'refuse') {
|
|
28
|
+
response.writeHead(404, { 'content-type': 'text/plain' }).end('Not found.\n');
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (!RelayModerationDoor.handles(url.pathname)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
this.moderate(request, response).catch(() => {
|
|
35
|
+
if (!response.headersSent) {
|
|
36
|
+
response.writeHead(400);
|
|
37
|
+
}
|
|
38
|
+
response.end();
|
|
39
|
+
});
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/** What the policy needs an account for, as /v1/info says it. */
|
|
43
|
+
async needsAccount() {
|
|
44
|
+
const needs = (await this.moderation.policy()).needsAccount;
|
|
45
|
+
return needs.length ? { needsAccount: needs } : {};
|
|
46
|
+
}
|
|
47
|
+
/** Whether a WebSocket to this path has no place on the domain it came to. */
|
|
48
|
+
refuses(request) {
|
|
49
|
+
return RelayContentOrigin.route(RelayServerGate.urlOf(request), this.options.content).kind === 'refuse';
|
|
50
|
+
}
|
|
51
|
+
static headersOf(request) {
|
|
52
|
+
const headers = new Headers();
|
|
53
|
+
for (const [name, value] of Object.entries(request.headers)) {
|
|
54
|
+
if (typeof value === 'string') {
|
|
55
|
+
headers.set(name, value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return headers;
|
|
59
|
+
}
|
|
60
|
+
/** Why a viewer of a link of this host is refused (RelayModeration.viewer); the pages of the relay in a browser by their Origin. */
|
|
61
|
+
refusesViewer(request, host) {
|
|
62
|
+
var _a;
|
|
63
|
+
const own = `http://${(_a = request.headers.host) !== null && _a !== void 0 ? _a : 'relay'}`;
|
|
64
|
+
const browser = RelayModerationDoor.browser({ headers: RelayServerGate.headersOf(request) }, [this.options.content, own]);
|
|
65
|
+
return this.moderation.viewer(host, browser);
|
|
66
|
+
}
|
|
67
|
+
/** Why a copy is not kept: where links need an account, the one who puts it names theirs (`x-ta-account`). */
|
|
68
|
+
async refusesCopy(request) {
|
|
69
|
+
const header = request.headers['x-ta-account'];
|
|
70
|
+
const who = typeof header === 'string' ? await this.options.whoIs(header) : undefined;
|
|
71
|
+
return this.moderation.viewer('', true, who);
|
|
72
|
+
}
|
|
73
|
+
/** 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). */
|
|
74
|
+
async refusesBlob(request, share) {
|
|
75
|
+
if (request.method === 'GET') {
|
|
76
|
+
return (await this.moderation.blocked(undefined, share)) ? 410 : undefined;
|
|
77
|
+
}
|
|
78
|
+
return request.method === 'PUT' && (await this.refusesCopy(request)) ? 451 : undefined;
|
|
79
|
+
}
|
|
80
|
+
async moderate(request, response) {
|
|
81
|
+
var _a;
|
|
82
|
+
const body = await RelayServerGate.body(request, 16 * 1024);
|
|
83
|
+
if (!body) {
|
|
84
|
+
response.writeHead(413, { connection: 'close' }).end('Too large.\n');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const method = (_a = request.method) !== null && _a !== void 0 ? _a : 'GET';
|
|
88
|
+
const outer = new Request(`http://relay${request.url}`, {
|
|
89
|
+
method,
|
|
90
|
+
headers: RelayServerGate.headersOf(request),
|
|
91
|
+
body: method === 'GET' || method === 'HEAD' ? undefined : body,
|
|
92
|
+
});
|
|
93
|
+
const answer = await RelayModerationDoor.handle(outer, RelaySpotTries.keyOf(request.socket.remoteAddress), {
|
|
94
|
+
whoIs: authorization => this.options.whoIs(authorization),
|
|
95
|
+
holds: async (host, secret) => this.options.holds(host, secret),
|
|
96
|
+
moderate: (inner, address, who) => this.moderation.handle(inner, address, this.options.adminToken || undefined, who),
|
|
97
|
+
});
|
|
98
|
+
response.writeHead(answer.status, Object.fromEntries(answer.headers));
|
|
99
|
+
response.end(Buffer.from(await answer.arrayBuffer()));
|
|
100
|
+
}
|
|
101
|
+
/** The body of a request, or undefined past `max` bytes: the rest is read and dropped. */
|
|
102
|
+
static body(request, max) {
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
const chunks = [];
|
|
105
|
+
let size = 0;
|
|
106
|
+
request.on('data', (chunk) => {
|
|
107
|
+
if (size < 0) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
size += chunk.length;
|
|
111
|
+
if (size > max) {
|
|
112
|
+
size = -1;
|
|
113
|
+
chunks.length = 0;
|
|
114
|
+
resolve(undefined);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
chunks.push(chunk);
|
|
118
|
+
});
|
|
119
|
+
request.on('end', () => size >= 0 && resolve(Buffer.concat(chunks)));
|
|
120
|
+
request.on('error', reject);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=relay-server-gate.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { RELAY_WEB_PATH } from '../common/relay-team.js';
|
|
4
|
+
import { RelayWebUtil } from '../common/relay-web.js';
|
|
5
|
+
/** Ta's web page as `ta relay` serves it under RELAY_WEB_PATH, from a directory of its files. */
|
|
6
|
+
export var RelayServerWeb;
|
|
7
|
+
(function (RelayServerWeb) {
|
|
8
|
+
function serve(dir, path, response) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (path === RELAY_WEB_PATH.slice(0, -1)) {
|
|
11
|
+
response.writeHead(308, { location: RELAY_WEB_PATH });
|
|
12
|
+
response.end();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const file = RelayWebUtil.file(path);
|
|
16
|
+
const full = file && dir ? join(dir, file) : undefined;
|
|
17
|
+
if (!file || !full || !((_a = statSync(full, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile())) {
|
|
18
|
+
response.writeHead(404, { 'content-type': 'text/plain' });
|
|
19
|
+
response.end('Not found.\n');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const body = readFileSync(full);
|
|
23
|
+
response.writeHead(200, RelayWebUtil.headers(file));
|
|
24
|
+
response.end(file === 'index.html' ? RelayWebUtil.index(body.toString('utf8')) : body);
|
|
25
|
+
}
|
|
26
|
+
RelayServerWeb.serve = serve;
|
|
27
|
+
})(RelayServerWeb || (RelayServerWeb = {}));
|
|
28
|
+
//# 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.js';
|
|
12
12
|
import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage.js';
|
|
13
13
|
import { RelayServerAccounts } from './relay-server-accounts.js';
|
|
14
|
+
import { RelayServerGate } from './relay-server-gate.js';
|
|
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/esm/node/relay-server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
-
import { accessSync, constants, mkdirSync, readFileSync, renameSync,
|
|
2
|
+
import { accessSync, constants, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
|
|
@@ -12,10 +12,11 @@ import { RELAY_BLOB_PATH, RELAY_CONNECT_PATH, RELAY_CONTENT_PATH, RELAY_FRAME_HE
|
|
|
12
12
|
import { RelayRoom } from '../common/relay-room.js';
|
|
13
13
|
import { RELAY_SPOT_PATH, RelaySpot, RelaySpotCloseCode, RelaySpotTries } from '../common/relay-spot.js';
|
|
14
14
|
import { RELAY_JOIN_PATH, RELAY_WEB_PATH } from '../common/relay-team.js';
|
|
15
|
-
import { RelayWebUtil } from '../common/relay-web.js';
|
|
16
15
|
import { FileRelayStorage } from './relay-file-storage.js';
|
|
17
16
|
import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage.js';
|
|
18
17
|
import { RelayServerAccounts } from './relay-server-accounts.js';
|
|
18
|
+
import { RelayServerGate } from './relay-server-gate.js';
|
|
19
|
+
import { RelayServerWeb } from './relay-server-web.js';
|
|
19
20
|
import { RelayViewer } from './relay-viewer.js';
|
|
20
21
|
const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
|
|
21
22
|
const peer = (connection) => ({ send: text => connection.send(text), close: (code, reason) => connection.close(code, reason) });
|
|
@@ -38,6 +39,20 @@ export class RelayServer {
|
|
|
38
39
|
/** The address each connection to a spot came from. */
|
|
39
40
|
this.spotAddresses = new WeakMap();
|
|
40
41
|
this.accounts = new RelayServerAccounts(options.data, { providers: options.accounts });
|
|
42
|
+
this.gate = new RelayServerGate(options.data ? new FileRelayStorage(join(options.data, 'moderation')) : new MemoryBlobStorage(), {
|
|
43
|
+
// Read as they are each time: a test sets the domain of content once it knows its port.
|
|
44
|
+
get content() {
|
|
45
|
+
return options.content;
|
|
46
|
+
},
|
|
47
|
+
adminToken: options.adminToken,
|
|
48
|
+
whoIs: authorization => this.accounts.whoIs(authorization),
|
|
49
|
+
holds: (host, secret) => {
|
|
50
|
+
var _a;
|
|
51
|
+
var _b;
|
|
52
|
+
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);
|
|
53
|
+
return !!hash && RelayServer.same(hash, createHash('sha256').update(secret).digest('base64url'));
|
|
54
|
+
},
|
|
55
|
+
});
|
|
41
56
|
if (options.data) {
|
|
42
57
|
mkdirSync(options.data, { recursive: true, mode: 0o700 });
|
|
43
58
|
try {
|
|
@@ -87,15 +102,20 @@ export class RelayServer {
|
|
|
87
102
|
const server = createServer((request, response) => {
|
|
88
103
|
var _a;
|
|
89
104
|
const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split(/[?#]/)[0];
|
|
105
|
+
if (this.gate.answer(request, response)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
90
108
|
if (path === TA_WELL_KNOWN_PATH || path === '/healthz' || path === '/readyz') {
|
|
91
109
|
this.describe(path, request, response);
|
|
92
110
|
return;
|
|
93
111
|
}
|
|
94
112
|
if (path === RELAY_INFO_PATH) {
|
|
95
113
|
// Without a directory for its data, rooms and copies live in memory: gone when the relay restarts.
|
|
96
|
-
const info = RelayInfoUtil.of(!!this.options.data, this.options.media);
|
|
97
|
-
|
|
98
|
-
|
|
114
|
+
const info = RelayInfoUtil.of(!!this.options.data, this.options.media, RelayInfoUtil.origin(this.options.content));
|
|
115
|
+
void this.gate.needsAccount().then(needs => {
|
|
116
|
+
response.writeHead(200, { 'content-type': 'application/json', 'access-control-allow-origin': '*', 'cache-control': 'no-store' });
|
|
117
|
+
response.end(JSON.stringify({ ...info, ...needs }));
|
|
118
|
+
});
|
|
99
119
|
return;
|
|
100
120
|
}
|
|
101
121
|
if (path.startsWith(RELAY_ACCOUNT_PATH)) {
|
|
@@ -154,22 +174,7 @@ export class RelayServer {
|
|
|
154
174
|
}
|
|
155
175
|
/** A file of Ta's web page (RelayWebUtil), from the directory of the options. */
|
|
156
176
|
web(path, response) {
|
|
157
|
-
|
|
158
|
-
if (path === RELAY_WEB_PATH.slice(0, -1)) {
|
|
159
|
-
response.writeHead(308, { location: RELAY_WEB_PATH });
|
|
160
|
-
response.end();
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const file = RelayWebUtil.file(path);
|
|
164
|
-
const full = file && this.options.web ? join(this.options.web, file) : undefined;
|
|
165
|
-
if (!file || !full || !((_a = statSync(full, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile())) {
|
|
166
|
-
response.writeHead(404, { 'content-type': 'text/plain' });
|
|
167
|
-
response.end('Not found.\n');
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const body = readFileSync(full);
|
|
171
|
-
response.writeHead(200, RelayWebUtil.headers(file));
|
|
172
|
-
response.end(file === 'index.html' ? RelayWebUtil.index(body.toString('utf8')) : body);
|
|
177
|
+
RelayServerWeb.serve(this.options.web, path, response);
|
|
173
178
|
}
|
|
174
179
|
close() {
|
|
175
180
|
var _a, _b, _c, _d, _e;
|
|
@@ -207,8 +212,13 @@ export class RelayServer {
|
|
|
207
212
|
response.writeHead(404).end();
|
|
208
213
|
return;
|
|
209
214
|
}
|
|
215
|
+
const refused = media ? undefined : await this.gate.refusesBlob(request, id);
|
|
216
|
+
if (refused) {
|
|
217
|
+
response.writeHead(refused, { 'access-control-allow-origin': '*' }).end('Refused by the operator of the relay.\n');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
210
220
|
const limits = media && RelayBlobsUtil.limitsOf(media);
|
|
211
|
-
const read = await
|
|
221
|
+
const read = await RelayServerGate.body(request, (_a = limits === null || limits === void 0 ? void 0 : limits.bytes) !== null && _a !== void 0 ? _a : RelayBlobs.MAX_BYTES);
|
|
212
222
|
if (!read) {
|
|
213
223
|
// Refused before it is all in memory, whatever its content-length said.
|
|
214
224
|
response.writeHead(413, { connection: 'close' }).end('Too large.\n');
|
|
@@ -269,28 +279,6 @@ export class RelayServer {
|
|
|
269
279
|
writeFileSync(`${file}.tmp`, JSON.stringify(Object.fromEntries(this.claims)), { mode: 0o600 });
|
|
270
280
|
renameSync(`${file}.tmp`, file);
|
|
271
281
|
}
|
|
272
|
-
/** The body of a request, or undefined past `max` bytes: the rest is read and dropped. */
|
|
273
|
-
static body(request, max) {
|
|
274
|
-
return new Promise((resolve, reject) => {
|
|
275
|
-
const chunks = [];
|
|
276
|
-
let size = 0;
|
|
277
|
-
request.on('data', (chunk) => {
|
|
278
|
-
if (size < 0) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
size += chunk.length;
|
|
282
|
-
if (size > max) {
|
|
283
|
-
size = -1;
|
|
284
|
-
chunks.length = 0;
|
|
285
|
-
resolve(undefined);
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
chunks.push(chunk);
|
|
289
|
-
});
|
|
290
|
-
request.on('end', () => size >= 0 && resolve(Buffer.concat(chunks)));
|
|
291
|
-
request.on('error', reject);
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
282
|
upgrade(request, socket, head) {
|
|
295
283
|
var _a, _b, _c;
|
|
296
284
|
const url = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://relay');
|
|
@@ -299,6 +287,10 @@ export class RelayServer {
|
|
|
299
287
|
WebSocketConnection.refuse(socket, checked.status, checked.message);
|
|
300
288
|
return;
|
|
301
289
|
}
|
|
290
|
+
if (this.gate.refuses(request)) {
|
|
291
|
+
WebSocketConnection.refuse(socket, 404, 'Not found.');
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
302
294
|
if (url.pathname.startsWith(RELAY_HUB_PATH)) {
|
|
303
295
|
const id = url.pathname.slice(RELAY_HUB_PATH.length);
|
|
304
296
|
if (!RELAY_ID.test(id)) {
|
|
@@ -334,10 +326,11 @@ export class RelayServer {
|
|
|
334
326
|
const connection = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
|
|
335
327
|
if (path === RELAY_HOST_PATH) {
|
|
336
328
|
this.openHost(id, (_c = url.searchParams.get('secret')) !== null && _c !== void 0 ? _c : '', connection);
|
|
329
|
+
return;
|
|
337
330
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
331
|
+
void this.gate
|
|
332
|
+
.refusesViewer(request, id)
|
|
333
|
+
.then(code => (code ? connection.close(code, 'Blocked by the operator of the relay.') : this.openClient(id, connection)));
|
|
341
334
|
}
|
|
342
335
|
/** The first host to come with an id keeps it, for as long as the relay runs, or for good with `data`. */
|
|
343
336
|
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/esm/node/relay-store.js
CHANGED
|
@@ -90,6 +90,7 @@ export class RelayStore {
|
|
|
90
90
|
const content = {
|
|
91
91
|
id,
|
|
92
92
|
relay,
|
|
93
|
+
...(input.page ? { page: input.page } : {}),
|
|
93
94
|
kind: input.kind,
|
|
94
95
|
title: input.title,
|
|
95
96
|
createdAt: input.createdAt,
|
|
@@ -115,6 +116,7 @@ export class RelayStore {
|
|
|
115
116
|
var _b;
|
|
116
117
|
return {
|
|
117
118
|
relay: RelayStore.relayOf(content, config),
|
|
119
|
+
...(content.page ? { page: content.page } : {}),
|
|
118
120
|
host: (_b = (_a = config.host) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '',
|
|
119
121
|
share: content.id,
|
|
120
122
|
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. */
|