[bugfix] fix playlist maps with malformed hash doesnt get loaded + improve playlist maps reading reliability

This commit is contained in:
MathieuG-P
2024-07-17 20:26:54 +02:00
parent 163857a14f
commit a6fa55719d
5 changed files with 87 additions and 25 deletions
+13
View File
@@ -0,0 +1,13 @@
const HashAlgorithmsLengths = {
sha1: 40,
} as const;
export function findHashInString(str: string, algorithm: keyof typeof HashAlgorithmsLengths = 'sha1'): string | undefined {
if(!str) { return undefined; }
const hashLength = HashAlgorithmsLengths[algorithm];
const regex = new RegExp(`[a-fA-F0-9]{${hashLength}}`, "g");
const match = str.match(regex);
return match ? match[0] : undefined;
}