2023-08-22 10:32:40 +02:00
|
|
|
import { Alert } from 'react-native';
|
2022-09-29 15:03:47 +02:00
|
|
|
// Lodash
|
|
|
|
|
// Http Client
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
// Network Infos
|
2023-08-22 10:32:40 +02:00
|
|
|
import NetInfo from '@react-native-community/netinfo';
|
2022-09-29 15:03:47 +02:00
|
|
|
// Translations
|
2023-08-22 10:32:40 +02:00
|
|
|
import i18n from '../../I18n';
|
2022-09-29 16:22:58 +02:00
|
|
|
// Database
|
2023-08-22 10:32:40 +02:00
|
|
|
import { Setting } from '../../Database';
|
2022-09-30 16:21:14 +02:00
|
|
|
|
2023-01-04 15:11:37 +01:00
|
|
|
const api_token = 'G9Q62jt8eL8gN4Ls';
|
2022-09-28 18:08:39 +02:00
|
|
|
class InstallController {
|
2023-08-22 10:32:40 +02:00
|
|
|
async getConfig(url) {
|
|
|
|
|
return axios({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: url + '/api/settings',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-09-28 18:08:39 +02:00
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
getAppConfig(url) {
|
|
|
|
|
NetInfo.fetch().then(state => {
|
|
|
|
|
if (state.isConnected) {
|
|
|
|
|
axios({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: url + '/api/app',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then(function (response) {
|
|
|
|
|
if (response.data) {
|
|
|
|
|
if (response.data.status === 'OK') {
|
|
|
|
|
Setting.upsert({
|
|
|
|
|
key: 'HomeFolders',
|
|
|
|
|
value: JSON.stringify(response.data.datas.folders),
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Alert.alert(
|
|
|
|
|
i18n.t('alert.error'),
|
|
|
|
|
i18n.t('error.error_has_occurred'),
|
|
|
|
|
);
|
2022-10-07 18:27:54 +02:00
|
|
|
return false;
|
2023-08-22 10:32:40 +02:00
|
|
|
}
|
2022-09-29 15:03:47 +02:00
|
|
|
}
|
2023-08-22 10:32:40 +02:00
|
|
|
})
|
|
|
|
|
.catch(function (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
Alert.alert(
|
|
|
|
|
i18n.t('alert.error'),
|
|
|
|
|
i18n.t('error.error_has_occurred'),
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Alert.alert(
|
|
|
|
|
i18n.t('alert.error'),
|
|
|
|
|
i18n.t('error.tablet_not_connected_internet'),
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-09-28 18:08:39 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-22 10:32:40 +02:00
|
|
|
export default new InstallController();
|