-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: old HW firmware/node notification (#58)
- Loading branch information
1 parent
4eb276d
commit cdcbd89
Showing
11 changed files
with
107 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { customEndpoint } from '@directus/sdk'; | ||
import { useMetadata } from '~/store/metadata.js'; | ||
|
||
export default defineNuxtPlugin(async () => { | ||
const metadata = useMetadata(); | ||
const { $directus } = useNuxtApp(); | ||
|
||
const response = await $directus.request<Metadata>(customEndpoint({ method: 'GET', path: '/metadata' })); | ||
metadata.setMetadata(response); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { defineStore } from 'pinia'; | ||
|
||
export const useMetadata = defineStore('metadata', { | ||
state: (): Metadata => ({ | ||
targetNodeVersion: '', | ||
targetHardwareDeviceFirmware: '', | ||
creditsPerDollar: 0, | ||
creditsPerAdoptedProbe: 0, | ||
}), | ||
actions: { | ||
setMetadata (metadata: Metadata) { | ||
this.targetNodeVersion = String(metadata.targetNodeVersion); | ||
this.targetHardwareDeviceFirmware = String(metadata.targetHardwareDeviceFirmware); | ||
this.creditsPerDollar = Number(metadata.creditsPerDollar); | ||
this.creditsPerAdoptedProbe = Number(metadata.creditsPerAdoptedProbe); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useMetadata } from '~/store/metadata.js'; | ||
|
||
const compareSemver = (a: string, b: string) => { | ||
const pa = a.split('.'); | ||
const pb = b.split('.'); | ||
|
||
for (let i = 0; i < 3; i++) { | ||
const na = Number(pa[i]) || 0; | ||
const nb = Number(pb[i]) || 0; | ||
|
||
if (na > nb) { return 1; } | ||
|
||
if (nb > na) { return -1; } | ||
} | ||
|
||
return 0; | ||
}; | ||
|
||
const isOutdated = (probeValue: string | null, metadataValue: string) => { | ||
if (!probeValue || !metadataValue) { | ||
return false; | ||
} | ||
|
||
const result = compareSemver(probeValue.replaceAll('v', ''), metadataValue.replaceAll('v', '')); | ||
return result === -1; | ||
}; | ||
|
||
export const getProbeStatus = (probe: Probe) => { | ||
const metadata = useMetadata(); | ||
|
||
if ( | ||
probe.status === 'ready' | ||
&& (isOutdated(probe.hardwareDeviceFirmware, metadata.targetHardwareDeviceFirmware) | ||
|| isOutdated(probe.nodeVersion, metadata.targetNodeVersion) | ||
)) { | ||
return 'ready (outdated)'; | ||
} | ||
|
||
return probe.status; | ||
}; |