Kastg commited on
Commit
3ea323c
·
verified ·
1 Parent(s): be112e0

Delete index.js

Browse files
Files changed (1) hide show
  1. index.js +0 -165
index.js DELETED
@@ -1,165 +0,0 @@
1
- const express = require('express');
2
- const path = require('path');
3
- const cors = require('cors');
4
- const axios = require('axios');
5
- const os = require('os');
6
- const fs = require('fs');
7
- const PORT = 25565;
8
- const app = express();
9
- const apirouter = require('./dashinfo/api.js');
10
-
11
- var __path = process.cwd();
12
-
13
- app.use('/css', express.static(path.join(__dirname, 'css')));
14
- app.use('/js', express.static(path.join(__dirname, 'js')));
15
- app.use('/lib', express.static(path.join(__dirname, 'lib')));
16
- app.use('/img', express.static(path.join(__dirname, 'img')));
17
-
18
- app.use('/api', apirouter);
19
-
20
- app.get('/', (req, res) => {
21
- res.sendFile(__path + '/index.html');
22
- });
23
-
24
- app.get('/ai', (req, res) => {
25
- res.sendFile(__path + '/views/ai.html');
26
- });
27
-
28
- app.use(cors());
29
-
30
- //////////////////////////////
31
-
32
- ////////////////////////////////////////////
33
-
34
- const dataFilePath = path.join(__dirname, 'visitor_data.json');
35
-
36
- let { visitorCount, visitorToday, lastUpdateDate } = loadVisitorData();
37
-
38
- const allowedPaths = ['/ai/aa', '/api', '/tool'];
39
-
40
- app.use((req, res, next) => {
41
- if (allowedPaths.some(path => req.path.startsWith(path))) {
42
- updateVisitorCounts();
43
- }
44
-
45
- next();
46
- });
47
-
48
- let Clock; // Declare Clock as a global variable
49
-
50
- // Function to update the Clock variable
51
- function updateClock() {
52
- var d = new Date();
53
- const hour = d.getHours();
54
- const min = d.getMinutes();
55
- const sec = d.getSeconds();
56
- Clock = `${hour}:${min}:${sec}`;
57
- }
58
-
59
- setInterval(() => {
60
- updateClock();
61
- }, 1000);
62
-
63
- app.get('/info', (req, res) => {
64
- const ip = req.connection.remoteAddress || req.socket.remoteAddress;
65
- const currentTime = new Date().toLocaleTimeString();
66
- const cleanIp = ip.includes('::ffff:') ? ip.replace('::ffff:', '') : ip;
67
-
68
- res.json({
69
- ip: cleanIp,
70
- current_time: Clock
71
- });
72
- });
73
-
74
- app.get('/count', (req, res) => {
75
- try {
76
- res.json({
77
- visitor_count: visitorCount,
78
- visitor_today: visitorToday
79
- });
80
- } catch (error) {
81
- console.error(error);
82
- res.status(500).json({ error: 'Internal Server Error' });
83
- }
84
- });
85
-
86
- app.get('/status', (req, res) => {
87
- try {
88
- const uptime = os.uptime();
89
- const runtime = formatUptime(uptime);
90
- const memory = {
91
- free: formatBytes(os.freemem()),
92
- total: formatBytes(os.totalmem())
93
- };
94
-
95
- res.json({
96
- runtime: runtime,
97
- memory: `${memory.free} / ${memory.total}`
98
- });
99
- } catch (error) {
100
- console.error(error);
101
- res.status(500).json({ error: 'Internal Server Error' });
102
- }
103
- });
104
-
105
- function updateVisitorCounts() {
106
- const currentDate = new Date().toDateString();
107
-
108
- if (currentDate !== lastUpdateDate) {
109
- visitorToday = 0;
110
- lastUpdateDate = currentDate;
111
- saveVisitorData();
112
- }
113
-
114
- visitorCount++;
115
- visitorToday++;
116
- saveVisitorData();
117
- }
118
-
119
- function loadVisitorData() {
120
- try {
121
- const data = fs.readFileSync(dataFilePath, 'utf8');
122
- return JSON.parse(data);
123
- } catch (error) {
124
- return {
125
- visitorCount: 0,
126
- visitorToday: 0,
127
- lastUpdateDate: new Date().toDateString()
128
- };
129
- }
130
- }
131
-
132
- function saveVisitorData() {
133
- const data = {
134
- visitorCount,
135
- visitorToday,
136
- lastUpdateDate
137
- };
138
-
139
- fs.writeFileSync(dataFilePath, JSON.stringify(data), 'utf8');
140
- }
141
-
142
- function formatBytes(bytes) {
143
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
144
- if (bytes === 0) return '0 Byte';
145
- const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
146
- return Math.round(100 * bytes / Math.pow(1024, i)) / 100 + ' ' + sizes[i];
147
- }
148
-
149
- function formatUptime(uptime) {
150
- const hours = Math.floor(uptime / 3600);
151
- const minutes = Math.floor((uptime % 3600) / 60);
152
- const seconds = Math.floor(uptime % 60);
153
-
154
- return `${hours} hours, ${minutes} minutes, ${seconds} seconds`;
155
- }
156
- app.use((req, res) => {
157
- res.status(404).sendFile(__path + '/404.html');
158
- });
159
-
160
-
161
- app.listen(PORT, () => {
162
- console.log("Server running on port " + PORT);
163
- });
164
-
165
- module.exports = app;