mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-09-14 05:25:23 +00:00
Store user settings/data on the server and multi user support (#2160)
* wip per user data * Rename, hide menu * better error rework default user * store pretty * Add userdata endpoints Change nodetemplates to userdata * add multi user message * make normal arg * Fix tests * Ignore user dir * user tests * Changed to default to browser storage and add server-storage arg * fix crash on empty templates * fix settings added before load * ignore parse errors
This commit is contained in:
@@ -1291,10 +1291,92 @@ export class ComfyApp {
|
||||
await Promise.all(extensionPromises);
|
||||
}
|
||||
|
||||
async #migrateSettings() {
|
||||
this.isNewUserSession = true;
|
||||
// Store all current settings
|
||||
const settings = Object.keys(this.ui.settings).reduce((p, n) => {
|
||||
const v = localStorage[`Comfy.Settings.${n}`];
|
||||
if (v) {
|
||||
try {
|
||||
p[n] = JSON.parse(v);
|
||||
} catch (error) {}
|
||||
}
|
||||
return p;
|
||||
}, {});
|
||||
|
||||
await api.storeSettings(settings);
|
||||
}
|
||||
|
||||
async #setUser() {
|
||||
const userConfig = await api.getUserConfig();
|
||||
this.storageLocation = userConfig.storage;
|
||||
if (typeof userConfig.migrated == "boolean") {
|
||||
// Single user mode migrated true/false for if the default user is created
|
||||
if (!userConfig.migrated && this.storageLocation === "server") {
|
||||
// Default user not created yet
|
||||
await this.#migrateSettings();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.multiUserServer = true;
|
||||
let user = localStorage["Comfy.userId"];
|
||||
const users = userConfig.users ?? {};
|
||||
if (!user || !users[user]) {
|
||||
// This will rarely be hit so move the loading to on demand
|
||||
const { UserSelectionScreen } = await import("./ui/userSelection.js");
|
||||
|
||||
this.ui.menuContainer.style.display = "none";
|
||||
const { userId, username, created } = await new UserSelectionScreen().show(users, user);
|
||||
this.ui.menuContainer.style.display = "";
|
||||
|
||||
user = userId;
|
||||
localStorage["Comfy.userName"] = username;
|
||||
localStorage["Comfy.userId"] = user;
|
||||
|
||||
if (created) {
|
||||
api.user = user;
|
||||
await this.#migrateSettings();
|
||||
}
|
||||
}
|
||||
|
||||
api.user = user;
|
||||
|
||||
this.ui.settings.addSetting({
|
||||
id: "Comfy.SwitchUser",
|
||||
name: "Switch User",
|
||||
type: (name) => {
|
||||
let currentUser = localStorage["Comfy.userName"];
|
||||
if (currentUser) {
|
||||
currentUser = ` (${currentUser})`;
|
||||
}
|
||||
return $el("tr", [
|
||||
$el("td", [
|
||||
$el("label", {
|
||||
textContent: name,
|
||||
}),
|
||||
]),
|
||||
$el("td", [
|
||||
$el("button", {
|
||||
textContent: name + (currentUser ?? ""),
|
||||
onclick: () => {
|
||||
delete localStorage["Comfy.userId"];
|
||||
delete localStorage["Comfy.userName"];
|
||||
window.location.reload();
|
||||
},
|
||||
}),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the app on the page
|
||||
*/
|
||||
async setup() {
|
||||
await this.#setUser();
|
||||
await this.ui.settings.load();
|
||||
await this.#loadExtensions();
|
||||
|
||||
// Create and mount the LiteGraph in the DOM
|
||||
|
Reference in New Issue
Block a user