diff --git a/javascript/_utils.js b/javascript/_utils.js index 06810db..863b4d3 100644 --- a/javascript/_utils.js +++ b/javascript/_utils.js @@ -38,7 +38,10 @@ function parseCSV(str) { } // Load file -async function readFile(filePath, json = false) { +async function readFile(filePath, json = false, cache = false) { + if (!cache) + filePath += `?${new Date().getTime()}`; + let response = await fetch(`file=${filePath}`); if (response.status != 200) { diff --git a/javascript/ext_embeddings.js b/javascript/ext_embeddings.js index ca83c9e..15070b7 100644 --- a/javascript/ext_embeddings.js +++ b/javascript/ext_embeddings.js @@ -35,7 +35,7 @@ class EmbeddingParser extends BaseTagParser { async function load() { if (embeddings.length === 0) { try { - embeddings = (await readFile(`${tagBasePath}/temp/emb.txt?${new Date().getTime()}`)).split("\n") + embeddings = (await readFile(`${tagBasePath}/temp/emb.txt`)).split("\n") .filter(x => x.trim().length > 0) // Remove empty lines .map(x => x.trim().split(",")); // Split into name, version type pairs } catch (e) { diff --git a/javascript/ext_hypernets.js b/javascript/ext_hypernets.js index 8e011cf..9b5dd4c 100644 --- a/javascript/ext_hypernets.js +++ b/javascript/ext_hypernets.js @@ -27,7 +27,7 @@ class HypernetParser extends BaseTagParser { async function load() { if (hypernetworks.length === 0) { try { - hypernetworks = (await readFile(`${tagBasePath}/temp/hyp.txt?${new Date().getTime()}`)).split("\n") + hypernetworks = (await readFile(`${tagBasePath}/temp/hyp.txt`)).split("\n") .filter(x => x.trim().length > 0) //Remove empty lines .map(x => x.trim()); // Remove carriage returns and padding if it exists } catch (e) { diff --git a/javascript/ext_loras.js b/javascript/ext_loras.js index 9279185..a9b7051 100644 --- a/javascript/ext_loras.js +++ b/javascript/ext_loras.js @@ -27,7 +27,7 @@ class LoraParser extends BaseTagParser { async function load() { if (loras.length === 0) { try { - loras = (await readFile(`${tagBasePath}/temp/lora.txt?${new Date().getTime()}`)).split("\n") + loras = (await readFile(`${tagBasePath}/temp/lora.txt`)).split("\n") .filter(x => x.trim().length > 0) // Remove empty lines .map(x => x.trim()); // Remove carriage returns and padding if it exists } catch (e) { diff --git a/javascript/ext_umi.js b/javascript/ext_umi.js index c476e7b..9384e97 100644 --- a/javascript/ext_umi.js +++ b/javascript/ext_umi.js @@ -205,7 +205,7 @@ function updateUmiTags( tagType, sanitizedText, newPrompt, textArea) { async function load() { if (yamlWildcards.length === 0) { try { - let yamlTags = (await readFile(`${tagBasePath}/temp/wcet.txt?${new Date().getTime()}`)).split("\n"); + let yamlTags = (await readFile(`${tagBasePath}/temp/wcet.txt`)).split("\n"); // Split into tag, count pairs yamlWildcards = yamlTags.map(x => x .trim() diff --git a/javascript/ext_wildcards.js b/javascript/ext_wildcards.js index f976449..22a2944 100644 --- a/javascript/ext_wildcards.js +++ b/javascript/ext_wildcards.js @@ -17,7 +17,7 @@ class WildcardParser extends BaseTagParser { // Use found wildcard file or look in external wildcard files let wcPair = wcFound || wildcardExtFiles.find(x => x[1].toLowerCase() === wcFile); - let wildcards = (await readFile(`${wcPair[0]}/${wcPair[1]}.txt?${new Date().getTime()}`)).split("\n") + let wildcards = (await readFile(`${wcPair[0]}/${wcPair[1]}.txt`)).split("\n") .filter(x => x.trim().length > 0 && !x.startsWith('#')); // Remove empty lines and comments let finalResults = []; @@ -58,14 +58,14 @@ class WildcardFileParser extends BaseTagParser { async function load() { if (wildcardFiles.length === 0 && wildcardExtFiles.length === 0) { try { - let wcFileArr = (await readFile(`${tagBasePath}/temp/wc.txt?${new Date().getTime()}`)).split("\n"); + let wcFileArr = (await readFile(`${tagBasePath}/temp/wc.txt`)).split("\n"); let wcBasePath = wcFileArr[0].trim(); // First line should be the base path wildcardFiles = wcFileArr.slice(1) .filter(x => x.trim().length > 0) // Remove empty lines .map(x => [wcBasePath, x.trim().replace(".txt", "")]); // Remove file extension & newlines // To support multiple sources, we need to separate them using the provided "-----" strings - let wcExtFileArr = (await readFile(`${tagBasePath}/temp/wce.txt?${new Date().getTime()}`)).split("\n"); + let wcExtFileArr = (await readFile(`${tagBasePath}/temp/wce.txt`)).split("\n"); let splitIndices = []; for (let index = 0; index < wcExtFileArr.length; index++) { if (wcExtFileArr[index].trim() === "-----") { diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index 89007b2..d6b54dc 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -87,14 +87,14 @@ async function loadTags(c) { // Load main tags and aliases if (allTags.length === 0 && c.tagFile && c.tagFile !== "None") { try { - allTags = await loadCSV(`${tagBasePath}/${c.tagFile}?${new Date().getTime()}`); + allTags = await loadCSV(`${tagBasePath}/${c.tagFile}`); } catch (e) { console.error("Error loading tags file: " + e); return; } if (c.extra.extraFile && c.extra.extraFile !== "None") { try { - extras = await loadCSV(`${tagBasePath}/${c.extra.extraFile}?${new Date().getTime()}`); + extras = await loadCSV(`${tagBasePath}/${c.extra.extraFile}`); if (c.extra.onlyAliasExtraFile) { // This works purely on index, so it's not very robust. But a lot faster. for (let i = 0, n = extras.length; i < n; i++) { @@ -135,7 +135,7 @@ async function loadTags(c) { async function loadTranslations(c) { if (c.translation.translationFile && c.translation.translationFile !== "None") { try { - let tArray = await loadCSV(`${tagBasePath}/${c.translation.translationFile}?${new Date().getTime()}`); + let tArray = await loadCSV(`${tagBasePath}/${c.translation.translationFile}`); tArray.forEach(t => { if (c.translation.oldFormat) translations.set(t[0], t[2]); @@ -781,7 +781,7 @@ function navigateInList(textArea, event) { // One-time setup, triggered from onUiUpdate async function setup() { // Load colors - CFG["colors"] = (await readFile(`${tagBasePath}/colors.json?${new Date().getTime()}`, true)); + CFG["colors"] = (await readFile(`${tagBasePath}/colors.json`, true)); // Load external files needed by completion extensions await processQueue(QUEUE_FILE_LOAD, null); @@ -909,7 +909,7 @@ onUiUpdate(async () => { if (CFG) return; // Get our tag base path from the temp file - tagBasePath = await readFile(`tmp/tagAutocompletePath.txt?${new Date().getTime()}`); + tagBasePath = await readFile(`tmp/tagAutocompletePath.txt`); // Load config from webui opts await syncOptions(); // Rest of setup