mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 22:52:12 -03:00
feat: Implement usage statistics tracking with backend integration and route setup
This commit is contained in:
37
web/comfyui/usage_stats.js
Normal file
37
web/comfyui/usage_stats.js
Normal 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user