fix/optimize wtv-news, wtv-proxy, wtv-register, wtv-search, wtv-setup, wtv-star
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
minisrv_service_file = true;
|
||||
const minisrv_service_file = true;
|
||||
request_is_async = true;
|
||||
|
||||
const proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||
let proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||
if (!proxyUrl.endsWith('/')) {
|
||||
proxyUrl += '/';
|
||||
}
|
||||
|
||||
// Remove 'service_name:/' from the start of request_url
|
||||
let forwardPath = request_headers.request_url
|
||||
const forwardPath = request_headers.request_url
|
||||
.replace(new RegExp(`^${service_name}:\\/`), '');
|
||||
|
||||
// Build the full URL to forward to
|
||||
@@ -24,12 +24,12 @@ lib.get(targetUrl, (res) => {
|
||||
headers += `Content-Type: ${res.headers['content-type']}\n`;
|
||||
}
|
||||
|
||||
let data = [];
|
||||
const data = [];
|
||||
res.on('data', chunk => data.push(chunk));
|
||||
res.on('end', () => {
|
||||
sendToClient(socket, headers, Buffer.concat(data));
|
||||
});
|
||||
}).on('error', err => {
|
||||
var errpage = WTVShared.doErrorPage(400, 'Error fetching image', err.message);
|
||||
const errpage = wtvshared.doErrorPage(400, 'Error fetching image', err.message);
|
||||
sendToClient(socket, errpage[0], errpage[1]);
|
||||
});
|
||||
@@ -1,23 +1,23 @@
|
||||
minisrv_service_file = true;
|
||||
const minisrv_service_file = true;
|
||||
request_is_async = true;
|
||||
|
||||
const proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||
let proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||
if (!proxyUrl.endsWith('/')) {
|
||||
proxyUrl += '/';
|
||||
}
|
||||
|
||||
// Remove 'service_name:/' from the start of request_url
|
||||
let forwardPath = request_headers.request_url
|
||||
const forwardPath = request_headers.request_url
|
||||
.replace(new RegExp(`^${service_name}:\\/`), '');
|
||||
|
||||
// Build the full URL to forward to
|
||||
var targetUrl = proxyUrl + forwardPath;
|
||||
let targetUrl = proxyUrl + forwardPath;
|
||||
|
||||
// Forward the request using http(s) module
|
||||
const urlObj = new URL(targetUrl);
|
||||
const lib = urlObj.protocol === 'https:' ? https : http;
|
||||
|
||||
coords = request_headers.request_url.split("?")[1];
|
||||
let coords = request_headers.request_url.split("?")[1];
|
||||
if (!coords) {
|
||||
coords = '0,0'
|
||||
}
|
||||
@@ -46,20 +46,20 @@ lib.get(targetUrl, (res) => {
|
||||
img: imgSrcMatch[1]
|
||||
});
|
||||
}
|
||||
var proxy_id = links[0].href.replace(/\/map\//, '');
|
||||
let proxy_id = links[0].href.replace(/\/map\//, '');
|
||||
proxy_id = proxy_id.replace(/\.map/, '');
|
||||
var imgExt = links[0].img.split('.').pop().split('?')[0].toLowerCase();
|
||||
const imgExt = links[0].img.split('.').pop().split('?')[0].toLowerCase();
|
||||
const urlInputMatch = data.match(/<input[^>]+type=["']text["'][^>]+name=["']url["'][^>]+value=["']([^"']+)["']/i);
|
||||
let pageUrl = '';
|
||||
if (urlInputMatch) {
|
||||
pageUrl = urlInputMatch[1];
|
||||
}
|
||||
var redirectUrl = `${service_name}:/proxy?id=${proxy_id}&t=${imgExt}&url=${encodeURIComponent(pageUrl)}`;
|
||||
const redirectUrl = `${service_name}:/proxy?id=${proxy_id}&t=${imgExt}&url=${encodeURIComponent(pageUrl)}`;
|
||||
sendToClient(socket, {'Status': 302, 'Location': redirectUrl}, '');
|
||||
} else {
|
||||
var idx = data.indexOf('<BR>');
|
||||
data = data.substring(0, idx);
|
||||
var redirectUrl = `${service_name}:/proxy?err=${encodeURIComponent(data)}`;
|
||||
const idx = data.indexOf('<BR>');
|
||||
data = data.slice(0, idx);
|
||||
const redirectUrl = `${service_name}:/proxy?err=${encodeURIComponent(data)}`;
|
||||
sendToClient(socket, {'Status': 302, 'Location': redirectUrl}, '');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
minisrv_service_file = true;
|
||||
const minisrv_service_file = true;
|
||||
request_is_async = true;
|
||||
|
||||
proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||
let proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||
if (!proxyUrl) {
|
||||
headers = `200 OK
|
||||
Content-Type: text/html
|
||||
@@ -104,7 +104,7 @@ Location: ${service_name}:/proxy`
|
||||
} else {
|
||||
function fetch(options, post_data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
req = lib.request(options, (res) => {
|
||||
const req = lib.request(options, (res) => {
|
||||
let data = '';
|
||||
res.on('data', chunk => data += chunk);
|
||||
res.on('end', () => resolve({ text: () => Promise.resolve(data) }));
|
||||
@@ -146,8 +146,8 @@ function process(content) {
|
||||
// You can now use the `links` array as needed
|
||||
|
||||
} else {
|
||||
var idx = content.indexOf('<BR>');
|
||||
content = content.substring(0, idx);
|
||||
const idx = content.indexOf('<BR>');
|
||||
content = content.slice(0, idx);
|
||||
finishPage(content);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user