Add missing updates checking

This commit is contained in:
Pig Fang 2018-08-21 10:49:02 +08:00
parent 94652f4257
commit f3fab514a5
3 changed files with 33 additions and 1 deletions

View File

@ -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 = `<span class="pull-right-container"><span class="label label-primary pull-right">v${data.latest}</span></span>`;
$(`[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 = `<span class="pull-right-container"><span class="label label-success pull-right">${data.plugins.length}</span></span>`;
$(`[href="${blessing.base_url}/admin/plugins/market"]`).append(dom);
}
}
}
window.checkForUpdates = checkForUpdates;
window.checkForPluginUpdates = checkForPluginUpdates;

View File

@ -3,6 +3,7 @@ import './i18n';
import './net';
import './layout';
import './logout';
import './check-updates';
import './feedback';
console.log(

View File

@ -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',