Skip to content

Commit

Permalink
feat(Node): make version regex for only supported v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Fab1o0107 committed Dec 27, 2023
1 parent 348552c commit 63800e3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ export class Node {
if (!this.manager.id) throw new Error("Don't connect a node when the library is not yet ready");
if (this.destroyed)
throw new Error("You can't re-use the same instance of a node once disconnected, please re-add the node again");
if (this.state === State.Connected) return undefined;

const version = await (
await fetch(`${this.url}/version`, {
headers: { Authorization: this.authorization, "User-Agent": this.manager.options.userAgent }
})
).text();
const versionRegex =
/^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;

if (Number(versionRegex.exec(version)?.at(1) ?? 0) !== 4)
throw new Error(`This node (${this.name}) is only supported for v4`);

this.state = State.Connecting;
this.sessionId = (await this.manager.redis?.get(RedisKey.NodeSession(this.name.toLowerCase()))) ?? null;
Expand Down

0 comments on commit 63800e3

Please sign in to comment.