Files
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

31 lines
930 B
TypeScript

import type { 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();
};
}