From d1eea880f3c5dacc1d357b7dc439809d43c91e4a Mon Sep 17 00:00:00 2001 From: DominikDoom Date: Sat, 13 Apr 2024 17:27:10 +0200 Subject: [PATCH] Rename API call functions on JS side to prevent name conflicts Fixes #282 --- javascript/_utils.js | 20 ++++++++++---------- javascript/ext_loras.js | 2 +- javascript/ext_lycos.js | 2 +- javascript/ext_wildcards.js | 2 +- javascript/tagAutocomplete.js | 10 +++++----- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/javascript/_utils.js b/javascript/_utils.js index f44aff2..c72ab2a 100644 --- a/javascript/_utils.js +++ b/javascript/_utils.js @@ -61,7 +61,7 @@ async function loadCSV(path) { } // Fetch API -async function fetchAPI(url, json = true, cache = false) { +async function fetchTacAPI(url, json = true, cache = false) { if (!cache) { const appendChar = url.includes("?") ? "&" : "?"; url += `${appendChar}${new Date().getTime()}` @@ -80,7 +80,7 @@ async function fetchAPI(url, json = true, cache = false) { return await response.text(); } -async function postAPI(url, body = null) { +async function postTacAPI(url, body = null) { let response = await fetch(url, { method: "POST", headers: {'Content-Type': 'application/json'}, @@ -95,7 +95,7 @@ async function postAPI(url, body = null) { return await response.json(); } -async function putAPI(url, body = null) { +async function putTacAPI(url, body = null) { let response = await fetch(url, { method: "PUT", body: body }); if (response.status != 200) { @@ -107,8 +107,8 @@ async function putAPI(url, body = null) { } // Extra network preview thumbnails -async function getExtraNetworkPreviewURL(filename, type) { - const previewJSON = await fetchAPI(`tacapi/v1/thumb-preview/${filename}?type=${type}`, true, true); +async function getTacExtraNetworkPreviewURL(filename, type) { + const previewJSON = await fetchTacAPI(`tacapi/v1/thumb-preview/${filename}?type=${type}`, true, true); if (previewJSON?.url) { const properURL = `sd_extra_networks/thumb?filename=${previewJSON.url}`; if ((await fetch(properURL)).status == 200) { @@ -237,24 +237,24 @@ function mapUseCountArray(useCounts, posAndNeg = false) { } // Call API endpoint to increase bias of tag in the database function increaseUseCount(tagName, type, negative = false) { - postAPI(`tacapi/v1/increase-use-count?tagname=${tagName}&ttype=${type}&neg=${negative}`); + postTacAPI(`tacapi/v1/increase-use-count?tagname=${tagName}&ttype=${type}&neg=${negative}`); } // Get use count of tag from the database async function getUseCount(tagName, type, negative = false) { - return (await fetchAPI(`tacapi/v1/get-use-count?tagname=${tagName}&ttype=${type}&neg=${negative}`, true, false))["result"]; + return (await fetchTacAPI(`tacapi/v1/get-use-count?tagname=${tagName}&ttype=${type}&neg=${negative}`, true, false))["result"]; } async function getUseCounts(tagNames, types, negative = false) { // While semantically weird, we have to use POST here for the body, as urls are limited in length const body = JSON.stringify({"tagNames": tagNames, "tagTypes": types, "neg": negative}); - const rawArray = (await postAPI(`tacapi/v1/get-use-count-list`, body))["result"] + const rawArray = (await postTacAPI(`tacapi/v1/get-use-count-list`, body))["result"] return mapUseCountArray(rawArray); } async function getAllUseCounts() { - const rawArray = (await fetchAPI(`tacapi/v1/get-all-use-counts`))["result"]; + const rawArray = (await fetchTacAPI(`tacapi/v1/get-all-use-counts`))["result"]; return mapUseCountArray(rawArray, true); } async function resetUseCount(tagName, type, resetPosCount, resetNegCount) { - await putAPI(`tacapi/v1/reset-use-count?tagname=${tagName}&ttype=${type}&pos=${resetPosCount}&neg=${resetNegCount}`); + await putTacAPI(`tacapi/v1/reset-use-count?tagname=${tagName}&ttype=${type}&pos=${resetPosCount}&neg=${resetNegCount}`); } function createTagUsageTable(tagCounts) { diff --git a/javascript/ext_loras.js b/javascript/ext_loras.js index da01d24..fc67a3e 100644 --- a/javascript/ext_loras.js +++ b/javascript/ext_loras.js @@ -50,7 +50,7 @@ async function load() { async function sanitize(tagType, text) { if (tagType === ResultType.lora) { let multiplier = TAC_CFG.extraNetworksDefaultMultiplier; - let info = await fetchAPI(`tacapi/v1/lora-info/${text}`) + let info = await fetchTacAPI(`tacapi/v1/lora-info/${text}`) if (info && info["preferred weight"]) { multiplier = info["preferred weight"]; } diff --git a/javascript/ext_lycos.js b/javascript/ext_lycos.js index 0e4ee3c..1342efd 100644 --- a/javascript/ext_lycos.js +++ b/javascript/ext_lycos.js @@ -50,7 +50,7 @@ async function load() { async function sanitize(tagType, text) { if (tagType === ResultType.lyco) { let multiplier = TAC_CFG.extraNetworksDefaultMultiplier; - let info = await fetchAPI(`tacapi/v1/lyco-info/${text}`) + let info = await fetchTacAPI(`tacapi/v1/lyco-info/${text}`) if (info && info["preferred weight"]) { multiplier = info["preferred weight"]; } diff --git a/javascript/ext_wildcards.js b/javascript/ext_wildcards.js index 98c365a..515e982 100644 --- a/javascript/ext_wildcards.js +++ b/javascript/ext_wildcards.js @@ -38,7 +38,7 @@ class WildcardParser extends BaseTagParser { } wildcards = wildcards.concat(getDescendantProp(yamlWildcards[basePath], fileName)); } else { - const fileContent = (await fetchAPI(`tacapi/v1/wildcard-contents?basepath=${basePath}&filename=${fileName}.txt`, false)) + const fileContent = (await fetchTacAPI(`tacapi/v1/wildcard-contents?basepath=${basePath}&filename=${fileName}.txt`, false)) .split("\n") .filter(x => x.trim().length > 0 && !x.startsWith('#')); // Remove empty lines and comments wildcards = wildcards.concat(fileContent); diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index e29a983..35b01e1 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -552,7 +552,7 @@ async function insertTextAtCursor(textArea, result, tagword, tabCompletedWithout let keywords = null; // Check built-in activation words first if (tagType === ResultType.lora || tagType === ResultType.lyco) { - let info = await fetchAPI(`tacapi/v1/lora-info/${result.text}`) + let info = await fetchTacAPI(`tacapi/v1/lora-info/${result.text}`) if (info && info["activation text"]) { keywords = info["activation text"]; } @@ -564,7 +564,7 @@ async function insertTextAtCursor(textArea, result, tagword, tabCompletedWithout // No match, try to find a sha256 match from the cache file if (!nameDict) { - const sha256 = await fetchAPI(`/tacapi/v1/lora-cached-hash/${result.text}`) + const sha256 = await fetchTacAPI(`/tacapi/v1/lora-cached-hash/${result.text}`) if (sha256) { nameDict = modelKeywordDict.get(sha256); } @@ -887,7 +887,7 @@ async function updateSelectionStyle(textArea, newIndex, oldIndex) { let img = previewDiv.querySelector("img"); - let url = await getExtraNetworkPreviewURL(selectedFilename, shorthandType); + let url = await getTacExtraNetworkPreviewURL(selectedFilename, shorthandType); if (url) { img.src = url; previewDiv.style.display = "block"; @@ -1361,7 +1361,7 @@ async function refreshTacTempFiles(api = false) { } if (api) { - await postAPI("tacapi/v1/refresh-temp-files"); + await postTacAPI("tacapi/v1/refresh-temp-files"); await reload(); } else { setTimeout(async () => { @@ -1371,7 +1371,7 @@ async function refreshTacTempFiles(api = false) { } async function refreshEmbeddings() { - await postAPI("tacapi/v1/refresh-embeddings", null); + await postTacAPI("tacapi/v1/refresh-embeddings", null); embeddings = []; await processQueue(QUEUE_FILE_LOAD, null); console.log("TAC: Refreshed embeddings");