Files
cloudron-box/dashboard/src/models/UpdaterModel.js
T

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-01-24 14:00:33 +01:00
2025-07-10 11:55:11 +02:00
import { fetcher } from '@cloudron/pankow';
2025-03-03 11:22:56 +01:00
import { API_ORIGIN } from '../constants.js';
2025-01-24 14:00:33 +01:00
2025-01-31 21:02:48 +01:00
function create() {
const accessToken = localStorage.token;
2025-01-24 14:00:33 +01:00
return {
2025-06-26 15:19:28 +02:00
async getBoxUpdate() {
2025-01-24 14:00:33 +01:00
let error, result;
try {
2025-06-26 15:19:28 +02:00
result = await fetcher.get(`${API_ORIGIN}/api/v1/updater/box_update`, { access_token: accessToken });
2025-01-24 14:00:33 +01:00
} catch (e) {
error = e;
}
if (error || result.status !== 200) return [error || result];
return [null, result.body.update];
},
async getAutoupdatePattern() {
let error, result;
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.get(`${API_ORIGIN}/api/v1/updater/autoupdate_pattern`, { access_token: accessToken });
2025-01-24 14:00:33 +01:00
} catch (e) {
error = e;
}
if (error || result.status !== 200) return [error || result];
return [null, result.body];
},
async setAutoupdatePattern(pattern) {
let error, result;
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.post(`${API_ORIGIN}/api/v1/updater/autoupdate_pattern`, { pattern }, { access_token: accessToken });
2025-01-24 14:00:33 +01:00
} catch (e) {
error = e;
}
if (error || result.status !== 200) return [error || result];
return [null];
},
2025-06-26 15:19:28 +02:00
async checkBoxUpdate() {
2025-01-24 14:00:33 +01:00
let error, result;
try {
2025-06-26 15:19:28 +02:00
result = await fetcher.post(`${API_ORIGIN}/api/v1/updater/check_box_update`, {}, { access_token: accessToken });
2025-01-24 14:00:33 +01:00
} catch (e) {
error = e;
}
if (error || result.status !== 200) return [error || result];
return [null];
},
2025-06-30 17:35:01 +02:00
async update(skipBackup = false) {
let error, result;
try {
result = await fetcher.post(`${API_ORIGIN}/api/v1/updater/box_update`, { skipBackup }, { access_token: accessToken });
} catch (e) {
error = e;
}
2025-06-30 17:35:01 +02:00
if (error || result.status !== 202) return [error || result];
return [null, result.body.taskId];
},
2025-01-24 14:00:33 +01:00
};
}
export default {
create,
};