2025-01-14 10:27:27 +01:00
|
|
|
|
|
|
|
|
import { fetcher } from 'pankow';
|
2025-03-03 11:22:56 +01:00
|
|
|
import { API_ORIGIN } from '../constants.js';
|
2025-01-14 10:27:27 +01:00
|
|
|
|
2025-01-31 21:02:48 +01:00
|
|
|
function create() {
|
|
|
|
|
const accessToken = localStorage.token;
|
|
|
|
|
|
2025-01-14 10:27:27 +01:00
|
|
|
return {
|
|
|
|
|
name: 'CloudronModel',
|
|
|
|
|
async languages() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/cloudron/languages`, { access_token: accessToken });
|
2025-01-14 10:27:27 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-23 18:36:30 +01:00
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body.languages];
|
|
|
|
|
},
|
|
|
|
|
async getLanguage() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/cloudron/language`, { access_token: accessToken });
|
2025-01-23 18:36:30 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body.language];
|
|
|
|
|
},
|
|
|
|
|
async setLanguage(language) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/cloudron/language`, { language }, { access_token: accessToken });
|
2025-01-23 18:36:30 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async getTimeZone() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/cloudron/time_zone`, { access_token: accessToken });
|
2025-01-23 18:36:30 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body.timeZone];
|
|
|
|
|
},
|
|
|
|
|
async setTimeZone(timeZone) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/cloudron/time_zone`, { timeZone }, { access_token: accessToken });
|
2025-01-23 18:36:30 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
2025-01-14 10:27:27 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-24 17:38:18 +01:00
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null];
|
|
|
|
|
},
|
|
|
|
|
async getRegistryConfig() {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.get(`${API_ORIGIN}/api/v1/docker/registry_config`, { access_token: accessToken });
|
2025-01-24 17:38:18 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null, result.body];
|
|
|
|
|
},
|
|
|
|
|
async setRegistryConfig(config) {
|
|
|
|
|
let error, result;
|
|
|
|
|
try {
|
2025-03-03 11:22:56 +01:00
|
|
|
result = await fetcher.post(`${API_ORIGIN}/api/v1/docker/registry_config`, config, { access_token: accessToken });
|
2025-01-24 17:38:18 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
error = e;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-23 18:36:30 +01:00
|
|
|
if (error || result.status !== 200) return [error || result];
|
|
|
|
|
return [null];
|
2025-01-14 10:27:27 +01:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
create,
|
|
|
|
|
};
|