Skip to content

Commit

Permalink
Test Windows bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Aug 10, 2024
1 parent f8d6d5c commit a68ff00
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"title": "HU LTS",
"host": "0.0.0.0",
"minifyScripts": true,
"randomizeIdentifiers": false,
"randomizeIdentifiers": true,
"production": false
}
126 changes: 62 additions & 64 deletions src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { paintSource, preloaded404, tryReadFile } from './randomization.mjs';
import loadTemplates from './templates.mjs';
import { fileURLToPath } from 'node:url';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { existsSync, unlinkSync } from 'node:fs';
import ecosystem from '../ecosystem.config.js';

Expand Down Expand Up @@ -249,74 +249,72 @@ app.get('/github/:redirect', (req, reply) => {
else reply.code(404).type('text/html').send(preloaded404);
});

if (config.randomizeIdentifiers) {
const encodingTable = (() => {
let yummyOneBytes = '';
for (let i = 0; i < 128; i++)
if (
JSON.stringify(JSON.stringify(String.fromCodePoint(i)).slice(1, -1))
.length < 6
const encodingTable = (() => {
let yummyOneBytes = '';
for (let i = 0; i < 128; i++)
if (
JSON.stringify(JSON.stringify(String.fromCodePoint(i)).slice(1, -1))
.length < 6
)
yummyOneBytes += String.fromCodePoint(i);
return yummyOneBytes;
})(),
randomValue = crypto
.randomUUID()
.split('-')
.map((gibberish) => {
let randomNumber = parseInt(gibberish, 16),
output = '';
while (randomNumber >= encodingTable.length) {
output +=
encodingTable[Math.floor(randomNumber) % encodingTable.length];
randomNumber = randomNumber / encodingTable.length;
}
return output + Math.floor(randomNumber);
})
.join(''),
randomizeGlobal = config.randomizeIdentifiers
? (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify(randomValue)
)
yummyOneBytes += String.fromCodePoint(i);
return yummyOneBytes;
})(),
randomValue = crypto
.randomUUID()
.split('-')
.map((gibberish) => {
let randomNumber = parseInt(gibberish, 16),
output = '';
while (randomNumber >= encodingTable.length) {
output +=
encodingTable[Math.floor(randomNumber) % encodingTable.length];
randomNumber = randomNumber / encodingTable.length;
}
return output + Math.floor(randomNumber);
})
.join(''),
randomizeGlobal = config.randomizeIdentifiers
? (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify(randomValue)
)
: (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify('__uv$config')
);
: (file) =>
tryReadFile(file, import.meta.url).replace(
/(["'`])\{\{__uv\$config\}\}\1/g,
JSON.stringify('__uv$config')
);

app.get('/assets/js/common-16451543478.js', (req, reply) => {
reply
.type('text/javascript')
.send(
randomizeGlobal(
'../views' + (config.minifyScripts ? '/dist' : '') + req.url
)
);
});
app.get('/assets/js/common-16451543478.js', (req, reply) => {
reply
.type('text/javascript')
.send(
randomizeGlobal(
'../views' + (config.minifyScripts ? '/dist' : '') + req.url
)
);
});

app.get('/uv/:file.js', (req, reply) => {
const destination = existsSync(
fileURLToPath(new URL('../views' + req.url, import.meta.url))
)
? '../views' + (config.minifyScripts ? '/dist' : '') + req.url
: uvPath + '/' + req.params.file + '.js';
reply
.type('text/javascript')
.send(
randomizeGlobal(destination).replace(
/(["'`])\{\{ultraviolet-error\}\}\1/g,
JSON.stringify(
tryReadFile(
'../views/pages/proxnav/ultraviolet-error.html',
import.meta.url
)
app.get('/uv/:file.js', (req, reply) => {
const destination = existsSync(
fileURLToPath(new URL('../views' + req.url, import.meta.url))
)
? '../views' + (config.minifyScripts ? '/dist' : '') + req.url
: pathToFileURL(uvPath) + `/${req.params.file}.js`;
reply
.type('text/javascript')
.send(
randomizeGlobal(destination).replace(
/(["'`])\{\{ultraviolet-error\}\}\1/g,
JSON.stringify(
tryReadFile(
'../views/pages/proxnav/ultraviolet-error.html',
import.meta.url
)
)
);
});
}
)
);
});

// Set an error page for invalid paths outside the query string system.
app.setNotFoundHandler((req, reply) => {
Expand Down

0 comments on commit a68ff00

Please sign in to comment.