api and image proxy

This commit is contained in:
Russell2259
2024-01-03 18:46:27 +00:00
parent 44cfda5666
commit b2ef5a6fd4
6 changed files with 229 additions and 56 deletions
+169
View File
@@ -23,6 +23,175 @@ const swPaths = [
'/assets/js/offline.js'
];
app.get('/api/games', (req, res) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const games = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/games.json')));
const gamesObject = {
popular: [],
all: []
};
for (let i = 0; i < games.length; i++) {
const game = games[i];
if (game.popular) gamesObject.popular.push({
name: game.name,
target: game.target,
image: `/api/games/${i + 1}/image`
});
gamesObject.all.push({
name: game.name,
target: game.target,
image: `/api/games/${i + 1}/image`
});
}
res.json(gamesObject);
});
app.get('/api/games/:id', async (req, res, next) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const games = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/games.json')));
if (games[req.params.id - 1]) {
const game = games[req.params.id - 1];
game.image = `/api/games/${req.params.id}/image`;
game.popular = Boolean(game.popular);
res.json(game);
} else next();
});
app.get('/api/games/:id/image', async (req, res, next) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const games = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/games.json')));
if (games[req.params.id - 1]) {
if (URL.canParse(games[req.params.id - 1].image)) {
const request = await fetch(games[req.params.id - 1].image);
const imageBuffer = Buffer.from(await request.arrayBuffer());
res.setHeader('content-type', request.headers.get('content-type'));
res.end(imageBuffer);
} else res.redirect(games[req.params.id - 1].image);
} else next();
});
app.get('/api/apps', (req, res) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const apps = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/apps.json')));
const appsObject = [];
for (let i = 0; i < apps.length; i++) {
const app = apps[i];
appsObject.push({
name: app.name,
target: app.target,
image: `/api/apps/${i + 1}/image`
});
}
res.json(appsObject);
});
app.get('/api/apps/:id', async (req, res, next) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const apps = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/apps.json')));
if (apps[req.params.id - 1]) {
const app = apps[req.params.id - 1];
app.image = `/api/apps/${req.params.id}/image`;
res.json(app);
} else next();
});
app.get('/api/apps/:id/image', async (req, res, next) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const apps = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/apps.json')));
if (apps[req.params.id - 1]) {
if (URL.canParse(apps[req.params.id - 1].image)) {
const request = await fetch(apps[req.params.id - 1].image);
const imageBuffer = Buffer.from(await request.arrayBuffer());
res.setHeader('content-type', request.headers.get('content-type'));
res.end(imageBuffer);
} else res.redirect(apps[req.params.id - 1].image);
} else next();
});
app.get('/api/cheats', (req, res) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const cheats = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/cheats.json')));
const cheatsObject = [];
for (let i = 0; i < cheats.length; i++) {
const cheat = cheats[i];
cheatsObject.push({
name: cheat.name,
target: cheat.target,
image: `/api/cheats/${i + 1}/image`
});
}
res.json(cheatsObject);
});
app.get('/api/cheats/:id', async (req, res, next) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const cheats = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/cheats.json')));
if (cheats[req.params.id - 1]) {
const cheat = cheats[req.params.id - 1];
cheat.image = `/api/cheats/${req.params.id}/image`;
res.json(cheat);
} else next();
});
app.get('/api/cheats/:id/image', async (req, res, next) => {
/**
* @type {Array.<{name: string, target: string, image: string, popular: boolean}>}
*/
const cheats = JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/cheats.json')));
if (cheats[req.params.id - 1]) {
if (URL.canParse(cheats[req.params.id - 1].image)) {
const request = await fetch(cheats[req.params.id - 1].image);
const imageBuffer = Buffer.from(await request.arrayBuffer());
res.setHeader('content-type', request.headers.get('content-type'));
res.end(imageBuffer);
} else res.redirect(cheats[req.params.id - 1].image);
} else next();
});
app.get('/cdn/3kh0/*', cors({
origin: false
}), async (req, res, next) => {
+1 -1
View File
@@ -312,7 +312,7 @@
},
{
"name": "Minecraft",
"target": "https://raw.githack.com/Skoolgq/eagler/main/index.html",
"target": "/cdn/3kh0/minecraft-15/index.html",
"image": "/assets/img/mc.jpeg",
"popular": true
},
+24 -20
View File
@@ -10,7 +10,8 @@ body[data-theme='dark'] {
--scrollbar-color: #ffffff59;
--solid: #1b2735;
--hover: #757575;
background: radial-gradient(at center bottom, rgb(27, 39, 53) 0%, rgb(9, 10, 15) 100%);;
background: radial-gradient(at center bottom, rgb(27, 39, 53) 0%, rgb(9, 10, 15) 100%);
;
background-repeat: no-repeat;
}
@@ -214,6 +215,26 @@ body[data-theme='violet'] {
@media screen and (prefers-color-scheme: light) {
body[data-theme='light'] {
--background-color: #fff;
--background-darker: var(--background-color);
--text: #000;
--hover: #757575;
--sidebar-bg: #ffffffee;
--button-bg: #ecececee;
--shadow-color: #c9c9c9;
--switch-color: #111111b0;
--switch-active: #2196F3;
--scrollbar-color: #4242424b;
--solid: #ffffffee;
--hover: #757575;
background: radial-gradient(ellipse at bottom, #b1b1b1 0%, #f6f5f0 100%);
background-repeat: no-repeat;
}
}
@media screen and (prefers-color-scheme: dark) {
body[data-theme='system-default'] {
--background-color: rgba(0, 0, 0, 0.8);
--background-darker: rgba(0, 0, 0, 0.9);
--text: #fff;
@@ -225,25 +246,8 @@ body[data-theme='violet'] {
--scrollbar-color: #ffffff59;
--solid: #1b2735;
--hover: #757575;
background: radial-gradient(at center bottom, rgb(27, 39, 53) 0%, rgb(9, 10, 15) 100%);;
background-repeat: no-repeat;
}
}
@media screen and (prefers-color-scheme: dark) {
body[data-theme='system-default'] {
--background-color: rgba(0, 0, 0, 0.8);
--background-darker: rgba(0, 0, 0, 0.9);
--text: #fff;
--sidebar-bg: #161f2eef;
--button-bg: #42424259;
--shadow-color: #000;
--switch-color: #42424259;
--switch-active: #2196F3;
--scrollbar-color: #ffffff59;
--solid: #1b2735;
--hover: #757575;
background: radial-gradient(at center bottom, rgb(27, 39, 53) 0%, rgb(9, 10, 15) 100%);;
background: radial-gradient(at center bottom, rgb(27, 39, 53) 0%, rgb(9, 10, 15) 100%);
;
background-repeat: no-repeat;
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { createViewPage, isValidURL } from './utils.js';
import PolarisError from './error.js';
import effects from './effects.js';
const load = () => fetch('/assets/JSON/apps.json').then(res => res.json()).then(apps => {
const load = () => fetch('/api/apps').then(res => res.json()).then(apps => {
apps.forEach(app => {
const el = document.createElement('div');
el.classList = 'app';
+1 -1
View File
@@ -2,7 +2,7 @@ import { createViewPage, isValidURL } from './utils.js';
import PolarisError from './error.js';
import effects from './effects.js';
const load = () => fetch('/assets/JSON/cheats.json')
const load = () => fetch('/api/cheats')
.then(res => res.json())
.then(cheats => cheats.forEach(cheat => {
const el = document.createElement('div');
+33 -33
View File
@@ -3,7 +3,7 @@ import PolarisError from './error.js';
import effects from './effects.js';
const load = () => {
fetch('/assets/JSON/games.json')
fetch('/api/games')
.then(res => res.json())
.then(games => {
const searchBar = document.querySelector('#searchInput');
@@ -31,7 +31,38 @@ const load = () => {
}
});
games.forEach(game => {
games.popular.forEach(game => {
const popularEl = document.createElement('div');
popularEl.classList = 'game';
popularEl.innerHTML = `<img loading='lazy' src='${game.image}'><h3>${game.name}</h3>`;
document.querySelector('.popular-games').appendChild(popularEl);
popularEl.addEventListener('click', async () => {
document.body.style.opacity = '0.7';
setTimeout(() => {
if (isValidURL(game.target)) createViewPage({
target: game.target,
title: game.name,
proxied: true
});
else createViewPage({
target: game.target,
title: game.name
});
}, 500);
});
effects.hoverTilt({
max: 8,
perspective: 1000,
scale: 1.05,
speed: 800,
easing: 'cubic-bezier(.03,.98,.52,.99)'
}, popularEl);
});
games.all.forEach(game => {
const el = document.createElement('div');
el.classList = 'game';
el.innerHTML = `<img loading="lazy" src="${game.image}"><h3>${game.name}</h3>`;
@@ -45,37 +76,6 @@ const load = () => {
easing: 'cubic-bezier(.03,.98,.52,.99)'
}, el);
if (game.popular) {
const popularEl = document.createElement('div');
popularEl.classList = 'game';
popularEl.innerHTML = `<img loading='lazy' src='${game.image}'><h3>${game.name}</h3>`;
document.querySelector('.popular-games').appendChild(popularEl);
popularEl.addEventListener('click', async () => {
document.body.style.opacity = '0.7';
setTimeout(() => {
if (isValidURL(game.target)) createViewPage({
target: game.target,
title: game.name,
proxied: true
});
else createViewPage({
target: game.target,
title: game.name
});
}, 500);
});
effects.hoverTilt({
max: 8,
perspective: 1000,
scale: 1.05,
speed: 800,
easing: 'cubic-bezier(.03,.98,.52,.99)'
}, popularEl);
}
el.addEventListener('click', async () => {
document.body.style.opacity = '0.7';