Add better api logging

This commit is contained in:
Lucas Sköld
2024-07-29 11:37:36 +02:00
parent bef99a79bd
commit fa28a670e7
2 changed files with 26 additions and 7 deletions
+3
View File
@@ -391,6 +391,9 @@ async def add_lora_loaders(request):
new_unique_loaders = [loader for loader in new_loaders if tuple(loader) not in existing_loaders_set]
data["loraLoaders"].extend(new_unique_loaders)
if len(new_unique_loaders) == 0:
return web.json_response({"message": "No new lora loaders added."})
# Write the updated JSON data back to the file
with open(json_path, "w") as file:
json.dump(data, file, indent=4)
+23 -7
View File
@@ -2,6 +2,28 @@ import { SettingUtils } from './sn0w.js';
import { app } from '../../../scripts/app.js';
import { api } from '../../../scripts/api.js';
async function addLoraLoaders(loraLoaders) {
try {
const response = await api.fetchApi(`${SettingUtils.API_PREFIX}/add_lora_loaders`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(loraLoaders),
})
if (!response.ok) {
const errorData = await response.json();
throw new Error(`[sn0w] ${response.status} ${response.statusText} - ${errorData.error}`);
}
const data = await response.json();
console.log("[sn0w]", data.message);
} catch (error) {
console.error("[sn0w]", error.message);
}
}
const id = 'sn0w.HighlightFavourite';
const settingDefinition = {
id,
@@ -45,13 +67,7 @@ app.registerExtension({
// Combine the existing custom loaders with the fetched ones
loraLoaders = loraLoaders.concat(...customLoraLoadersArrays);
const apiRequest = await api.fetchApi(`${SettingUtils.API_PREFIX}/add_lora_loaders`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(loraLoaders),
})
addLoraLoaders(loraLoaders);
const original_getNodeMenuOptions = app.canvas.getNodeMenuOptions;
app.canvas.getNodeMenuOptions = function (node) {