feat(web): restart unraid-api after sign out

This commit is contained in:
Zack Spear
2023-09-05 15:22:29 -07:00
parent 83e2b495c5
commit 389da7a7fd
4 changed files with 14 additions and 4 deletions

View File

@@ -40,7 +40,7 @@ export const WebguiState = request.url('/plugins/dynamix.my.servers/data/server-
*/
export interface WebguiUnraidApiCommandPayload {
csrf_token: string;
command: 'report' | 'start';
command: 'report' | 'restart' | 'start';
param1?: '-v'|'-vv';
}
export const WebguiUnraidApiCommand = async (payload: WebguiUnraidApiCommandPayload) => {

View File

@@ -211,6 +211,8 @@ export const useAccountStore = defineStore('account', () => {
console.debug('[connectSignOutMutation]', res);
accountActionStatus.value = 'success';
setQueueConnectSignOut(false); // reset
// Restarting the unraid api client to see if this helps remedy the unpredictable issue of needing to sign in twice
unraidApiStore.restartUnraidApiClient();
});
onError((error) => {

View File

@@ -719,10 +719,14 @@ export const useServerStore = defineStore('server', () => {
const mutateServerStateFromApi = (data: serverStateQuery): Server => {
const mutatedData = {
// if we get an owners obj back and the username is root we don't want to overwrite the values
...(data.owner && data.owner.username !== 'root' && {
...(data.owner && data.owner.username !== 'root' ? {
// avatar: data.owner.avatar,
username: data.owner.username,
registered: true,
} : { // handles sign outs
// avatar: data.owner.avatar,
username: '',
registered: false,
}),
name: (data.info && data.info.os) ? data.info.os.hostname : null,
keyfile: (data.registration && data.registration.keyFile) ? data.registration.keyFile.contents : null,

View File

@@ -168,13 +168,17 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
unraidApiClient.value = undefined;
unraidApiStatus.value = 'offline';
};
/**
* Can both start and restart the unraid-api depending on it's current status
*/
const restartUnraidApiClient = async () => {
const command = unraidApiStatus.value === 'offline' ? 'start' : 'restart';
console.debug('[restartUnraidApiClient]', { command });
unraidApiStatus.value = 'restarting';
try {
const response = await WebguiUnraidApiCommand({
csrf_token: serverStore.csrf,
command: 'start',
command,
});
console.debug('[restartUnraidApiClient] response', response);
return setTimeout(() => {