improve proxy and search

This commit is contained in:
zefie
2025-07-23 12:11:49 -04:00
parent 59a36bdefb
commit 1b24e9d7bf
2 changed files with 55 additions and 22 deletions

View File

@@ -58,6 +58,11 @@ wtv-expire-all: wtv-proxy:/`;
if (request_headers.query.err) { if (request_headers.query.err) {
finishPage(`<h1>Error</h1><p>${request_headers.query.err}</p>`).join('<br>'); finishPage(`<h1>Error</h1><p>${request_headers.query.err}</p>`).join('<br>');
} else { } else {
if (request_headers.query.Fn) {
if (typeof request_headers.query.Fn !== 'string') {
request_headers.query.Fn = request_headers.query.Fn[0];
}
}
const params = new URLSearchParams({ const params = new URLSearchParams({
url: request_headers.query.url, url: request_headers.query.url,
z: request_headers.query.z || '1.0', z: request_headers.query.z || '1.0',
@@ -65,24 +70,50 @@ wtv-expire-all: wtv-proxy:/`;
c: request_headers.query.c || '256', c: request_headers.query.c || '256',
h: request_headers.query.h || '426', h: request_headers.query.h || '426',
w: request_headers.query.w || '640', w: request_headers.query.w || '640',
m: request_headers.query.m || 'ismap' m: request_headers.query.m || 'ismap',
Fn: request_headers.query.Fn || ''
}); });
const fullUrl = proxyUrl + '?' + params.toString();
const urlObj = new URL(fullUrl); if (params.get('Fn') === '129') {
params.set('Fn', 'Bk');
}
if (params.get('Fn') === 'Home') {
headers = `302 Moved
Location: /proxy`
data = '';
sendToClient(socket, headers, data);
} else {
const urlObj = new URL(proxyUrl);
const post_data = params.toString();
const options = {
protocol: urlObj.protocol,
hostname: urlObj.hostname,
port: parseInt(urlObj.port),
path: urlObj.pathname,
method: 'POST',
headers: {
'User-Agent': request_headers['User-Agent'] || 'Mozilla/4.0 WebTV/2.6 (compatible; MSIE 4.0)',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(post_data)
}
}
const lib = urlObj.protocol === 'https:' ? https : http; const lib = urlObj.protocol === 'https:' ? https : http;
if (request_headers.query.id) { if (request_headers.query.id) {
finishPage(`<a href="/map/${request_headers.query.id}.map"><img src="/img/${request_headers.query.id}.${params.get('t')}" ISMAP></a>`); finishPage(`<a href="/map/${request_headers.query.id}.map"><img src="/img/${request_headers.query.id}.${params.get('t')}" ISMAP></a>`);
} else { } else {
function fetch(url) { function fetch(options, post_data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lib.get(url, (res) => { req = lib.request(options, (res) => {
let data = ''; let data = '';
res.on('data', chunk => data += chunk); res.on('data', chunk => data += chunk);
res.on('end', () => resolve({ text: () => Promise.resolve(data) })); res.on('end', () => resolve({ text: () => Promise.resolve(data) }));
}).on('error', reject); }).on('error', reject);
req.write(post_data); // 🔁 Send body
req.end();
}); });
} }
fetch(fullUrl) fetch(options, post_data)
.then(response => response.text()) .then(response => response.text())
.then(text => { process(text); }) .then(text => { process(text); })
.catch(err => { finishPage(`Error fetching page: ${err.message}`); }); .catch(err => { finishPage(`Error fetching page: ${err.message}`); });
@@ -90,6 +121,7 @@ wtv-expire-all: wtv-proxy:/`;
} }
} }
} }
}
function process(content) { function process(content) {
if (content.startsWith('<HTML')) { if (content.startsWith('<HTML')) {
@@ -123,7 +155,7 @@ wtv-expire-all: wtv-proxy:/`;
<head> <head>
<title>Web Rendering Proxy</title> <title>Web Rendering Proxy</title>
</head> </head>
<display nooptions> <display nooptions skipback showwhencomplete>
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff" fontsize="small"> <body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff" fontsize="small">
<form method="POST" action="wtv-proxy:/proxy"> <form method="POST" action="wtv-proxy:/proxy">
<label for="url">URL:</label> <label for="url">URL:</label>
@@ -132,9 +164,9 @@ wtv-expire-all: wtv-proxy:/`;
<input type="hidden" name="t" value="${request_headers.query.t || 'jpg'}"> <input type="hidden" name="t" value="${request_headers.query.t || 'jpg'}">
<input type="hidden" name="c" value="${request_headers.query.c || '216'}"> <input type="hidden" name="c" value="${request_headers.query.c || '216'}">
<input type="submit" value="Go"> <input type="submit" value="Go">
<input type="submit" name="Fn" value="Bk"> <input type="submit" name="Fn" value="&#129;">
<input type="submit" name="Fn" value="Re"> <input type="submit" name="Fn" value="Re">
<a href="/proxy">*</a> <input type="submit" name="Fn" value="Home">
<hr> <hr>
${content} ${content}
</form> </form>

View File

@@ -90,7 +90,8 @@ function process(data) {
} else { } else {
content = '<h1>Search Results</h1>'; content = '<h1>Search Results</h1>';
results.forEach(result => { results.forEach(result => {
content += `<p><a href="${result.url}" target="_blank">${result.title}</a><br>${result.content || `<img src="${result.thumbnail_src}">` || ''}</p><br>`; result.title = result.title.replace(/\</g, '&lt;').replace(/\>/g, '&gt;');
content += `<p><font color="gold">${result.title}</font><br><a href="${result.url}" target="_blank">Direct</a> - <a href="wtv-proxy:/proxy?url=${encodeURIComponent(result.url)}">Proxy</a><br>${result.content || `<img src="${result.thumbnail_src}">` || ''}</p><br>`;
}); });
} }
finishPage(content); finishPage(content);