feat: Implement usage statistics tracking with backend integration and route setup

This commit is contained in:
Will Miao
2025-04-22 08:56:34 +08:00
parent b395d3f487
commit b12079e0f6
5 changed files with 363 additions and 4 deletions

View File

@@ -0,0 +1,37 @@
// ComfyUI extension to track model usage statistics
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
// Register the extension
app.registerExtension({
name: "ComfyUI-Lora-Manager.UsageStats",
init() {
// Listen for successful executions
api.addEventListener("execution_success", ({ detail }) => {
if (detail && detail.prompt_id) {
this.updateUsageStats(detail.prompt_id);
}
});
},
async updateUsageStats(promptId) {
try {
console.log("Updating usage statistics for prompt ID:", promptId);
// Call backend endpoint with the prompt_id
const response = await fetch(`/loras/api/update-usage-stats`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt_id: promptId }),
});
if (!response.ok) {
console.warn("Failed to update usage statistics:", response.statusText);
}
} catch (error) {
console.error("Error updating usage statistics:", error);
}
}
});