Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving pr to branch #12

Merged
merged 18 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/node_modules
**.DS_Store
.gitpod.yml
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
port: 8080,
mode: 'dev',
minify: false,
assetScrambling: false,
allowDangerousTemplateInsert: true
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ server.listen({
port
});

export default app;
export default app;
2,440 changes: 2,440 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "polaris",
"version": "1.0.0",
"description": "The future of school gaming.",
"description": "The future of school gaming",
"main": "index.js",
"type": "module",
"scripts": {
"dev": "nodemon index.js -e js,css,html,jpeg,png,json",
"start": "node index.js"
"start": "node server",
"prod": "node server prod",
"dev": "node server dev"
},
"author": "Polaris Developments",
"license": "GNU-3.0-or-later",
Expand All @@ -15,7 +16,11 @@
"cors": "*",
"easyviolet": "github:Russell2259/Easyviolet",
"express": "*",
"mime": "*"
"html-minifier": "^4.0.0",
"javascript-obfuscator": "^4.1.0",
"jsdom": "^23.0.1",
"mime": "*",
"uuid": "^9.0.1"
},
"devDependencies": {
"nodemon": "^3.0.1"
Expand Down
53 changes: 29 additions & 24 deletions pages/404.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="/assets/css/main.css">

<title>404 Error | Polaris</title>
</head>

<body>
<div class="content box">
<h1 style="font-size: 50px;">404</h1>
<p>Looks you found a page that does not exist! Try checking your url for spelling mistakes.<br><br>Or, you can report it in our <a href="//dsc.gg/skoolworld">discord server</a>.</p>
</div>

<script src="/assets/js/main.js" type="module"></script>
<script src='https://cdn.jsdelivr.net/npm/@widgetbot/crate@3' async defer>
new Crate({
server: '950407933408198717',
channel: '1172313771985870938'
})
</script>
</body>
<head>
<!--el:meta-->
<!--el:adtop-->
<!--el:analytics-->

<link rel="stylesheet" href="/assets/css/main.css">

<title>404 Error | Polaris</title>
</head>

<body>
<!--el:navbar-->
<!--el:sidebar-->

<div class="content box">
<h1 style="font-size: 50px;">404</h1>

<p>
Looks you found a page that does not exist! Try checking your url for spelling mistakes.
<br>
<br>
Or, you can report it in our <a href="https://discord.gg/skool-community-950407933408198717" target="_blank" class="link">discord server</a>.
</p>
</div>

<script src="/assets/js/main.js" type="module"></script>

<!--el:{{mode === 'dev'}}:development-->
</body>

</html>
384 changes: 210 additions & 174 deletions pages/TOS.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pages/apps.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ <h1>Apps</h1>
<span data-ccpa-link="1"></span>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion pages/cheats.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ <h1>Cheats</h1>
<span data-ccpa-link="1"></span>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion pages/games.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ <h1 style="font-size: 4vh;" class="gamesectionheader">All Games</h1>
<span data-ccpa-link="1"></span>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ <h2>Changelog</h2>
</div>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion pages/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ <h1 class="proxytitle">Proxy</h1>
<span data-ccpa-link="1"></span>
</body>

</html>
</html>
22 changes: 22 additions & 0 deletions pages/uv_404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Loading...</title>
</head>

<body>
<script src="/uv/uv.bundle.js"></script>
<script src="/uv/uv.config.js"></script>

<script>
navigator.serviceWorker.register('/assets/ultraviolet/sw.js', {
scope: __uv$config.prefix
}).then(e => location.reload()).catch(e => { });
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion pages/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
<span data-ccpa-link="1"></span>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
plan: free
runtime: node
buildCommand: npm i
startCommand: node index.js
startCommand: npm start
envVars:
- key: NODE_VERSION
value: 20.0.0
104 changes: 104 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { createBareServer } from '@tomphttp/bare-server-node';
import express from 'express';
import mime from 'mime';
import cors from 'cors';

import { pathToFile, TokenManager, rewriter } from './utils.js';
import config from '../config.js';

import path from 'node:path';
import http from 'node:http';
import url from 'node:url';
import fs from 'node:fs';

const app = express();
const server = http.createServer();
const bareServer = createBareServer('/bare/');
const mode = (process.argv[2] === 'prod' || process.argv[2] === 'dev' ? process.argv[2] : (process.argv[3] === 'prod' || process.argv[3] === 'dev' ? process.argv[3] : (config.mode === 'prod' || config.mode === 'dev' ? config.mode : 'prod')));
const port = (process.argv[2] !== 'prod' && process.argv[2] !== 'dev' && Boolean(Number(process.argv[2]))) ? process.argv[2] : (Boolean(Number(process.argv[3])) ? process.argv[3] : (Boolean(Number(config.port)) ? config.port : (mode === 'prod' ? 80 : 8080 ) ));
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

app.get('/cdn/*', cors({
origin: false
}), async (req, res, next) => {
let reqTarget = `https://raw.githubusercontent.com/Skoolgq/Polaris-Assets/main/${req.path.replace('/cdn/', '')}`;

const asset = await fetch(reqTarget);
if (asset.status == 200) {
var data = Buffer.from(await asset.arrayBuffer());

const noRewrite = ['.unityweb'];
if (!noRewrite.includes(mime.getExtension(reqTarget))) res.writeHead(200, {
'content-type': mime.getType(reqTarget)
});

if (mime.getType(reqTarget) === 'text/html') data = data + '<script src=\'/assets/js/cdn_inject.js\' preload=\'true\'></script>';

res.end(data);
} else next();
});

app.get('/asset', (req, res, next) => {
if (req.query.asset) {
const {
exists,
path: filePath
} = pathToFile(req.query.asset, path.join(__dirname, '../static/assets'));

if (exists) {
if (filePath.startsWith(path.join(__dirname, '../static/assets'))) res.setHeader('content-type', mime.getType(filePath)).end(fs.readFileSync(filePath));
else next();
} else next();
} else next();
});

app.get('/asset/:token', async (req, res, next) => {
if (req.params.token && !req.query.asset) {
if (TokenManager.exists(req.params.token)) {
const token = TokenManager.get(req.params.token);

if (TokenManager.get(req.params.token).type === 'asset') {
TokenManager.delete(req.params.token);

res.setHeader('content-type', token.data.type);
res.end(await rewriter.auto(fs.readFileSync(token.data.asset), token.data.type));
} else next();
} else next();
}
});

app.get('/uv/service*', async (req, res) => {
res.end(await rewriter.html(fs.readFileSync(path.join(__dirname, './pages/uv_404.html'))));
res.setHeader('Service-Worker-Allowed', 'true');
});

app.use(async (req, res, next) => {
const {
exists,
path: filePath
} = pathToFile(req.path, path.join(__dirname, '../static'));

if (exists) {
res.setHeader('content-type', mime.getType(filePath));

if (mime.getType(filePath) === 'text/html') res.end(await rewriter.html(fs.readFileSync(filePath)));
else if (mime.getType(filePath) === 'text/javascript') res.end(await rewriter.javascript(fs.readFileSync(filePath)));
else if (mime.getType(filePath) === 'text/css') res.end(await rewriter.css(fs.readFileSync(filePath)));
else res.sendFile(filePath);
} else {
res.setHeader('content-type', 'text/html');
res.status(404).end(await rewriter.html(fs.readFileSync(path.join(__dirname, '../pages/404.html'))));
}
});

server.on('request', (req, res) => {
if (bareServer.shouldRoute(req)) bareServer.routeRequest(req, res);
else app(req, res);
});

server.on('upgrade', (req, socket, head) => {
if (bareServer.shouldRoute(req)) bareServer.routeUpgrade(req, socket, head);
else socket.end();
});

server.listen(port, () => console.log(`Polaris listening\n\nPort: ${server.address().port}\nMode: ${mode}\nNode.js: ${process.version}\n`));
34 changes: 34 additions & 0 deletions server/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as rewriter from './utils/rewriter.js';
import TokenManager from './utils/token.js';

import path from 'node:path';
import fs from 'node:fs';

/**
* @param {string} url
* @param {string} folderPath
* @returns {{ exists: boolean, path: string }}
*/
const pathToFile = (url = '', folderPath) => {
if (url.endsWith('/')) url = url + 'index.html';
else if (url.split(/[#?]/)[0].split('.').pop().trim() === url) {
if (!fs.existsSync(path.join(folderPath, url))) url = url + '.html';
}

return {
exists: fs.existsSync(path.join(folderPath, url)),
path: path.join(folderPath, url)
};
};

export default {
pathToFile,
TokenManager,
rewriter
};

export {
pathToFile,
TokenManager,
rewriter
};
Loading