removed linting from api.js

pull/1097/head
smit95tpatel 2021-12-17 18:40:09 +05:30
parent f979eddce3
commit 8351c09161
1 changed files with 269 additions and 374 deletions

View File

@ -1,413 +1,308 @@
import axios from 'axios'; import axios from 'axios'
const qs = require('querystring'); const qs = require('querystring');
// axios.defaults.withCredentials = true; axios.defaults.withCredentials = true
axios.defaults.withCredentials = false;
const tokenKey = 'statping_auth'; const tokenKey = "statping_auth";
class Api { class Api {
constructor () { constructor() {
this.version = '0.90.74'; this.version = "0.90.74";
this.commit = '2612402a7782f28ca0b7fc10c941d8c4a1a5acc6'; this.commit = "2612402a7782f28ca0b7fc10c941d8c4a1a5acc6";
} }
async oauth () { async oauth() {
const oauth = axios.get('api/oauth').then((response) => response.data); const oauth = axios.get('api/oauth').then(response => (response.data))
return oauth; return oauth
} }
async core () {
const core = axios.get('api').then((response) => response.data);
if (core.allow_reports) {
await this.sentry_init();
}
return core;
}
async core_save (obj) {
return axios.post('api/core', obj).then((response) => response.data);
}
async oauth_save (obj) {
return axios.post('api/oauth', obj).then((response) => response.data);
}
async setup_save (data) {
return axios
.post('api/setup', qs.stringify(data))
.then((response) => response.data);
}
async services () {
return axios.get('api/services').then((response) => response.data);
}
async service (id) {
return axios.get('api/services/' + id).then((response) => response.data);
}
async service_create (data) {
return axios.post('api/services', data).then((response) => response.data);
}
async service_update (data) {
return axios
.post('api/services/' + data.id, data)
.then((response) => response.data);
}
async service_hits (id, start, end, group, fill = true) {
return axios
.get(
'api/services/' +
id +
'/hits_data?start=' +
start +
'&end=' +
end +
'&group=' +
group +
'&fill=' +
fill
)
.then((response) => response.data);
}
async service_ping (id, start, end, group, fill = true) {
return axios
.get(
'api/services/' +
id +
'/ping_data?start=' +
start +
'&end=' +
end +
'&group=' +
group +
'&fill=' +
fill
)
.then((response) => response.data);
}
async service_failures_data (id, start, end, group, fill = true) {
return axios
.get(
'api/services/' +
id +
'/failure_data?start=' +
start +
'&end=' +
end +
'&group=' +
group +
'&fill=' +
fill
)
.then((response) => response.data);
}
async service_uptime (id, start, end) {
return axios
.get('api/services/' + id + '/uptime_data?start=' + start + '&end=' + end)
.then((response) => response.data);
}
async service_heatmap (id, start, end, group) {
return axios
.get('api/services/' + id + '/heatmap')
.then((response) => response.data);
}
async service_failures (id, start, end, limit = 999, offset = 0) {
return axios
.get(
'api/services/' +
id +
'/failures?start=' +
start +
'&end=' +
end +
'&limit=' +
limit +
'&offset=' +
offset
)
.then((response) => response.data);
}
async service_failures_delete (service) {
return axios
.delete('api/services/' + service.id + '/failures')
.then((response) => response.data);
}
async service_delete (id) {
return axios.delete('api/services/' + id).then((response) => response.data);
}
async services_reorder (data) {
return axios
.post('api/reorder/services', data)
.then((response) => response.data);
}
async checkins () {
return axios.get('api/checkins').then((response) => response.data);
}
async groups () {
return axios.get('api/groups').then((response) => response.data);
}
async groups_reorder (data) {
return axios
.post('api/reorder/groups', data)
.then((response) => response.data);
}
async group_delete (id) {
return axios.delete('api/groups/' + id).then((response) => response.data);
}
async group_create (data) {
return axios.post('api/groups', data).then((response) => response.data);
}
async group_update (data) {
return axios
.post('api/groups/' + data.id, data)
.then((response) => response.data);
}
async users () {
return axios.get('api/users').then((response) => response.data);
}
async user_create (data) { async core() {
return axios.post('api/users', data).then((response) => response.data); const core = axios.get('api').then(response => (response.data))
if (core.allow_reports) {
await this.sentry_init()
} }
return core
}
async user_update (data) { async core_save(obj) {
return axios return axios.post('api/core', obj).then(response => (response.data))
.post('api/users/' + data.id, data) }
.then((response) => response.data);
}
async user_delete (id) { async oauth_save(obj) {
return axios.delete('api/users/' + id).then((response) => response.data); return axios.post('api/oauth', obj).then(response => (response.data))
} }
async incident_updates (incident) { async setup_save(data) {
return axios return axios.post('api/setup', qs.stringify(data)).then(response => (response.data))
.get('api/incidents/' + incident.id + '/updates') }
.then((response) => response.data);
}
async incident_update_create (update) { async services() {
return axios return axios.get('api/services').then(response => (response.data))
.post('api/incidents/' + update.incident + '/updates', update) }
.then((response) => response.data);
}
async incident_update_delete (update) { async service(id) {
return axios return axios.get('api/services/' + id).then(response => (response.data))
.delete('api/incidents/' + update.incident + '/updates/' + update.id) }
.then((response) => response.data);
}
async incidents_service (id) { async service_create(data) {
return axios return axios.post('api/services', data).then(response => (response.data))
.get('api/services/' + id + '/incidents') }
.then((response) => response.data);
}
async incident_create (service_id, data) { async service_update(data) {
return axios return axios.post('api/services/' + data.id, data).then(response => (response.data))
.post('api/services/' + service_id + '/incidents', data) }
.then((response) => response.data);
}
async incident_delete (incident) { async service_hits(id, start, end, group, fill = true) {
return axios return axios.get('api/services/' + id + '/hits_data?start=' + start + '&end=' + end + '&group=' + group + '&fill=' + fill).then(response => (response.data))
.delete('api/incidents/' + incident.id) }
.then((response) => response.data);
}
async checkin (api) { async service_ping(id, start, end, group, fill = true) {
return axios.get('api/checkins/' + api).then((response) => response.data); return axios.get('api/services/' + id + '/ping_data?start=' + start + '&end=' + end + '&group=' + group + '&fill=' + fill).then(response => (response.data))
} }
async checkin_create (data) { async service_failures_data(id, start, end, group, fill = true) {
return axios.post('api/checkins', data).then((response) => response.data); return axios.get('api/services/' + id + '/failure_data?start=' + start + '&end=' + end + '&group=' + group + '&fill=' + fill).then(response => (response.data))
} }
async checkin_delete (checkin) { async service_uptime(id, start, end) {
return axios return axios.get('api/services/' + id + '/uptime_data?start=' + start + '&end=' + end).then(response => (response.data))
.delete('api/checkins/' + checkin.api_key) }
.then((response) => response.data);
}
async messages () { async service_heatmap(id, start, end, group) {
return axios.get('api/messages').then((response) => response.data); return axios.get('api/services/' + id + '/heatmap').then(response => (response.data))
} }
async message_create (data) { async service_failures(id, start, end, limit = 999, offset = 0) {
return axios.post('api/messages', data).then((response) => response.data); return axios.get('api/services/' + id + '/failures?start=' + start + '&end=' + end + '&limit=' + limit + '&offset=' + offset).then(response => (response.data))
} }
async message_update (data) { async service_failures_delete(service) {
return axios return axios.delete('api/services/' + service.id + '/failures').then(response => (response.data))
.post('api/messages/' + data.id, data) }
.then((response) => response.data);
}
async message_delete (id) { async service_delete(id) {
return axios.delete('api/messages/' + id).then((response) => response.data); return axios.delete('api/services/' + id).then(response => (response.data))
} }
async group (id) { async services_reorder(data) {
return axios.get('api/groups/' + id).then((response) => response.data); return axios.post('api/reorder/services', data).then(response => (response.data))
} }
async notifiers () { async checkins() {
return axios.get('api/notifiers').then((response) => response.data); return axios.get('api/checkins').then(response => (response.data))
} }
async notifier_save (data) { async groups() {
return axios return axios.get('api/groups').then(response => (response.data))
.post('api/notifier/' + data.method, data) }
.then((response) => response.data);
}
async notifier_test (data, notifier) { async groups_reorder(data) {
return axios return axios.post('api/reorder/groups', data).then(response => (response.data))
.post('api/notifier/' + notifier + '/test', data) }
.then((response) => response.data);
}
async renewApiKeys () { async group_delete(id) {
return axios.get('api/renew').then((response) => response.data); return axios.delete('api/groups/' + id).then(response => (response.data))
} }
async logs () { async group_create(data) {
return axios.get('api/logs').then((response) => response.data) || []; return axios.post('api/groups', data).then(response => (response.data))
} }
async logs_last () { async group_update(data) {
return axios.get('api/logs/last').then((response) => response.data); return axios.post('api/groups/' + data.id, data).then(response => (response.data))
} }
async theme () { async users() {
return axios.get('api/theme').then((response) => response.data); return axios.get('api/users').then(response => (response.data))
} }
async theme_generate (create = true) { async user_create(data) {
if (create) { return axios.post('api/users', data).then(response => (response.data))
return axios.get('api/theme/create').then((response) => response.data); }
} else {
return axios.delete('api/theme').then((response) => response.data);
}
}
async theme_save (data) { async user_update(data) {
return axios.post('api/theme', data).then((response) => response.data); return axios.post('api/users/' + data.id, data).then(response => (response.data))
} }
async import (data) { async user_delete(id) {
return axios return axios.delete('api/users/' + id).then(response => (response.data))
.post('api/settings/import', data) }
.then((response) => response.data);
}
async check_token (token) { async incident_updates(incident) {
const f = { token: token }; return axios.get('api/incidents/' + incident.id + '/updates').then(response => (response.data))
return axios }
.post('api/users/token', qs.stringify(f))
.then((response) => response.data);
}
async login (username, password) { async incident_update_create(update) {
const f = { username: username, password: password }; return axios.post('api/incidents/' + update.incident + '/updates', update).then(response => (response.data))
return axios }
.post('api/login', qs.stringify(f))
.then((response) => response.data);
}
async logout () { async incident_update_delete(update) {
return axios.get('api/logout').then((response) => response.data); return axios.delete('api/incidents/' + update.incident + '/updates/' + update.id).then(response => (response.data))
} }
async scss_base () { async incidents_service(id) {
return await axios({ return axios.get('api/services/' + id + '/incidents').then(response => (response.data))
url: '/scss/base.scss', }
method: 'GET',
responseType: 'blob',
}).then((response) => {
const reader = new window.FileReader();
return reader.readAsText(response.data);
});
}
async configs () { async incident_create(service_id, data) {
return ( return axios.post('api/services/' + service_id + '/incidents', data).then(response => (response.data))
axios.get('api/settings/configs').then((response) => response.data) || [] }
);
} async incident_delete(incident) {
return axios.delete('api/incidents/' + incident.id).then(response => (response.data))
async configs_save (data) { }
return (
axios async checkin(api) {
.post('api/settings/configs', data) return axios.get('api/checkins/' + api).then(response => (response.data))
.then((response) => response.data) || [] }
);
} async checkin_create(data) {
return axios.post('api/checkins', data).then(response => (response.data))
token () { }
return $cookies.get(tokenKey);
} async checkin_delete(checkin) {
return axios.delete('api/checkins/' + checkin.api_key).then(response => (response.data))
authToken () { }
const tk = $cookies.get(tokenKey);
if (tk) { async messages() {
return { Authorization: 'Bearer ' + tk }; return axios.get('api/messages').then(response => (response.data))
} else { }
return {};
} async message_create(data) {
} return axios.post('api/messages', data).then(response => (response.data))
}
async github_release () {
return fetch( async message_update(data) {
'https://api.github.com/repos/statping/statping/releases/latest' return axios.post('api/messages/' + data.id, data).then(response => (response.data))
).then((response) => response.json()); }
}
async message_delete(id) {
async allActions (...all) { return axios.delete('api/messages/' + id).then(response => (response.data))
await axios.all([ all ]); }
}
async group(id) {
async downtimes ({ serviceId, start, end, skip, count, subStatus }) { return axios.get('api/groups/' + id).then(response => (response.data))
return axios.get('api/downtimes', { }
params: { service_id: serviceId, start, end, skip, count, sub_status: subStatus }
}).then((response) => response.data); async notifiers() {
} return axios.get('api/notifiers').then(response => (response.data))
}
async downtime (id) {
return axios.get(`api/downtimes/${id}`).then((response) => response.data); async notifier_save(data) {
} return axios.post('api/notifier/' + data.method, data).then(response => (response.data))
}
async downtime_create (data) {
return axios.post('/api/downtimes', data).then((response) => response.data); async notifier_test(data, notifier) {
} return axios.post('api/notifier/' + notifier + '/test', data).then(response => (response.data))
}
async downtime_update ({ id, data }) {
return axios.patch(`/api/downtimes/${id}`, data).then((response) => response.data); async renewApiKeys() {
} return axios.get('api/renew').then(response => (response.data))
}
async downtime_delete (id) {
return axios.delete(`/api/downtimes/${id}`).then((response) => response.data); async logs() {
} return axios.get('api/logs').then(response => (response.data)) || []
}
async logs_last() {
return axios.get('api/logs/last').then(response => (response.data))
}
async theme() {
return axios.get('api/theme').then(response => (response.data))
}
async theme_generate(create = true) {
if (create) {
return axios.get('api/theme/create').then(response => (response.data))
} else {
return axios.delete('api/theme').then(response => (response.data))
}
}
async theme_save(data) {
return axios.post('api/theme', data).then(response => (response.data))
}
async import(data) {
return axios.post('api/settings/import', data).then(response => (response.data))
}
async check_token(token) {
const f = {token: token}
return axios.post('api/users/token', qs.stringify(f)).then(response => (response.data))
}
async login(username, password) {
const f = {username: username, password: password}
return axios.post('api/login', qs.stringify(f)).then(response => (response.data))
}
async logout() {
return axios.get('api/logout').then(response => (response.data))
}
async scss_base() {
return await axios({
url: '/scss/base.scss',
method: 'GET',
responseType: 'blob'
}).then((response) => {
const reader = new window.FileReader();
return reader.readAsText(response.data)
})
}
async configs() {
return axios.get('api/settings/configs').then(response => (response.data)) || []
}
async configs_save(data) {
return axios.post('api/settings/configs', data).then(response => (response.data)) || []
}
token() {
return $cookies.get(tokenKey);
}
authToken() {
const tk = $cookies.get(tokenKey)
if (tk) {
return {'Authorization': 'Bearer ' + tk};
} else {
return {};
}
}
async github_release() {
return fetch('https://api.github.com/repos/statping/statping/releases/latest').then(response => response.json())
}
async allActions(...all) {
await axios.all([all])
}
async downtimes ({ serviceId, start, end, skip, count, subStatus }) {
return axios.get('api/downtimes', {
params: { service_id: serviceId, start, end, skip, count, sub_status: subStatus }
}).then((response) => response.data);
}
async downtime (id) {
return axios.get(`api/downtimes/${id}`).then((response) => response.data);
}
async downtime_create (data) {
return axios.post('/api/downtimes', data).then((response) => response.data);
}
async downtime_update ({ id, data }) {
return axios.patch(`/api/downtimes/${id}`, data).then((response) => response.data);
}
async downtime_delete (id) {
return axios.delete(`/api/downtimes/${id}`).then((response) => response.data);
}
} }
const api = new Api(); const api = new Api()
export default api; export default api