Add files via upload

This commit is contained in:
Ricardo Fernández Serrata 2022-06-16 20:35:50 -04:00 committed by GitHub
parent 12ea39a4a9
commit 14c7359eaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 40 deletions

View file

@ -1,10 +1,11 @@
const express = require('express');
const request = require('request');
const compression = require('compression');
const timeout = require('connect-timeout');
const rateLimit = require("express-rate-limit");
const fs = require("fs");
const app = express();
"use strict";
const express = require('express')
const request = require('request')
const compression = require('compression')
const timeout = require('connect-timeout')
const rateLimit = require("express-rate-limit")
const fs = require("fs")
const app = express()
let serverList = require('./servers.json')
let pinnedServers = serverList.filter(x => x.pinned)
@ -34,7 +35,7 @@ const RL2 = rateLimit({
keyGenerator: function(req) { return req.headers['x-real-ip'] || req.headers['x-forwarded-for'] }
})
let XOR = require('./classes/XOR.js');
let XOR = require('./classes/XOR.js')
let achievements = require('./misc/achievements.json')
let achievementTypes = require('./misc/achievementTypes.json')
let music = require('./misc/music.json')
@ -51,10 +52,10 @@ app.servers.forEach(x => {
app.mainEndpoint = app.servers.find(x => !x.id).endpoint // boomlings.com unless changed in fork
app.set('json spaces', 2)
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(timeout('20s'));
app.use(compression())
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use(timeout('20s'))
app.use(async function(req, res, next) {
@ -123,7 +124,7 @@ app.timeSince = function(id, time) {
if (!time) time = app.lastSuccess[id]
let secsPassed = Math.floor((Date.now() - time) / 1000)
let minsPassed = Math.floor(secsPassed / 60)
secsPassed -= 60 * minsPassed;
secsPassed -= 60 * minsPassed
return `${app.actuallyWorked[id] ? "" : "~"}${minsPassed}m ${secsPassed}s`
}
@ -162,11 +163,11 @@ catch(e) {
}
app.parseResponse = function (responseBody, splitter=":") {
if (!responseBody || responseBody == "-1") return {};
if (!responseBody || responseBody == "-1") return {}
if (responseBody.startsWith("\nWarning:")) responseBody = responseBody.split("\n").slice(2).join("\n").trim() // GDPS'es are wild
if (responseBody.startsWith("<br />")) responseBody = responseBody.split("<br />").slice(2).join("<br />").trim() // Seriously screw this
let response = responseBody.split('#')[0].split(splitter);
let res = {};
let response = responseBody.split('#')[0].split(splitter)
let res = {}
for (let i = 0; i < response.length; i += 2) {
res[response[i]] = response[i + 1]}
return res
@ -177,10 +178,10 @@ app.clean = function(text) {return !text || typeof text != "string" ? text : tex
// ASSETS
app.use('/assets', express.static(__dirname + '/assets', {maxAge: "7d"}));
app.use('/assets/css', express.static(__dirname + '/assets/css'));
app.use('/assets', express.static(__dirname + '/assets', {maxAge: "7d"}))
app.use('/assets/css', express.static(__dirname + '/assets/css'))
app.use('/iconkit', express.static(__dirname + '/iconkit'));
app.use('/iconkit', express.static(__dirname + '/iconkit'))
app.get("/global.js", function(req, res) { res.status(200).sendFile(__dirname + "/misc/global.js") })
app.get("/dragscroll.js", function(req, res) { res.status(200).sendFile(__dirname + "/misc/dragscroll.js") })
@ -230,7 +231,7 @@ app.get("/", function(req, res) {
if (req.query.hasOwnProperty("offline") || (req.offline && !req.query.hasOwnProperty("home"))) res.status(200).sendFile(__dirname + "/html/offline.html")
else {
fs.readFile('./html/home.html', 'utf8', function (err, data) {
let html = data;
let html = data
if (req.isGDPS) {
html = html.replace('"levelBG"', '"levelBG purpleBG"')
.replace(/Geometry Dash Browser!/g, req.server.name + " Browser!")
@ -363,7 +364,7 @@ app.get('/api/iconkit', function(req, res) {
let sample = [JSON.stringify(sampleIcons[Math.floor(Math.random() * sampleIcons.length)].slice(1))]
let iconserver = req.isGDPS ? req.server.name : undefined
res.status(200).send(Object.assign(iconKitFiles, {sample, server: iconserver, noCopy: req.onePointNine || req.offline}));
});
})
app.get('/icon/:text', function(req, res) {
let iconID = Number(req.query.icon || 1)
@ -377,13 +378,13 @@ app.get('/icon/:text', function(req, res) {
app.get('*', function(req, res) {
if (req.path.startsWith('/api') || req.path.startsWith("/iconkit")) res.status(404).send('-1')
else res.redirect('/search/404%20')
});
})
app.use(function (err, req, res, next) {
if (err && err.message == "Response timeout") res.status(504).send('Internal server error! (Timed out)')
})
process.on('uncaughtException', (e) => { console.log(e) });
process.on('unhandledRejection', (e, p) => { console.log(e) });
process.on('uncaughtException', e => { console.log(e) })
process.on('unhandledRejection', (e, p) => { console.log(e) })
app.listen(app.config.port, () => console.log(`Site online! (port ${app.config.port})`))

View file

@ -5,7 +5,7 @@ module.exports = {
port: 2000, // Port to host website on
params: { // Always send this stuff to the servers
params: { // Always send this stuff to the servers
secret: 'Wmfd2893gb7',
gameVersion: '21',
binaryVersion: '35',