mirror of
https://github.com/unraid/api.git
synced 2026-03-09 02:39:52 -05:00
wip: update os via upc
This commit is contained in:
@@ -7,6 +7,7 @@ import { useCallbackStore } from '~/store/callbackActions';
|
||||
import { useDropdownStore } from '~/store/dropdown';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import { useThemeStore } from '~/store/theme';
|
||||
import { useUpdateOsStore } from '~/store/updateOs';
|
||||
import type { Server } from '~/types/server';
|
||||
import 'tailwindcss/tailwind.css';
|
||||
import '~/assets/main.css';
|
||||
@@ -21,6 +22,7 @@ const { t } = useI18n();
|
||||
const callbackStore = useCallbackStore();
|
||||
const dropdownStore = useDropdownStore();
|
||||
const serverStore = useServerStore();
|
||||
const updateOsStore = useUpdateOsStore();
|
||||
|
||||
const { dropdownVisible } = storeToRefs(dropdownStore);
|
||||
const { name, description, lanIp, state, connectPluginInstalled } = storeToRefs(serverStore);
|
||||
@@ -73,6 +75,7 @@ onBeforeMount(() => {
|
||||
}
|
||||
|
||||
callbackStore.watcher();
|
||||
updateOsStore.checkForOsUpdate();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ACCOUNT, CONNECT_DASHBOARD, PLUGIN_SETTINGS } from '~/helpers/urls';
|
||||
import { useErrorsStore } from '~/store/errors';
|
||||
// import { usePromoStore } from '~/store/promo';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import { useUpdateOsStore } from '~/store/updateOs';
|
||||
import type { UserProfileLink } from '~/types/userProfile';
|
||||
|
||||
const props = defineProps<{ t: any; }>();
|
||||
@@ -13,8 +14,9 @@ const props = defineProps<{ t: any; }>();
|
||||
const errorsStore = useErrorsStore();
|
||||
// const promoStore = usePromoStore();
|
||||
|
||||
const { keyActions, connectPluginInstalled, registered, stateData } = storeToRefs(useServerStore());
|
||||
const { errors } = storeToRefs(errorsStore);
|
||||
const { keyActions, connectPluginInstalled, registered, stateData } = storeToRefs(useServerStore());
|
||||
const { updateAvailable, initUpdateOsCallback } = storeToRefs(useUpdateOsStore());
|
||||
|
||||
const signInAction = computed(() => stateData.value.actions?.filter((act: { name: string; }) => act.name === 'signIn') ?? []);
|
||||
const signOutAction = computed(() => stateData.value.actions?.filter((act: { name: string; }) => act.name === 'signOut') ?? []);
|
||||
@@ -24,7 +26,7 @@ const links = computed(():UserProfileLink[] => {
|
||||
...(registered.value && connectPluginInstalled.value
|
||||
? [
|
||||
{
|
||||
emphasize: true,
|
||||
emphasize: !updateAvailable.value, // only emphasize when we don't have an update available
|
||||
external: true,
|
||||
href: CONNECT_DASHBOARD.toString(),
|
||||
icon: ArrowTopRightOnSquareIcon,
|
||||
@@ -91,6 +93,12 @@ const showKeyline = computed(() => showConnectStatus.value && (keyActions.value?
|
||||
<UpcKeyline />
|
||||
</li>
|
||||
|
||||
<template v-if="updateAvailable">
|
||||
<li>
|
||||
<UpcDropdownItem :item="initUpdateOsCallback" :t="t" />
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<template v-if="keyActions">
|
||||
<li v-for="action in keyActions" :key="action.name">
|
||||
<UpcDropdownItem :item="action" :t="t" />
|
||||
|
||||
@@ -16,6 +16,8 @@ const PURCHASE_CALLBACK = new URL('/c', UNRAID_NET);
|
||||
const SETTINGS_MANAGMENT_ACCESS = new URL('/Settings/ManagementAccess', window.location.origin);
|
||||
const PLUGIN_SETTINGS = new URL('#UnraidNetSettings', SETTINGS_MANAGMENT_ACCESS);
|
||||
|
||||
const OS_RELEASES = new URL('https://s3.amazonaws.com/dnld.lime-technology.com/stable/releases.json');
|
||||
|
||||
export {
|
||||
ACCOUNT,
|
||||
ACCOUNT_CALLBACK,
|
||||
@@ -28,4 +30,5 @@ export {
|
||||
PURCHASE_CALLBACK,
|
||||
PLUGIN_SETTINGS,
|
||||
SETTINGS_MANAGMENT_ACCESS,
|
||||
OS_RELEASES,
|
||||
};
|
||||
|
||||
@@ -202,5 +202,6 @@
|
||||
"Signing In": "Signing In",
|
||||
"Signing Out": "Signing Out",
|
||||
"Sign In requires the local unraid-api to be running": "Sign In requires the local unraid-api to be running",
|
||||
"Sign Out requires the local unraid-api to be running": "Sign Out requires the local unraid-api to be running"
|
||||
"Sign Out requires the local unraid-api to be running": "Sign Out requires the local unraid-api to be running",
|
||||
"Unraid OS Update Available": "Unraid OS Update Available"
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { parse } from 'dotenv';
|
||||
const envConfig = parse(readFileSync('.env'));
|
||||
for (const k in envConfig) {
|
||||
process.env[k] = envConfig[k];
|
||||
}
|
||||
|
||||
console.log('\n');
|
||||
console.log('==============================');
|
||||
console.log('========= ENV VALUES =========');
|
||||
console.log('==============================');
|
||||
console.log('[ACCOUNT URL]', process.env.VITE_ACCOUNT);
|
||||
console.log('[CONNECT URL]', process.env.VITE_CONNECT);
|
||||
console.log('[UNRAID.NET URL]', process.env.VITE_UNRAID_NET);
|
||||
for (const k in envConfig) {
|
||||
process.env[k] = envConfig[k];
|
||||
console.log(`[${k}]`, process.env[k]);
|
||||
}
|
||||
console.log('==============================');
|
||||
console.log('\n');
|
||||
|
||||
@@ -63,7 +60,7 @@ export default defineNuxtConfig({
|
||||
build: {
|
||||
minify: 'terser',
|
||||
terserOptions: {
|
||||
mangle: {
|
||||
mangle: process.env.VITE_ALLOW_CONSOLE_LOGS ? false : {
|
||||
reserved: terserReservations(charsToReserve),
|
||||
toplevel: true,
|
||||
},
|
||||
|
||||
903
web/package-lock.json
generated
903
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -49,6 +49,7 @@
|
||||
"graphql-tag": "^2.12.6",
|
||||
"graphql-ws": "^5.14.0",
|
||||
"hex-to-rgba": "^2.0.1",
|
||||
"semver": "^7.5.4",
|
||||
"vue-i18n": "^9.2.2",
|
||||
"wretch": "^2.6.0"
|
||||
},
|
||||
|
||||
@@ -27,8 +27,9 @@ export type TrialStart = 'trialStart';
|
||||
export type Purchase = 'purchase';
|
||||
export type Redeem = 'redeem';
|
||||
export type Upgrade = 'upgrade';
|
||||
export type UpdateOs = 'updateOs';
|
||||
export type AccountActionTypes = Troubleshoot | SignIn | SignOut | OemSignOut;
|
||||
export type AccountKeyActionTypes = Recover | Replace | TrialExtend | TrialStart;
|
||||
export type AccountKeyActionTypes = Recover | Replace | TrialExtend | TrialStart | UpdateOs;
|
||||
export type PurchaseActionTypes = Purchase | Redeem | Upgrade;
|
||||
|
||||
export type ServerActionTypes = AccountActionTypes | AccountKeyActionTypes | PurchaseActionTypes;
|
||||
@@ -76,6 +77,11 @@ export interface ExternalKeyActions {
|
||||
keyUrl: string;
|
||||
}
|
||||
|
||||
export interface ExternalUpdateOsAction {
|
||||
type: UpdateOs;
|
||||
plgUrl: string;
|
||||
}
|
||||
|
||||
export interface ServerPayload {
|
||||
type: ServerActionTypes;
|
||||
server: ServerData;
|
||||
@@ -86,7 +92,7 @@ export interface ServerTroubleshoot {
|
||||
server: ServerData;
|
||||
}
|
||||
|
||||
export type ExternalActions = ExternalSignIn | ExternalSignOut | ExternalKeyActions;
|
||||
export type ExternalActions = ExternalSignIn | ExternalSignOut | ExternalKeyActions | ExternalUpdateOsAction;
|
||||
|
||||
export type UpcActions = ServerPayload | ServerTroubleshoot;
|
||||
|
||||
|
||||
@@ -4,12 +4,14 @@ import { addPreventClose, removePreventClose } from '~/composables/preventClose'
|
||||
import { useAccountStore } from '~/store/account';
|
||||
import { useInstallKeyStore } from '~/store/installKey';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import { useUpdateOsStore } from '~/store/updateOs';
|
||||
import { useCallbackStoreGeneric, type CallbackActionsStore, type ExternalKeyActions, type QueryPayloads } from '~/store/callback';
|
||||
|
||||
export const useCallbackActionsStore = defineStore('callbackActions', () => {
|
||||
const accountStore = useAccountStore();
|
||||
const installKeyStore = useInstallKeyStore();
|
||||
const serverStore = useServerStore();
|
||||
const updateOsStore = useUpdateOsStore();
|
||||
|
||||
type CallbackStatus = 'closing' | 'error' | 'loading' | 'ready' | 'success';
|
||||
const callbackStatus = ref<CallbackStatus>('ready');
|
||||
@@ -57,6 +59,11 @@ export const useCallbackActionsStore = defineStore('callbackActions', () => {
|
||||
accountStore.setAccountAction(action);
|
||||
accountStore.setQueueConnectSignOut(true);
|
||||
}
|
||||
|
||||
// if (action.type === 'updateOs') {
|
||||
// updateOsStore.setAccountAction(action);
|
||||
// updateOsStore.installOsUpdate();
|
||||
// }
|
||||
// all actions have run
|
||||
if (array.length === (index + 1)) {
|
||||
await serverStore.refreshServerState();
|
||||
|
||||
@@ -834,6 +834,7 @@ export const useServerStore = defineStore('server', () => {
|
||||
locale,
|
||||
lanIp,
|
||||
name,
|
||||
osVersion,
|
||||
registered,
|
||||
regGen,
|
||||
regGuid,
|
||||
|
||||
111
web/store/updateOs.ts
Normal file
111
web/store/updateOs.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { BellAlertIcon } from '@heroicons/vue/24/solid';
|
||||
import { defineStore, createPinia, setActivePinia } from 'pinia';
|
||||
import gt from 'semver/functions/gt';
|
||||
|
||||
import { request } from '~/composables/services/request';
|
||||
import { ACCOUNT_CALLBACK, OS_RELEASES } from '~/helpers/urls';
|
||||
import { useCallbackStore } from '~/store/callbackActions';
|
||||
import { useErrorsStore } from '~/store/errors';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import type { ServerStateDataAction } from '~/types/server';
|
||||
|
||||
/**
|
||||
* @see https://stackoverflow.com/questions/73476371/using-pinia-with-vue-js-web-components
|
||||
* @see https://github.com/vuejs/pinia/discussions/1085
|
||||
*/
|
||||
setActivePinia(createPinia());
|
||||
|
||||
export interface OsRelease {
|
||||
basefile: string; // "unRAIDServer-6.12.4-x86_64.zip"
|
||||
changelog: string; // "https://unraid-dl.sfo2.cdn.digitaloceanspaces.com/stable/unRAIDServer-6.12.4-x86_64.txt"
|
||||
date: string; // "2023-08-31"
|
||||
md5: string; // "df6e5859d28c14617efde36d59458206"
|
||||
name: string; // "Unraid 6.12.4"
|
||||
size: string; // "439999418"
|
||||
url: string; // "https://unraid-dl.sfo2.cdn.digitaloceanspaces.com/stable/unRAIDServer-6.12.4-x86_64.zip"
|
||||
}
|
||||
|
||||
export const useUpdateOsStore = defineStore('updateOs', () => {
|
||||
const callbackStore = useCallbackStore();
|
||||
const errorsStore = useErrorsStore();
|
||||
const serverStore = useServerStore();
|
||||
|
||||
// State
|
||||
const status = ref<'failed' | 'ready' | 'success' | 'updating' | 'downgrading'>('ready');
|
||||
const updateAvailable = ref<OsRelease | undefined>();
|
||||
watchEffect(() => {
|
||||
if (updateAvailable.value) {
|
||||
console.debug('[useUpdateOsStore] updateAvailable', updateAvailable.value);
|
||||
}
|
||||
});
|
||||
const downgradeAvailable = ref<boolean>(false);
|
||||
|
||||
// Getters
|
||||
const currentOsVersion = computed((): string => serverStore?.osVersion);
|
||||
|
||||
// Actions
|
||||
const checkForOsUpdate = async () => {
|
||||
console.debug('[checkForOsUpdate]');
|
||||
|
||||
if (!currentOsVersion.value) {
|
||||
return console.error('[checkForOsUpdate] currentOsVersion not found, skipping OS update check');
|
||||
}
|
||||
|
||||
const response: OsRelease[] = await request.url(OS_RELEASES.toString()).get().json();
|
||||
console.debug('[checkForOsUpdate] response', response);
|
||||
|
||||
if (response) {
|
||||
response.forEach(release => {
|
||||
const releaseVersion = release.name.replace('Unraid ', '');
|
||||
console.debug('[checkForOsUpdate] releaseVersion', releaseVersion);
|
||||
if (gt(releaseVersion, '6.12.3')) { // currentOsVersion.value
|
||||
updateAvailable.value = release;
|
||||
return; // stop looping, we found an update
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const downgradeOs = async () => {
|
||||
console.debug('[downgradeOs]');
|
||||
status.value = 'downgrading';
|
||||
};
|
||||
|
||||
const installOsUpdate = (plgUrl: string) => {
|
||||
console.debug('[installOsUpdate]', plgUrl);
|
||||
status.value = 'updating';
|
||||
};
|
||||
|
||||
const initUpdateOsCallback = computed((): ServerStateDataAction => {
|
||||
return {
|
||||
click: () => {
|
||||
callbackStore.send(
|
||||
ACCOUNT_CALLBACK.toString(),
|
||||
[{
|
||||
server: {
|
||||
...serverStore.serverAccountPayload,
|
||||
},
|
||||
type: 'updateOs',
|
||||
}],
|
||||
serverStore.inIframe,
|
||||
);
|
||||
},
|
||||
emphasize: true,
|
||||
external: true,
|
||||
icon: BellAlertIcon,
|
||||
name: 'updateOs',
|
||||
text: 'Unraid OS Update Available',
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
// State
|
||||
status,
|
||||
updateAvailable,
|
||||
// Actions
|
||||
checkForOsUpdate,
|
||||
downgradeOs,
|
||||
installOsUpdate,
|
||||
initUpdateOsCallback,
|
||||
};
|
||||
});
|
||||
@@ -110,7 +110,7 @@ export interface ServerPurchaseCallbackSendPayload {
|
||||
site: string;
|
||||
}
|
||||
|
||||
export type ServerStateDataKeyActions = 'purchase' | 'redeem' | 'upgrade' | 'recover' | 'replace' | 'trialExtend' | 'trialStart';
|
||||
export type ServerStateDataKeyActions = 'purchase' | 'redeem' | 'upgrade' | 'recover' | 'replace' | 'trialExtend' | 'trialStart' | 'updateOs';
|
||||
|
||||
export type ServerStateDataAccountActions = 'signIn' | 'signOut' | 'troubleshoot';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user