Upload files to "/"

main
v00rm 2025-01-25 18:27:39 +00:00
parent 5e6b982a8a
commit ddb7217a8b
2 changed files with 110 additions and 0 deletions

90
index.js 100644
View File

@ -0,0 +1,90 @@
const express = require('express');
const axios = require('axios');
const path = require('path');
const ejs = require('ejs');
const app = express();
const port = 8080;
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/proxy', async (req, res) => {
const url = req.query.url;
const whitelisted_urls = [
"https://api-cdn.rule34.xxx/",
"https://api-cdn-mp4.rule34.xxx/"
];
try {
const isWhitelisted = whitelisted_urls.some((base) => url.startsWith(base));
if (!isWhitelisted) {
return res.status(403).send('URL is not allowed.');
}
const response = await axios.get(url, { responseType: 'arraybuffer' });
const contentType = response.headers['content-type'];
if (!contentType) {
return res.status(400).send('Invalid content type.');
}
console.log(`Proxied Content-Type: ${contentType}`);
res.set('Content-Type', contentType);
res.send(response.data);
} catch (error) {
console.error('Error fetching media:', error.message);
res.status(500).send('Error fetching media.');
}
});
app.get('/', (req, res) => {
res.render('index', {
searchTerm: '',
});
});
app.get('/donate', (req, res) => {
res.render('donate', {
searchTerm: '',
});
});
app.get('/monero', (req, res) => {
res.status(200).send('86kNVqWXqTvAYnW97rPCLkGJL1pLyZZAreGa4NgMesEjggvBXso7JQ5TxWVdmu6FgA9zhKk2gvPEwRE2myZwQD4hANE7Pbw') //Please dont change that <3
});
app.get('/posts', async (req, res) => {
const search = req.query.search || '';
const page = parseInt(req.query.page) || 1;
const limit = 10;
const offset = (page - 1) * limit;
try {
const apiUrl = search
? `https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&tags=${encodeURIComponent(search)}&limit=${limit}&pid=${page - 1}`
: `https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&limit=${limit}&pid=${page - 1}`;
const response = await axios.get(apiUrl, {
headers: { 'User-Agent': 'Mozilla/5.0' },
});
const posts = response.data || [];
res.render('posts', {
posts,
search,
page,
});
} catch (error) {
console.error('Error fetching posts:', error.message);
res.status(500).send('Error fetching posts. Please try again later.');
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});

20
package.json 100644
View File

@ -0,0 +1,20 @@
{
"name": "rulei2p",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "v00rm",
"license": "GPL-3.0-only",
"description": "",
"dependencies": {
"axios": "^1.7.9",
"body-parser": "^1.20.3",
"ejs": "^3.1.10",
"express": "^4.21.2",
"node-fetch": "^3.3.2",
"xml2js": "^0.6.2"
}
}