mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-26 03:25:56 +00:00
Prepare Manager 0.9.2 with database startup and configuration fixes
This commit is contained in:
1 parent
81f031b30f
commit
ce83f04d9d
21 files changed
+470
-83
No files matched your search
+7
-1
@@ -1,4 +1,7 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { updateCheckQueue } from "./updateCheckQueue";
|
||||
|
||||
const queuedUpdateCheck = updateCheckQueue<UpdatePreview>();
|
||||
|
||||
export const REMOTE_CLIENT_ID = "@remote-client";
|
||||
export interface RemoteConnection { host: string; client_path: string | null }
|
||||
@@ -539,7 +542,10 @@ export const api = {
|
||||
createAccount: (id: string, username: string, password: string, administrator: boolean) =>
|
||||
invoke<void>("create_account", { id, username, password, administrator }),
|
||||
/** `background`: the repeating check, which must not start the database of a stopped server. */
|
||||
checkUpdate: (id: string, source?: string, background?: boolean) => invoke<UpdatePreview>("check_update", { id, source: source ?? null, background: background ?? false }),
|
||||
checkUpdate: (id: string, source?: string, background?: boolean) => queuedUpdateCheck(
|
||||
id, JSON.stringify([source ?? null, background ?? false]),
|
||||
() => invoke<UpdatePreview>("check_update", { id, source: source ?? null, background: background ?? false }),
|
||||
),
|
||||
pendingUpdate: (id: string) => invoke<UpdateTxn | null>("pending_update", { id }),
|
||||
applyUpdate: (id: string, resolutions: Record<string, "keep" | "replace">, source?: string) =>
|
||||
invoke<{ txn: UpdateTxn; preexisting_character_count?: number }>("apply_update", { id, source: source ?? null, resolutions }),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
export function updateCheckQueue<T>() {
|
||||
const requests = new Map<string, Promise<T>>();
|
||||
const servers = new Map<string, Promise<unknown>>();
|
||||
return (server: string, request: string, run: () => Promise<T>): Promise<T> => {
|
||||
const key = JSON.stringify([server, request]);
|
||||
const existing = requests.get(key);
|
||||
if (existing) return existing;
|
||||
const previous = servers.get(server) ?? Promise.resolve();
|
||||
const result = previous.catch(() => undefined).then(run);
|
||||
requests.set(key, result);
|
||||
servers.set(server, result);
|
||||
const clear = () => {
|
||||
if (requests.get(key) === result) requests.delete(key);
|
||||
if (servers.get(server) === result) servers.delete(server);
|
||||
};
|
||||
void result.then(clear, clear);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user