Commit c861d88c by PLN (Algolia)

fix: Correct rewrite

parent e43bc5bb
...@@ -33,17 +33,25 @@ export default function HydraSynth({ source }) { ...@@ -33,17 +33,25 @@ export default function HydraSynth({ source }) {
// Remove any HTML-like tags // Remove any HTML-like tags
let sanitizedCode = code.replace(/<[^>]*>/g, ''); let sanitizedCode = code.replace(/<[^>]*>/g, '');
// Replace local file paths with Git URLs - careful to preserve s0.initImage // Replace local file paths with Git URLs
sanitizedCode = sanitizedCode.replace( sanitizedCode = sanitizedCode.replace(
/initImage\("file:\/\/\/home\/pln\/Work\/Hydra\/(.+?)\/(.+?)"\)/g, /s([0-9])\.initImage\("file:\/\/\/home\/pln\/Work\/Hydra\/(.+?)\/(.+?)"\)/g,
'initImage("https://git.nech.pl/pln/Hydra/raw/master/$1/$2")' 's$1.initImage("https://git.nech.pl/pln/Hydra/raw/master/$2/$3")'
); );
// Replace old domain with new domain // Replace old domain with new domain - match the complete URL
sanitizedCode = sanitizedCode.replace(/git\.plnech\.fr/g, 'git.nech.pl'); sanitizedCode = sanitizedCode.replace(
/https:\/\/git\.plnech\.fr\/pln\/Hydra\/raw\/[a-f0-9]+\/(.+?)\/(.+?)(\.jpg|\.jpeg|\.png|\.gif|\.svg)/g,
'https://git.nech.pl/pln/Hydra/raw/master/$1/$2$3'
);
// Trim whitespace and remove any leading/trailing backticks // Trim whitespace and remove any leading/trailing backticks
return sanitizedCode.trim().replace(/^`+|`+$/g, ''); sanitizedCode = sanitizedCode.trim().replace(/^`+|`+$/g, '');
// Remove any JavaScript code block indicators
sanitizedCode = sanitizedCode.replace(/```javascript|```/g, '');
return sanitizedCode;
}; };
// Validate and run the hydra code // Validate and run the hydra code
...@@ -59,15 +67,14 @@ export default function HydraSynth({ source }) { ...@@ -59,15 +67,14 @@ export default function HydraSynth({ source }) {
} }
// Log the transformed code for debugging // Log the transformed code for debugging
console.log("Running Hydra code with transformed paths"); console.log("Running Hydra code:", cleanCode);
// Attempt to evaluate the code // Attempt to evaluate the code
hydra.eval(cleanCode); hydra.eval(cleanCode);
} catch (error) { } catch (error) {
console.error("Error running Hydra code:", error); console.error("Error running Hydra code:", error);
console.error("Error details:", error.message);
// Attempt to provide more context console.error("Error location:", error.lineNumber, error.columnNumber);
console.log("Sanitized code error location:", error.lineNumber);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment