Extract file load to queue

This enables other parsers to keep their load function in the same file
This commit is contained in:
Dominik Reh
2023-02-10 11:55:56 +01:00
parent 890f1a48c2
commit cbeced9121
8 changed files with 119 additions and 94 deletions

View File

@@ -32,4 +32,19 @@ class EmbeddingParser extends BaseTagParser {
}
}
PARSERS.push(new EmbeddingParser(EMB_TRIGGER));
async function load() {
if (embeddings.length === 0) {
try {
embeddings = (await readFile(`${tagBasePath}/temp/emb.txt?${new Date().getTime()}`)).split("\n")
.filter(x => x.trim().length > 0) // Remove empty lines
.map(x => x.trim().split(",")); // Split into name, version type pairs
} catch (e) {
console.error("Error loading embeddings.txt: " + e);
}
}
}
PARSERS.push(new EmbeddingParser(EMB_TRIGGER));
// Add load function to the queue
QUEUE_FILE_LOAD.push(load);