fix/optimize wtv-news, wtv-proxy, wtv-register, wtv-search, wtv-setup, wtv-star
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
minisrv_service_file = true;
|
||||
const minisrv_service_file = true;
|
||||
request_is_async = true;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ request_is_async = true;
|
||||
async function handleRequest(request_headers) {
|
||||
const imageUrl = request_headers.query.url;
|
||||
if (!imageUrl) {
|
||||
var errpage = wtvshared.doErrorPage(400, "Missing url parameter");
|
||||
const errpage = wtvshared.doErrorPage(400, "Missing url parameter");
|
||||
sendToClient(socket, errpage[0], errpage[1]);
|
||||
return;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ async function handleRequest(request_headers) {
|
||||
const lib = urlObj.protocol === 'https:' ? https : http;
|
||||
const fetch = (lib, options) => new Promise((resolve, reject) => {
|
||||
const req = lib.request(imageUrl, options, (res) => {
|
||||
let data = [];
|
||||
const data = [];
|
||||
res.on('data', chunk => data.push(chunk));
|
||||
res.on('end', () => {
|
||||
res.buffer = async () => Buffer.concat(data);
|
||||
@@ -29,7 +29,7 @@ async function handleRequest(request_headers) {
|
||||
});
|
||||
const imgRes = await fetch(lib, { method: 'GET', headers: { 'User-Agent': 'Mozilla/4.0 WebTV/2.6 (compatible; MSIE 4.0)' } });
|
||||
if (!imgRes.ok) {
|
||||
var errpage = wtvshared.doErrorPage(502, "Failed to fetch image");
|
||||
const errpage = wtvshared.doErrorPage(502, "Failed to fetch image");
|
||||
sendToClient(socket, errpage[0], errpage[1]);
|
||||
return;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ Content-Type: image/png`;
|
||||
data = resized;
|
||||
sendToClient(socket, headers, data);
|
||||
} catch (err) {
|
||||
var errpage = wtvshared.doErrorPage(500, "Error processing image: " + err.message);
|
||||
const errpage = wtvshared.doErrorPage(500, "Error processing image: " + err.message);
|
||||
sendToClient(socket, errpage[0], errpage[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
minisrv_service_file = true;
|
||||
const minisrv_service_file = true;
|
||||
request_is_async = true;
|
||||
|
||||
var searchUrl = minisrv_config.services[service_name].searxng_url;
|
||||
let searchUrl = minisrv_config.services[service_name].searxng_url;
|
||||
if (!searchUrl.endsWith('/')) {
|
||||
searchUrl += '/';
|
||||
}
|
||||
@@ -42,7 +42,7 @@ if (!request_headers.query.q) {
|
||||
params.append('limit', '10');
|
||||
const urlObj = new URL(searchUrl);
|
||||
const lib = urlObj.protocol === 'https:' ? https : http;
|
||||
var post_data = params.toString();
|
||||
const post_data = params.toString();
|
||||
const options = {
|
||||
protocol: urlObj.protocol,
|
||||
hostname: urlObj.hostname,
|
||||
@@ -68,7 +68,7 @@ if (!request_headers.query.q) {
|
||||
|
||||
function fetch(lib, options, post_data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var 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) }));
|
||||
|
||||
Reference in New Issue
Block a user