WIP idea of loading the files oddly

This commit is contained in:
Andre Molnar 2023-12-01 20:13:42 -05:00
parent 4a7a32a051
commit 86bcd911a4
2 changed files with 37 additions and 2 deletions

View File

@ -11,7 +11,9 @@
<script type="text/javascript" src="./lib/litegraph.extensions.js" defer></script>
<script type="module">
import { app } from "./scripts/app.js";
app.apiBase = "https://undertake-greek-possibly-mil.trycloudflare.com"
await app.setup();
window.app = app;
window.graph = app.graph;
</script>

View File

@ -1283,10 +1283,43 @@ export class ComfyApp {
async #loadExtensions() {
const extensions = await api.getExtensions();
this.logging.addEntry("Comfy.App", "debug", { Extensions: extensions });
const extensionPromises = extensions.map(async ext => {
try {
await import(api.apiURL(ext));
// Fetch the file as text
const response = await fetch(api.apiURL(ext));
let text = await response.text();
const lines = text.split('\n');
for (const line of lines) {
// Process each line here
if (line.startsWith("import")) {
const match = line.match(/from "(.*)"/);
if (match) {
const importPath = match[1];
if (importPath.startsWith("./")) {
let file = importPath.substring(2);
ext = ext.replace(/[^/]*$/, file)
text = text.replace(line, line.replace(importPath, `${api.apiURL(ext)}`));
}
}
}
}
// text = text.replace(/import { app } from "..\/..\/scripts\/app.js"/, '');
// text = text.replace(/import { app } from "..\/..\/scripts\/api.js"/, '');
// Act on the text here...
// Create a blob from the text
const blob = new Blob([text], { type: 'text/javascript' });
// Create a URL for the blob
const url = URL.createObjectURL(blob);
// Import the module from the blob URL
await import(url);
// await import(api.apiURL(ext));
} catch (error) {
console.error("Error loading extension", ext, error);
}