mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Add hook to check version with GitHub API
This commit is contained in:
parent
85f791e382
commit
d79c804591
28
hooks/useVersion.js
Normal file
28
hooks/useVersion.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import useFetch from 'hooks/useFetch';
|
||||||
|
|
||||||
|
export default function useVersion() {
|
||||||
|
const { data } = useMemo(() =>
|
||||||
|
useFetch('https://api.github.com/repos/mikecao/umami/releases/latest'),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!data || !data['tag_name']) return null;
|
||||||
|
|
||||||
|
const latest = data['tag_name'].startsWith('v') ? data['tag_name'].slice(1) : data['tag_name'];
|
||||||
|
const current = process.env.VERSION;
|
||||||
|
|
||||||
|
if (latest === current) return null;
|
||||||
|
|
||||||
|
const latestArray = latest.split('.');
|
||||||
|
const currentArray = current.split('.');
|
||||||
|
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
if (Number(latestArray[i]) > Number(currentArray[i]))
|
||||||
|
return {
|
||||||
|
current: current,
|
||||||
|
latest: latest,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user