mirror of
https://github.com/unraid/api.git
synced 2026-01-05 16:09:49 -06:00
fix: authAction server getter
This commit is contained in:
@@ -47,7 +47,7 @@ const serverState = {
|
||||
lanIp: '192.168.0.1',
|
||||
locale: 'en',
|
||||
pluginInstalled: false,
|
||||
registered: false,
|
||||
registered: true,
|
||||
site: 'http://localhost:4321',
|
||||
state,
|
||||
uptime,
|
||||
|
||||
@@ -2,30 +2,12 @@
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ExclamationTriangleIcon } from '@heroicons/vue/24/solid';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import type { ServerStateDataAction } from '~/types/server';
|
||||
import 'tailwindcss/tailwind.css';
|
||||
import '~/assets/main.css';
|
||||
|
||||
export interface Props {
|
||||
phpRegistered?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
phpRegistered: false,
|
||||
});
|
||||
|
||||
const serverStore = useServerStore();
|
||||
const { registered, stateData } = storeToRefs(serverStore);
|
||||
const { authAction, stateData } = storeToRefs(serverStore);
|
||||
|
||||
// rely on prop before the pinia state kicks in
|
||||
const computedRegistered = computed(() => registered.value === undefined ? !!props.phpRegistered : registered.value);
|
||||
|
||||
// Intended to retrieve sign in and sign out from actions
|
||||
const accountAction = computed((): ServerStateDataAction | undefined => {
|
||||
const allowed = ['signIn', 'signOut'];
|
||||
if (!stateData.value.actions) return;
|
||||
return stateData.value.actions.find(action => allowed.includes(action.name));
|
||||
});
|
||||
// @todo use callback url
|
||||
const stateDataErrorAction = computed(() => {
|
||||
return {
|
||||
@@ -39,7 +21,7 @@ const stateDataErrorAction = computed(() => {
|
||||
|
||||
const button = computed(() => {
|
||||
if (stateData.value.error) return stateDataErrorAction.value;
|
||||
return accountAction.value;
|
||||
return authAction.value;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const { keyActions } = storeToRefs(useServerStore());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="keyActions">
|
||||
<div v-if="keyActions" class="flex flex-col gap-y-8px">
|
||||
<component
|
||||
v-for="action in keyActions" :key="action.name"
|
||||
:is="action.click ? 'button' : 'a'"
|
||||
@@ -21,7 +21,7 @@ const { keyActions } = storeToRefs(useServerStore());
|
||||
<component v-if="action.icon" :is="action.icon" class="flex-shrink-0 w-14px" />
|
||||
{{ action.text }}
|
||||
</component>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="postcss">
|
||||
|
||||
@@ -91,49 +91,59 @@ export const useServerStore = defineStore('server', () => {
|
||||
name: 'signOut',
|
||||
text: 'Sign Out of Unraid.net',
|
||||
};
|
||||
const stateDataDefault: ServerStateData = {
|
||||
actions: [
|
||||
// sign in
|
||||
...(registered.value ? [] : [signInAction]),
|
||||
{
|
||||
click: () => { console.debug('purchase') },
|
||||
external: true,
|
||||
icon: KeyIcon,
|
||||
name: 'purchase',
|
||||
text: 'Purchase Key',
|
||||
},
|
||||
// sign out,
|
||||
...(registered.value ? [signOutAction] : []),
|
||||
],
|
||||
humanReadable: 'Trial',
|
||||
heading: 'Thank you for choosing Unraid OS!',
|
||||
message: '[Temp] Your Trial Key includes all the features of a Pro Key',
|
||||
};
|
||||
|
||||
const stateDataDefault = computed((): ServerStateData => {
|
||||
return {
|
||||
actions: [
|
||||
// sign in
|
||||
...(registered.value ? [] : [signInAction]),
|
||||
{
|
||||
click: () => { console.debug('purchase') },
|
||||
external: true,
|
||||
icon: KeyIcon,
|
||||
name: 'purchase',
|
||||
text: 'Purchase Key',
|
||||
},
|
||||
{
|
||||
click: () => { console.debug('redeem') },
|
||||
external: true,
|
||||
icon: KeyIcon,
|
||||
name: 'redeem',
|
||||
text: 'Redeem Activation Code',
|
||||
},
|
||||
// sign out,
|
||||
...(registered.value ? [signOutAction] : []),
|
||||
],
|
||||
humanReadable: 'Trial',
|
||||
heading: 'Thank you for choosing Unraid OS!',
|
||||
message: '[Temp] Your Trial Key includes all the features of a Pro Key',
|
||||
};
|
||||
});
|
||||
const stateData = computed(():ServerStateData => {
|
||||
switch (state.value) {
|
||||
case 'TRIAL':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
};
|
||||
case 'EEXPIRED':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
};
|
||||
case 'BASIC':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
};
|
||||
case 'PLUS':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
};
|
||||
case 'PRO':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
};
|
||||
case 'EGUID':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -142,7 +152,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'EGUID1':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -151,7 +161,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'ENOKEYFILE2':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -160,7 +170,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'ETRIAL':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -169,7 +179,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'ENOKEYFILE1':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -185,7 +195,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
case 'ENOFLASH6':
|
||||
case 'ENOFLASH7':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -194,7 +204,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'EBLACKLISTED':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -203,7 +213,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'EBLACKLISTED1':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -212,7 +222,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'EBLACKLISTED2':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -221,7 +231,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
case 'ENOCONN':
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
error: {
|
||||
heading: `${state.value} temp heading`,
|
||||
message: `${state.value} temp message – this is an error message`,
|
||||
@@ -230,13 +240,13 @@ export const useServerStore = defineStore('server', () => {
|
||||
};
|
||||
default:
|
||||
return {
|
||||
...stateDataDefault,
|
||||
...stateDataDefault.value,
|
||||
};
|
||||
}
|
||||
});
|
||||
const authActionsNames = ['signIn', 'signOut'];
|
||||
// Extract sign in / out from actions so we can display seperately as needed
|
||||
const authActions = computed((): ServerStateDataAction | undefined => {
|
||||
const authAction = computed((): ServerStateDataAction | undefined => {
|
||||
if (!stateData.value.actions) return;
|
||||
return stateData.value.actions.find(action => authActionsNames.includes(action.name));
|
||||
});
|
||||
@@ -295,7 +305,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
uptime,
|
||||
username,
|
||||
// getters
|
||||
authActions,
|
||||
authAction,
|
||||
isRemoteAccess,
|
||||
keyActions,
|
||||
pluginOutdated,
|
||||
|
||||
Reference in New Issue
Block a user