mirror of
https://github.com/outline/outline.git
synced 2026-05-20 01:28:58 -05:00
0ec6440506
* Move editor version check to collaboration server connection * connected -> onConnect * docs * Remove hardcoded event codes
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { Extension, onConnectPayload } from "@hocuspocus/server";
|
||
import semver from "semver";
|
||
import { EditorUpdateError } from "@shared/collaboration/CloseEvents";
|
||
import EDITOR_VERSION from "@shared/editor/version";
|
||
import Logger from "@server/logging/Logger";
|
||
import { trace } from "@server/logging/tracing";
|
||
import { withContext } from "./types";
|
||
|
||
@trace()
|
||
export class EditorVersionExtension implements Extension {
|
||
/**
|
||
* On connect hook – prevents connections from clients with an outdated editor
|
||
* version. See the equivalent logic for API in /server/routes/api/middlewares/editor.ts
|
||
*
|
||
* @param data The connect payload
|
||
* @returns Promise, resolving will allow the connection, rejecting will drop.
|
||
*/
|
||
onConnect({ requestParameters }: withContext<onConnectPayload>) {
|
||
const clientVersion = requestParameters.get("editorVersion");
|
||
|
||
if (clientVersion) {
|
||
const parsedClientVersion = semver.parse(clientVersion);
|
||
const parsedServerVersion = semver.parse(EDITOR_VERSION);
|
||
|
||
if (
|
||
parsedClientVersion &&
|
||
parsedServerVersion &&
|
||
parsedClientVersion.major < parsedServerVersion.major
|
||
) {
|
||
Logger.debug(
|
||
"multiplayer",
|
||
`Dropping connection due to outdated editor version: ${clientVersion} < ${EDITOR_VERSION}`
|
||
);
|
||
return Promise.reject(EditorUpdateError);
|
||
}
|
||
}
|
||
|
||
return Promise.resolve();
|
||
}
|
||
}
|