Moved mongo id validation into its own function

This commit is contained in:
Dev 2024-09-23 14:33:47 +01:00
parent cabd17d2c9
commit 22b661ac49
2 changed files with 10 additions and 1 deletions

View File

@ -1141,7 +1141,7 @@ export class InventoryHelper {
public validateInventoryUsesMonogoIds(itemsToValidate: Item[]) {
for (const item of itemsToValidate) {
if (!/^[a-fA-F0-9]{24}$/.test(item._id)) {
if (!this.hashUtil.isValidMongoId(item._id)) {
throw new Error(
`This profile is not compatible with 3.10.0, It contains an item with the ID: ${item._id} that is not compatible. Loading of SPT has been halted, use another profile or create a new one.`,
);

View File

@ -17,6 +17,15 @@ export class HashUtil {
return mongoid();
}
/**
* is the passed in string a valid mongo id
* @param stringToCheck String to check
* @returns True when string is a valid mongo id
*/
public isValidMongoId(stringToCheck: string) {
return /^[a-fA-F0-9]{24}$/.test(stringToCheck);
}
public generateMd5ForData(data: string): string {
return this.generateHashForData("md5", data);
}