Fix AICC direct link import parsing (#5307)
* Fix AICC direct link import parsing Update parseAICC in src/endpoints/content-manager.js to dynamically extract the author and character name from the end of the URL path. This resolves a 404 import error caused by AICC adding category subfolders and changing their base URL structure from /character-cards/ to /charactercards/. * Clean up whitespace in content-manager.js Remove unnecessary whitespace in URL path processing. * Use isValidUrl for URL validation --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
This commit is contained in:
@@ -584,11 +584,24 @@ async function downloadAICCCharacter(id) {
|
||||
* @returns {string | null} AICC path
|
||||
*/
|
||||
function parseAICC(url) {
|
||||
const pattern = /^https?:\/\/aicharactercards\.com\/character-cards\/([^/]+)\/([^/]+)\/?$|([^/]+)\/([^/]+)$/;
|
||||
const match = url.match(pattern);
|
||||
if (match) {
|
||||
// Match group 1 & 2 for full URL, 3 & 4 for relative path
|
||||
return match[1] && match[2] ? `${match[1]}/${match[2]}` : `${match[3]}/${match[4]}`;
|
||||
try {
|
||||
if (isValidUrl(url)) {
|
||||
const urlObj = new URL(url);
|
||||
// Split the path and remove empty strings caused by trailing slashes
|
||||
const parts = urlObj.pathname.split('/').filter(Boolean);
|
||||
if (parts.length >= 2) {
|
||||
// Always grab the last two segments (author/character)
|
||||
return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
|
||||
}
|
||||
} else {
|
||||
// Fallback for relative paths or raw "author/character" strings
|
||||
const parts = url.split('/').filter(Boolean);
|
||||
if (parts.length >= 2) {
|
||||
return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing AICC URL:', e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user