mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
* Move editor version check to collaboration server connection * connected -> onConnect * docs * Remove hardcoded event codes
31 lines
925 B
TypeScript
31 lines
925 B
TypeScript
import { Context, Next } from "koa";
|
|
import semver from "semver";
|
|
import EDITOR_VERSION from "@shared/editor/version";
|
|
import { EditorUpdateError } from "@server/errors";
|
|
|
|
export default function editor() {
|
|
/**
|
|
* Middleware to prevent connections from clients with an outdated editor
|
|
* version. See the equivalent logic for collab server in:
|
|
* /server/collaboration/EditorVersionExtension.ts
|
|
*/
|
|
return async function editorMiddleware(ctx: Context, next: Next) {
|
|
const clientVersion = ctx.headers["x-editor-version"];
|
|
|
|
if (clientVersion) {
|
|
const parsedClientVersion = semver.parse(clientVersion as string);
|
|
const parsedCurrentVersion = semver.parse(EDITOR_VERSION);
|
|
|
|
if (
|
|
parsedClientVersion &&
|
|
parsedCurrentVersion &&
|
|
parsedClientVersion.major < parsedCurrentVersion.major
|
|
) {
|
|
throw EditorUpdateError();
|
|
}
|
|
}
|
|
|
|
return next();
|
|
};
|
|
}
|