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

48 lines
1.2 KiB
JavaScript
Raw Normal View History

import { fetcher } from 'pankow';
2025-03-03 11:22:56 +01:00
import { API_ORIGIN } from '../constants.js';
2025-01-31 21:02:48 +01:00
function create() {
const accessToken = localStorage.token;
return {
async getConfig() {
let error, result;
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.get(`${API_ORIGIN}/api/v1/dashboard/config`, { access_token: accessToken });
} catch (e) {
error = e;
}
2025-01-24 14:00:33 +01:00
if (error || result.status !== 200) return [error || result];
return [null, result.body];
},
2025-01-27 22:20:26 +01:00
async prepareDomain(domain) {
let error, result;
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.post(`${API_ORIGIN}/api/v1/dashboard/prepare_location`, { domain }, { access_token: accessToken });
2025-01-27 22:20:26 +01:00
} catch (e) {
error = e;
}
if (error || result.status !== 202) return [error || result];
return [null, result.body.taskId];
},
async setDomain(domain) {
let error, result;
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.post(`${API_ORIGIN}/api/v1/dashboard/location`, { domain }, { access_token: accessToken });
2025-01-27 22:20:26 +01:00
} catch (e) {
error = e;
}
if (error || result.status !== 204) return [error || result];
return [null];
},
};
}
export default {
create,
};