Fix Bulk registration invalid MXID in requests, fixes #30 (#33)

* Fix Bulk registration invalid MXID in requests

* update readme
This commit is contained in:
Aine
2024-09-17 14:02:41 +03:00
committed by GitHub
parent 66c706532a
commit 6957cb1f7d
4 changed files with 35 additions and 10 deletions

View File

@@ -72,6 +72,26 @@ export function generateRandomMxId(): string {
return `@${localpart}:${homeserver}`;
}
/**
* Return the full MXID from an arbitrary input
* @param input the input string
* @returns full MXID as string
*/
export function returnMXID(input: string): string {
const homeserver = storage.getItem("home_server");
// Check if the input already looks like a valid MXID (i.e., starts with "@" and contains ":")
const mxidPattern = /^@[^@:]+:[^@:]+$/;
if (mxidPattern.test(input)) {
return input; // Already a valid MXID
}
// If input is not a valid MXID, assume it's a localpart and construct the MXID
const localpart = input.startsWith('@') ? input.slice(1) : input;
return `@${localpart}:${homeserver}`;
}
/**
* Generate a random user password
* @returns a new random password as string