feat(api,userbot,frontend): add accounts from the web ui and isolate per-account settings
This commit is contained in:
1 parent
92fd20137e
commit
9c265af3d3
19 files changed
+917
-268
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { browser } from "$app/environment";
|
||||
import { listAccounts } from "$lib/api/endpoints";
|
||||
import { listAccounts, logoutAccount } from "$lib/api/endpoints";
|
||||
import type { Account } from "$lib/api/types";
|
||||
|
||||
const STORAGE_KEY = "bg.account";
|
||||
@@ -32,6 +32,22 @@ function createAccounts() {
|
||||
}
|
||||
}
|
||||
|
||||
function select(id: number | null) {
|
||||
selectedId = id;
|
||||
persist(id);
|
||||
}
|
||||
|
||||
async function load() {
|
||||
list = await listAccounts();
|
||||
loaded = true;
|
||||
const exists = list.some((account) => account.account_id === selectedId);
|
||||
if (!exists) {
|
||||
const fallback =
|
||||
list.find((account) => account.is_active) ?? list.at(0) ?? null;
|
||||
select(fallback ? fallback.account_id : null);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
get list() {
|
||||
return list;
|
||||
@@ -45,20 +61,14 @@ function createAccounts() {
|
||||
get loaded() {
|
||||
return loaded;
|
||||
},
|
||||
async load() {
|
||||
list = await listAccounts();
|
||||
loaded = true;
|
||||
const exists = list.some((account) => account.account_id === selectedId);
|
||||
if (!exists) {
|
||||
const fallback =
|
||||
list.find((account) => account.is_active) ?? list.at(0) ?? null;
|
||||
selectedId = fallback ? fallback.account_id : null;
|
||||
persist(selectedId);
|
||||
load,
|
||||
select,
|
||||
async logout(id: number) {
|
||||
await logoutAccount(id);
|
||||
if (id === selectedId) {
|
||||
select(null);
|
||||
}
|
||||
},
|
||||
select(id: number) {
|
||||
selectedId = id;
|
||||
persist(id);
|
||||
await load();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user