From d75e92ce57c4c97797c0925588e35e6a9ee2ac6a Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 14 Oct 2023 21:06:30 +0300 Subject: [PATCH] rewrite api --- src/App.vue | 20 +++++ src/api/AdminApi.js | 34 ++++---- src/api/GlobalApi.js | 80 ++++++++++++++++++ src/components/Others/BackgroundImage.vue | 3 +- src/components/Others/SnackLoader.vue | 33 ++++++++ src/components/PublicMethods.js | 81 ------------------- src/components/TabsMenu.vue | 5 +- .../SubComponents/CurrentPlayers.vue | 21 +---- .../TabsMenuElements/RulesView/RulesView.vue | 9 +-- .../Components/PlayerExtendedInfo.vue | 4 +- .../ServersView/ServersView.vue | 24 ++++-- src/main.js | 11 ++- 12 files changed, 190 insertions(+), 135 deletions(-) create mode 100644 src/api/GlobalApi.js create mode 100644 src/components/Others/SnackLoader.vue delete mode 100644 src/components/PublicMethods.js diff --git a/src/App.vue b/src/App.vue index 3c66215..178de75 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,6 +15,8 @@ import MdCard from "vue-material/dist/components/MdCard"; import MdDialog from "vue-material/dist/components/MdDialog"; import MdDrawer from "vue-material/dist/components/MdDrawer"; import MdButton from "vue-material/dist/components/MdButton"; +import MdProgress from "vue-material/dist/components/MdProgress"; +import MdSnackbar from "vue-material/dist/components/MdSnackbar"; Vue.use(MdTabs); Vue.use(MdIcon); @@ -22,6 +24,8 @@ Vue.use(MdCard); Vue.use(MdDialog); Vue.use(MdDrawer); Vue.use(MdButton); +Vue.use(MdProgress); +Vue.use(MdSnackbar); import TabsMenu from "@/components/TabsMenu.vue"; export default { @@ -153,4 +157,20 @@ a { font-family: tf2secondary; text-transform: none; } + +.md-progress-bar { + background-color: rgba(253,136,70,0.5) !important; +} + +.md-progress-bar-track { + color: black; +} + +.md-progress-bar-fill { + color: black; +} + +.md-progress-bar-buffer { + color: black; +} diff --git a/src/api/AdminApi.js b/src/api/AdminApi.js index 316c416..91b9d1d 100644 --- a/src/api/AdminApi.js +++ b/src/api/AdminApi.js @@ -1,23 +1,27 @@ import axios from "axios"; -export default { - name: 'AdminApi', - data: () => ({ - allowBan: false - }), - checkAllowBan() { - return axios.options("/api/admin/ban") +export default class AdminApi { + permition = { + ban:false, + mute:false, + kick:false + } + + async checkPermition(name) { + return axios.options(`/api/admin/${name}`) .then(response => { - return response.status === 200; + if (response.status === 200) this.permition[name] = true; }) .catch((err) => { - return err.response.status === 200 + if (err.response.status === 200) this.permition[name] = true; }); - }, - async serverPrefetch() { - this.checkAllowBan().then((r) => { - console.log("[AdminApi] allow ban: " + r); - this.allowBan = true; - }) + } + + async load() { + console.log(`[AdminAPI] request permissions`); + if (document.cookie.indexOf("steam64=") === -1) return; + await this.checkPermition('ban') + await this.checkPermition('mute') + await this.checkPermition('kick') } } \ No newline at end of file diff --git a/src/api/GlobalApi.js b/src/api/GlobalApi.js new file mode 100644 index 0000000..3c7143a --- /dev/null +++ b/src/api/GlobalApi.js @@ -0,0 +1,80 @@ +import axios from "axios"; +import AdminApi from "@/api/AdminApi"; + +export default class GlobalApi { + stats = { + 'statistic':null, + 'servers': null, + 'uniq': null + } + loading = false; + + admin = new AdminApi() + + constructor() { + } + + async fillThis(value) { + console.log(`[API] load: ${value}`); + return await axios.get(`/api/stats?filter=${value}`) + .then(response => response.data) + .then(response => { + this.stats[value] = response[value]; + }) + .catch(err => { + console.log(`[API] cannot request ${value}, err: ${err}`); + }) + } + + async fillServers() { + console.log(`[API] load: servers`); + return axios.get("/api/stats?filter=servers") + .then(response => response.data['servers']) + .then(response => { + let srvs = { + 'w':[], + "e":[], + 'n':[] + }; + for (let srv in response) { + if (response[srv]['status'] == false) srvs.n.push(response[srv]); + else if (response[srv]['player_count'] > 0) srvs.w.push(response[srv]); + else srvs.e.push(response[srv]); + } + this.stats['servers'] = srvs; + }) + .catch(err => { + console.log(`[API] cannot request servers, err: ${err}`); + }); + } + + async load() { + this.loading = true; + await this.fillThis('statistic'); + await this.fillThis('uniq'); + await this.fillServers(); + await this.admin.load(); + this.loading = false; + } + + getRandomBackground() { + const backgrounds = [ + require('../assets/images/backgrounds/1.png'), + require('../assets/images/backgrounds/2.png'), + require('../assets/images/backgrounds/3.png'), + require('../assets/images/backgrounds/4.png') + ]; + return backgrounds[Math.floor(Math.random() * backgrounds.length)]; + } + + getRules(){ + return [ + [{"name":"Читы", "about":"Бан навсегда сука", "image": require('@/assets/images/rules/cheats.jpg')}, + {"name":"Реклама серверов", "about":"Кроме мге, бан навсегда сука", "image": require('@/assets/images/rules/ads.jpg')}, + {"name":"Багоюз", "about":"Пиздец тебе, бан навсегда", "image": require('@/assets/images/rules/bug_use.jpg')}], + [{"name":"Абуз команды !mir", "about":"Блокировка дверей, открытие спавна и т.д", "image":require('@/assets/images/rules/abuse.jpg')}, + {"name":"Абуз випки на сервере", "about":"Модеры сам решат как и за что", "image":require('@/assets/images/rules/abuse_vip.jpg')}, + {"name":"Делай короче чё хочешь", "about":":troll_face:", "image":require('@/assets/images/rules/make_everyone.jpg')}] + ]; + } +} diff --git a/src/components/Others/BackgroundImage.vue b/src/components/Others/BackgroundImage.vue index 19390fb..1469c09 100644 --- a/src/components/Others/BackgroundImage.vue +++ b/src/components/Others/BackgroundImage.vue @@ -3,7 +3,6 @@ + + \ No newline at end of file diff --git a/src/components/PublicMethods.js b/src/components/PublicMethods.js deleted file mode 100644 index 97322a4..0000000 --- a/src/components/PublicMethods.js +++ /dev/null @@ -1,81 +0,0 @@ -import axios from "axios"; - -export default { - name: "PublicMethods", - methods: {}, - getBackground(){ - const backgrounds = [ - require('../assets/images/backgrounds/1.png'), - require('../assets/images/backgrounds/2.png'), - require('../assets/images/backgrounds/3.png'), - require('../assets/images/backgrounds/4.png') - ]; - return backgrounds[Math.floor(Math.random()*backgrounds.length)]; - }, - getApi(){ - console.log("[PublicMethods] request api/stats"); - return axios.get("/api/stats") - .then(response => response.data) - .then(response => { - console.log("[PublicMethods] success get api/stats"); - console.log(response); - return response; - }) - .catch(err => { - console.log(`[PublicMethods] cannot request api/stats, err: ${err}`); - }) - }, - getStatistics(){ - console.log("[PublicMethods] request api/stats/statistics"); - return axios.get("/api/stats?filter=statistic") - .then(response => response.data) - .then(response => { - return response; - }) - .catch(err => { - console.log(`[PublicMethods] cannot request api/stats/statistic, err: ${err}`); - }) - }, - getServers(){ - console.log("[PublicMethods] request api/stats/servers"); - return axios.get("/api/stats?filter=servers") - .then(response => response.data['servers']) - .then(response => { - let srvs = { - 'w':[], - "e":[], - 'n':[] - }; - for (let srv in response) { - if (response[srv]['status'] == false) srvs.n.push(response[srv]); - else if (response[srv]['player_count'] > 0) srvs.w.push(response[srv]); - else srvs.e.push(response[srv]); - } - return srvs; - }) - .catch(err => { - console.log(`[PublicMethods] cannot request api/stats/statistic, err: ${err}`); - }); - }, - getUniq(){ - console.log("[PublicMethods] request api/stats/uniq"); - return axios.get("/api/stats?filter=uniq") - .then(response => response.data) - .then(response => { - return response; - }) - .catch(err => { - console.log(`[PublicMethods] cannot request api/stats/statistic, err: ${err}`); - }) - }, - getRules(){ - return [ - [{"name":"Читы", "about":"Бан навсегда сука", "image": require('@/assets/images/rules/cheats.jpg')}, - {"name":"Реклама серверов", "about":"Кроме мге, бан навсегда сука", "image": require('@/assets/images/rules/ads.jpg')}, - {"name":"Багоюз", "about":"Пиздец тебе, бан навсегда", "image": require('@/assets/images/rules/bug_use.jpg')}], - [{"name":"Абуз команды !mir", "about":"Блокировка дверей, открытие спавна и т.д", "image":require('@/assets/images/rules/abuse.jpg')}, - {"name":"Абуз випки на сервере", "about":"Модеры сам решат как и за что", "image":require('@/assets/images/rules/abuse_vip.jpg')}, - {"name":"Делай короче чё хочешь", "about":":troll_face:", "image":require('@/assets/images/rules/make_everyone.jpg')}] - ]; - } -} \ No newline at end of file diff --git a/src/components/TabsMenu.vue b/src/components/TabsMenu.vue index da45925..dfb20b6 100644 --- a/src/components/TabsMenu.vue +++ b/src/components/TabsMenu.vue @@ -31,7 +31,10 @@ export default { components: {BackendStatus, MainView, EmptyTab, RulesView, ServersView, ProfileView, VipView, AboutView, BackgroundImage}, data: () => ({ current_tab: "" - }) + }), + beforeCreate() { + console.log("wait data to render"); + } } diff --git a/src/components/TabsMenuElements/MainView/Components/SubComponents/CurrentPlayers.vue b/src/components/TabsMenuElements/MainView/Components/SubComponents/CurrentPlayers.vue index 4963f3b..345ea51 100644 --- a/src/components/TabsMenuElements/MainView/Components/SubComponents/CurrentPlayers.vue +++ b/src/components/TabsMenuElements/MainView/Components/SubComponents/CurrentPlayers.vue @@ -15,40 +15,27 @@
-

{{player_now}}

+

{{this.$API.stats.statistic.player_now}}

-

{{player_max}}

+

{{this.$API.stats.statistic.player_max}}

-

{{working_servers}}/{{total_servers}}

+

{{this.$API.stats.statistic.working_servers}}/{{this.$API.stats.statistic.total_servers}}

\ No newline at end of file diff --git a/src/components/TabsMenuElements/RulesView/RulesView.vue b/src/components/TabsMenuElements/RulesView/RulesView.vue index 31bcac1..d8e1c16 100644 --- a/src/components/TabsMenuElements/RulesView/RulesView.vue +++ b/src/components/TabsMenuElements/RulesView/RulesView.vue @@ -4,11 +4,11 @@
-
-

Правила (для сам маленьких)

+
+

Правила (для сам маленьких)

-
+

Правила на которые ты забьешь хуй

V V V

@@ -34,7 +34,6 @@ \ No newline at end of file diff --git a/src/components/TabsMenuElements/ServersView/Components/PlayerExtendedInfo.vue b/src/components/TabsMenuElements/ServersView/Components/PlayerExtendedInfo.vue index 7ad298c..5c99306 100644 --- a/src/components/TabsMenuElements/ServersView/Components/PlayerExtendedInfo.vue +++ b/src/components/TabsMenuElements/ServersView/Components/PlayerExtendedInfo.vue @@ -31,7 +31,7 @@
РЕПОРТ кикнуть - забанить + забанить замьютить
@@ -40,7 +40,6 @@ \ No newline at end of file diff --git a/src/main.js b/src/main.js index 63eb05f..fa92765 100644 --- a/src/main.js +++ b/src/main.js @@ -1,8 +1,11 @@ import Vue from 'vue' import App from './App.vue' +import GlobalApi from './api/GlobalApi' Vue.config.productionTip = false - -new Vue({ - render: h => h(App), -}).$mount('#app') +Vue.prototype.$API = new GlobalApi(); +Vue.prototype.$API.load().then(() => { + new Vue({ + render: h => h(App), + }).$mount('#app') +}); \ No newline at end of file