Add endpoint and util to fetch latest version

This commit is contained in:
Justin Edmund 2023-01-25 22:18:23 -08:00
parent 122e12411d
commit 31f2bd075a
4 changed files with 26 additions and 0 deletions

5
types/AppUpdate.d.ts vendored Normal file
View file

@ -0,0 +1,5 @@
interface AppUpdate {
version: string
update_type: string
updated_at: string
}

View file

@ -148,6 +148,11 @@ class Api {
const resourceUrl = `${this.url}/users/info/${id}` const resourceUrl = `${this.url}/users/info/${id}`
return axios.get(resourceUrl) return axios.get(resourceUrl)
} }
version() {
const resourceUrl = `${this.url}/version`
return axios.get(resourceUrl)
}
} }
const api: Api = new Api({ url: process.env.NEXT_PUBLIC_SIERO_API_URL || 'https://localhost:3000/api/v1'}) const api: Api = new Api({ url: process.env.NEXT_PUBLIC_SIERO_API_URL || 'https://localhost:3000/api/v1'})

View file

@ -67,6 +67,7 @@ interface AppState {
jobs: Job[] jobs: Job[]
jobSkills: JobSkill[] jobSkills: JobSkill[]
weaponKeys: GroupedWeaponKeys weaponKeys: GroupedWeaponKeys
version: AppUpdate
} }
export const initialAppState: AppState = { export const initialAppState: AppState = {
@ -127,6 +128,11 @@ export const initialAppState: AppState = {
gauph: [], gauph: [],
emblem: [], emblem: [],
}, },
version: {
version: '0.0',
update_type: '',
updated_at: new Date(),
},
} }
export const appState = proxy(initialAppState) export const appState = proxy(initialAppState)

View file

@ -0,0 +1,10 @@
import api from './api'
export default async function fetchLatestVersion() {
try {
const response = await api.version()
return response.data as AppUpdate
} catch (error) {
console.error(error)
}
}