mirror of
https://github.com/unraid/api.git
synced 2026-01-02 22:50:02 -06:00
refactor: updateOsActions store with new updateOs store
This commit is contained in:
@@ -9,11 +9,7 @@ import { ACCOUNT_CALLBACK, WEBGUI_TOOLS_UPDATE } from '~/helpers/urls';
|
||||
import { useCallbackStore } from '~/store/callbackActions';
|
||||
// import { useErrorsStore } from '~/store/errors';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import {
|
||||
useUpdateOsStoreGeneric,
|
||||
type Release,
|
||||
type UpdateOsActionStore,
|
||||
} from '~/store/updateOs';
|
||||
import { useUpdateOsStore } from '~/store/updateOs';
|
||||
|
||||
import type { ExternalUpdateOsAction } from '~/store/callback';
|
||||
import type { UserProfileLink } from '~/types/userProfile';
|
||||
@@ -24,22 +20,43 @@ import type { UserProfileLink } from '~/types/userProfile';
|
||||
*/
|
||||
setActivePinia(createPinia());
|
||||
|
||||
export interface Release {
|
||||
version: string; // "6.12.4"
|
||||
name: string; // "Unraid 6.12.4"
|
||||
basefile: string; // "unRAIDServer-6.12.4-x86_64.zip"
|
||||
date: string; // "2023-08-31"
|
||||
url: string; // "https://stable.dl.unraid.net/unRAIDServer-6.12.4-x86_64.zip"
|
||||
changelog: string; // "https://raw.githubusercontent.com/unraid/docs/main/docs/unraid-os/release-notes/6.12.4.md"
|
||||
changelog_pretty: string; // "https://docs.unraid.net/unraid-os/release-notes/6.12.4/"
|
||||
md5: string; // "df6e5859d28c14617efde36d59458206"
|
||||
size: string; // "439999418"
|
||||
sha256: string; // "5ad2d22e8c124e3b925c3bd05f1d782d8521965aabcbedd7dd782db76afd9ace"
|
||||
plugin_url: string; // "https://stable.dl.unraid.net/unRAIDServer-6.12.4.plg"
|
||||
plugin_sha256: string; // "57d2ab6036e663208b3f72298ceb478b937b17e333986e68dcae2696c88ed152"
|
||||
announce_url: string; // "https://unraid.net/blog/6-12-4"
|
||||
}
|
||||
|
||||
export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
const callbackStore = useCallbackStore();
|
||||
// const errorsStore = useErrorsStore();
|
||||
const serverStore = useServerStore();
|
||||
// in this instance we don't need to pass a payload because we're already in the store that would be passed to it
|
||||
const useUpdateOsStore = useUpdateOsStoreGeneric();
|
||||
const updateOsStore = useUpdateOsStore();
|
||||
|
||||
const { install: installPlugin } = useInstallPlugin();
|
||||
|
||||
// State
|
||||
const updateAction = ref<ExternalUpdateOsAction | undefined>();
|
||||
|
||||
const guid = computed(() => serverStore.guid);
|
||||
const inIframe = computed(() => serverStore.inIframe);
|
||||
const keyfile = computed(() => serverStore.keyfile);
|
||||
const osVersion = computed(() => serverStore.osVersion);
|
||||
const osVersionBranch = computed(() => serverStore.osVersionBranch);
|
||||
const regExp = computed(() => serverStore.regExp);
|
||||
const regUpdatesExpired = computed(() => serverStore.regUpdatesExpired);
|
||||
const serverAccountPayload = computed(() => serverStore.serverAccountPayload);
|
||||
|
||||
const updateOsAvailable = computed(() => updateOsStore.available);
|
||||
/** used when coming back from callback, this will be the release to install */
|
||||
const status = ref<'confirming' | 'checking' | 'ineligible' | 'failed' | 'ready' | 'success' | 'updating' | 'downgrading'>('ready');
|
||||
const callbackUpdateRelease = ref<Release | null>(null);
|
||||
@@ -57,14 +74,13 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
const rebootVersion = computed(() => serverStore.rebootVersion);
|
||||
|
||||
const ineligible = computed(() => !serverStore.guid || !serverStore.keyfile || !osVersion.value || regUpdatesExpired.value);
|
||||
const ineligible = computed(() => !guid.value || !keyfile.value || !osVersion.value || regUpdatesExpired.value);
|
||||
const ineligibleText = computed(() => { // translated in components
|
||||
if (!serverStore.guid) {
|
||||
if (!guid.value) {
|
||||
return 'A valid GUID is required to check for OS updates.';
|
||||
}
|
||||
if (!serverStore.keyfile) {
|
||||
if (!keyfile.value) {
|
||||
return 'A valid keyfile is required to check for OS updates.';
|
||||
}
|
||||
if (!osVersion.value) {
|
||||
@@ -73,7 +89,7 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
if (regUpdatesExpired.value) {
|
||||
const base = 'Your {0} license included one year of free updates at the time of purchase. You are now eligible to extend your license and access the latest OS updates.';
|
||||
const addtlText = 'You are still eligible to access OS updates that were published on or before {1}.';
|
||||
return updateOsStore.available ? `${base} ${addtlText}` : base;
|
||||
return updateOsAvailable.value ? `${base} ${addtlText}` : base;
|
||||
}
|
||||
return '';
|
||||
});
|
||||
@@ -85,7 +101,7 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
icon: BellAlertIcon,
|
||||
name: 'updateOs',
|
||||
text: 'Unraid OS {0} Update Available',
|
||||
textParams: [updateOsStore.available],
|
||||
textParams: [updateOsAvailable.value],
|
||||
};
|
||||
});
|
||||
|
||||
@@ -97,19 +113,19 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
ACCOUNT_CALLBACK.toString(),
|
||||
[{
|
||||
server: {
|
||||
...serverStore.serverAccountPayload,
|
||||
...serverAccountPayload.value,
|
||||
},
|
||||
type: 'updateOs',
|
||||
}],
|
||||
serverStore.inIframe ? 'newTab' : undefined,
|
||||
inIframe.value ? 'newTab' : undefined,
|
||||
);
|
||||
},
|
||||
disabled: rebootType.value !== '',
|
||||
external: true,
|
||||
icon: updateOsStore.available ? BellAlertIcon : ArrowPathIcon,
|
||||
icon: updateOsAvailable.value ? BellAlertIcon : ArrowPathIcon,
|
||||
name: 'updateOs',
|
||||
text: updateOsStore.available ? 'Unraid OS {0} Update Available' : 'Check for OS Updates',
|
||||
textParams: [updateOsStore.available],
|
||||
text: updateOsAvailable.value ? 'Unraid OS {0} Update Available' : 'Check for OS Updates',
|
||||
textParams: [updateOsAvailable.value ?? ''],
|
||||
title: rebootType.value !== '' ? rebootTypeText.value : '',
|
||||
};
|
||||
};
|
||||
@@ -119,11 +135,11 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
ACCOUNT_CALLBACK.toString(),
|
||||
[{
|
||||
server: {
|
||||
...serverStore.serverAccountPayload,
|
||||
...serverAccountPayload.value,
|
||||
},
|
||||
type: 'updateOs',
|
||||
}],
|
||||
serverStore.inIframe ? 'newTab' : (autoRedirectReplace ? 'replace' : undefined),
|
||||
inIframe.value ? 'newTab' : (autoRedirectReplace ? 'replace' : undefined),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -157,7 +173,7 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
if (!foundRelease) {
|
||||
throw new Error('Release not found');
|
||||
}
|
||||
if (foundRelease.version === serverStore.osVersion) {
|
||||
if (foundRelease.version === osVersion.value) {
|
||||
throw new Error('Release version is the same as the server\'s current version');
|
||||
}
|
||||
confirmUpdateOs(foundRelease);
|
||||
@@ -206,11 +222,8 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
callbackUpdateRelease,
|
||||
osVersion,
|
||||
osVersionBranch,
|
||||
regExp,
|
||||
regUpdatesExpired,
|
||||
rebootType,
|
||||
rebootTypeText,
|
||||
rebootVersion,
|
||||
status,
|
||||
ineligible,
|
||||
ineligibleText,
|
||||
@@ -228,7 +241,3 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => {
|
||||
getReleaseFromKeyServer,
|
||||
};
|
||||
});
|
||||
|
||||
export const useUpdateOsStore = useUpdateOsStoreGeneric({
|
||||
useUpdateOsActions: useUpdateOsActionsStore as unknown as () => UpdateOsActionStore,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user