41932c9127
this way if the app auto updates in the background, we are showing the correct state in the view
70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
|
|
import { fetcher } from '@cloudron/pankow';
|
|
import { API_ORIGIN } from '../constants.js';
|
|
|
|
function create() {
|
|
const accessToken = localStorage.token;
|
|
|
|
return {
|
|
async getBoxUpdate() {
|
|
let error, result;
|
|
try {
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/updater/box_update`, { access_token: accessToken });
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
return [null, result.body.update];
|
|
},
|
|
async getAutoupdatePattern() {
|
|
let error, result;
|
|
try {
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/updater/autoupdate_pattern`, { access_token: accessToken });
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
return [null, result.body];
|
|
},
|
|
async setAutoupdatePattern(pattern) {
|
|
let error, result;
|
|
try {
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/updater/autoupdate_pattern`, { pattern }, { access_token: accessToken });
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
return [null];
|
|
},
|
|
async checkBoxUpdate() {
|
|
let error, result;
|
|
try {
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/updater/check_box_update`, {}, { access_token: accessToken });
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
return [null];
|
|
},
|
|
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;
|
|
}
|
|
|
|
if (error || result.status !== 202) return [error || result];
|
|
return [null, result.body.taskId];
|
|
},
|
|
};
|
|
}
|
|
|
|
export default {
|
|
create,
|
|
};
|