Skip to content

Commit

Permalink
Merge local games route + Added web retro locally (UseInterstellar#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
xbubbo committed Mar 25, 2024
1 parent 1f86377 commit 124a425
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
47 changes: 28 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,43 @@ if (config.routes !== false) {
})
})
}
if (config.local !== false) {
app.get('/y/*', (req, res, next) => {
const baseUrl = 'https://raw.githubusercontent.com/ypxa/y/main'
fetchData(req, res, next, baseUrl)
})

app.get('/f/*', (req, res, next) => {
const baseUrl = 'https://raw.githubusercontent.com/4x-a/x/fixy'
fetchData(req, res, next, baseUrl)
})
if (config.local !== false) {
app.get('/e/*', (req, res, next) => {
const baseUrls = [
'https://raw.githubusercontent.com/4x-a/x/fixy',
'https://raw.githubusercontent.com/ypxa/y/main',
'https://raw.githubusercontent.com/ypxa/w/master',
];
fetchData(req, res, next, baseUrls);
});
}

const fetchData = async (req, res, next, baseUrl) => {
const fetchData = async (req, res, next, baseUrls) => {
try {
const reqTarget = `${baseUrl}/${req.params[0]}`
const asset = await fetch(reqTarget)
const reqTarget = baseUrls.map(baseUrl => `${baseUrl}/${req.params[0]}`);
let data;
let asset;

for (const target of reqTarget) {
asset = await fetch(target);
if (asset.ok) {
data = await asset.arrayBuffer();
break;
}
}

if (asset.ok) {
const data = await asset.arrayBuffer()
res.end(Buffer.from(data))
if (data) {
res.end(Buffer.from(data));
} else {
next()
next();
}
} catch (error) {
console.error('Error fetching:', error)
next(error)
console.error('Error fetching:', error);
next(error);
}
}
};

server.on('request', (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res)
Expand Down
21 changes: 11 additions & 10 deletions static/assets/json/g.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
},
{
"name": "Stickman Hook",
"link": "/y/stickman-hook/index.html",
"link": "/e/stickman-hook/index.html",
"image": "/assets/media/icons/stickmanhook.webp",
"categories": ["all", "local"],
"local": "true"
Expand Down Expand Up @@ -345,7 +345,7 @@
},
{
"name": "Jetpack Joyride",
"link": "/y/jetpack-joyride/index.html",
"link": "/e/jetpack-joyride/index.html",
"image": "/assets/media/icons/jetpackjoyride.webp",
"categories": ["all", "local"],
"local": "true"
Expand Down Expand Up @@ -646,9 +646,10 @@
},
{
"name": "Web Retro",
"link": "https://binbashbanana.github.io/webretro/",
"link": "/e/index.html",
"image": "/assets/media/icons/webretro.webp",
"categories": ["all,", "emu"]
"categories": ["all,", "emu"],
"local": "true"
},
{
"name": "Slope",
Expand Down Expand Up @@ -826,7 +827,7 @@
},
{
"name": "Cluster Rush",
"link": "/y/Cluster-Rush/index.html",
"link": "/e/Cluster-Rush/index.html",
"image": "/assets/media/icons/cluster-rush.webp",
"categories": ["all", "local"],
"local": "true"
Expand Down Expand Up @@ -1067,7 +1068,7 @@
},
{
"name": "Monkey Mart",
"link": "/y/monkey-mart/index.html",
"link": "/e/monkey-mart/index.html",
"image": "/assets/media/icons/mm.webp",
"categories": ["all", "local"],
"local": "true"
Expand Down Expand Up @@ -1212,7 +1213,7 @@
},
{
"name": "Pizza Tower",
"link": "https://gamaverse.com/c/f/g/pizza-tower-1678640389/index.html",
"link": "https://gamaverse.com/c/e/g/pizza-tower-1678640389/index.html",
"image": "/assets/media/icons/pizza-tower.webp",
"categories": ["all"]
},
Expand Down Expand Up @@ -1526,7 +1527,7 @@
},
{
"name": "Retro Bowl",
"link": "/y/retro/index.html",
"link": "/e/retro/index.html",
"image": "/assets/media/icons/retro.webp",
"categories": ["all,", "sports", "local"],
"local": "true"
Expand Down Expand Up @@ -1737,14 +1738,14 @@
},
{
"name": "Minecraft 1.5.2 (Eaglercraft)",
"link": "/f/ec-15/index.html",
"link": "/e/ec-15/index.html",
"image": "/assets/media/icons/mc.webp",
"categories": ["all", "2P", "emu", "local"],
"local": "true"
},
{
"name": "Minecraft 1.8 (Eaglercraft)",
"link": "/f/ec-18/index.html",
"link": "/e/ec-18/index.html",
"image": "/assets/media/icons/mc.webp",
"categories": ["all", "2P", "emu", "local"],
"local": "true"
Expand Down
2 changes: 1 addition & 1 deletion static/assets/json/g.min.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions static/assets/scripts/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ function iframeLoad() {
if (document.readyState === 'complete') {
const website = iframe.contentWindow?.location.href.replace(window.location.origin, '')

if (website.includes('/y/') || website.includes('/f/')) {
document.getElementById('is').value = '.'
} else if (website.includes('/a/')) {
if (website.includes('/a/')) {
const website = iframe.contentWindow?.location.href.replace(window.location.origin, '').replace('/a/', '')
document.getElementById('is').value = decodeXor(website)
localStorage.setItem('decoded', decodeXor(website));
Expand Down Expand Up @@ -123,7 +121,7 @@ window.onload = function () {
let GoUrl = sessionStorage.getItem('GoUrl')
let dyValue = localStorage.getItem('dy')

if (!GoUrl.startsWith('/y/') && !GoUrl.startsWith('/f/')) {
if (!GoUrl.startsWith('/e/')) {
if (dyValue === 'true' || dyValue === 'auto') {
GoUrl = '/a/q/' + GoUrl
} else {
Expand Down
2 changes: 1 addition & 1 deletion static/games.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link rel="stylesheet" href="/assets/styles/main.css?v=5" />
<link rel="stylesheet" href="/assets/styles/themes/default.css?v=5" />
<script src="/assets/scripts/index.js?v=9"></script>
<script src="/assets/scripts/g.js?v=28"></script>
<script src="/assets/scripts/g.js?v=30"></script>
</head>
<body>
<div class="fixed-nav-bar">
Expand Down

0 comments on commit 124a425

Please sign in to comment.