diff --git a/resources/assets/src/js/check-updates.js b/resources/assets/src/js/check-updates.js new file mode 100644 index 00000000..72614304 --- /dev/null +++ b/resources/assets/src/js/check-updates.js @@ -0,0 +1,30 @@ +import { init } from './net'; + +async function checkForUpdates() { + const response = await fetch(`${blessing.base_url}/admin/update/check`, init); + + if (response.ok) { + const data = await response.json(); + if (data.available) { + const dom = `v${data.latest}`; + + $(`[href="${blessing.base_url}/admin/update"]`).append(dom); + } + } +} + +async function checkForPluginUpdates() { + const response = await fetch(`${blessing.base_url}/admin/plugins/market/check`, init); + + if (response.ok) { + const data = await response.json(); + if (data.available) { + const dom = `${data.plugins.length}`; + + $(`[href="${blessing.base_url}/admin/plugins/market"]`).append(dom); + } + } +} + +window.checkForUpdates = checkForUpdates; +window.checkForPluginUpdates = checkForPluginUpdates; diff --git a/resources/assets/src/js/index.js b/resources/assets/src/js/index.js index a0fc5bc5..4a7aa73d 100644 --- a/resources/assets/src/js/index.js +++ b/resources/assets/src/js/index.js @@ -3,6 +3,7 @@ import './i18n'; import './net'; import './layout'; import './logout'; +import './check-updates'; import './feedback'; console.log( diff --git a/resources/assets/src/js/net.js b/resources/assets/src/js/net.js index 518186ab..053b7266 100644 --- a/resources/assets/src/js/net.js +++ b/resources/assets/src/js/net.js @@ -5,7 +5,8 @@ import { showAjaxError } from './notify'; const csrfField = document.querySelector('meta[name="csrf-token"]'); const empty = Object.create(null); -const init = { +/** @type Request */ +export const init = { credentials: 'same-origin', headers: { 'Accept': 'application/json',