fix(content-manager) parseChubUrl should clean URL before relying on length (#5604)

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
This commit is contained in:
Rojikku
2026-05-13 22:03:26 +03:00
committed by GitHub
co-authored by Cohee
parent d08bbb1096
commit 3913dfffb9
+9 -9
View File
@@ -556,11 +556,6 @@ async function downloadPygmalionCharacter(id) {
*/
function parseChubUrl(str) {
const splitStr = str.split('/');
const length = splitStr.length;
if (length < 2) {
return null;
}
let domainIndex = -1;
@@ -570,20 +565,25 @@ function parseChubUrl(str) {
}
});
const lastTwo = domainIndex !== -1 ? splitStr.slice(domainIndex + 1) : splitStr;
const cleanUrl = domainIndex !== -1 ? splitStr.slice(domainIndex + 1) : splitStr;
const length = cleanUrl.length;
const firstPart = lastTwo[0].toLowerCase();
if (length < 2) {
return null;
}
const firstPart = cleanUrl[0].toLowerCase();
if (firstPart === 'characters' || firstPart === 'lorebooks') {
const type = firstPart === 'characters' ? 'character' : 'lorebook';
const id = type === 'character' ? lastTwo.slice(1).join('/') : lastTwo.join('/');
const id = type === 'character' ? cleanUrl.slice(1).join('/') : cleanUrl.join('/');
return {
id: id,
type: type,
};
} else if (length === 2) {
return {
id: lastTwo.join('/'),
id: cleanUrl.join('/'),
type: 'character',
};
}