aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build/server.js35
-rw-r--r--src/server/HttpServer.hx32
-rw-r--r--src/server/cache/YoutubeCache.hx3
3 files changed, 56 insertions, 14 deletions
diff --git a/build/server.js b/build/server.js
index f142aa6..0ea2bdb 100644
--- a/build/server.js
+++ b/build/server.js
@@ -4287,16 +4287,24 @@ server_HttpServer.prototype = {
return false;
});
if(proxy2 == null) {
- res.end("Proxy error: multiple redirects for url " + tmp);
+ if(!res.headersSent) {
+ res.end("Proxy error: multiple redirects for url " + tmp);
+ }
return true;
}
req.pipe(proxy2);
+ req.on("error",function() {
+ return proxy2.destroy();
+ });
return true;
});
if(proxy == null) {
return false;
}
req.pipe(proxy);
+ req.on("error",function() {
+ return proxy.destroy();
+ });
return true;
}
,proxyRequest: function(url,req,res,cancelProxyRequest) {
@@ -4315,14 +4323,28 @@ server_HttpServer.prototype = {
var request = url1.protocol == "https:" ? js_node_Https.request : js_node_Http.request;
var proxy = request(options,function(proxyRes) {
if(cancelProxyRequest(proxyRes)) {
+ proxyRes.destroy();
return;
}
proxyRes.headers["content-type"] = "application/octet-stream";
res.writeHead(proxyRes.statusCode,proxyRes.headers);
proxyRes.pipe(res);
+ proxyRes.on("end",function() {
+ if(!res.writableEnded) {
+ res.end();
+ }
+ });
});
proxy.on("error",function(err) {
- res.end("Proxy error: " + url1.href);
+ proxy.destroy();
+ if(!res.headersSent) {
+ res.end("Proxy error: " + url1.href);
+ }
+ });
+ res.on("close",function() {
+ if(!proxy.destroyed) {
+ proxy.destroy();
+ }
});
return proxy;
}
@@ -6628,14 +6650,11 @@ server_cache_YoutubeCache.prototype = {
});
dlVideo.then(function(v) {
var tmp = _gthis.cache.findFile(function(n) {
- if(StringTools.startsWith(n,inVideoName)) {
- return StringTools.endsWith(n,".mp4");
- } else {
- return false;
- }
+ return StringTools.startsWith(n,inVideoName);
});
if(tmp == null) {
_gthis.cache.logWithAdmins(client,"Error: cannot find downloaded file with prefix " + inVideoName);
+ _gthis.cancelProgress(clientName);
return;
}
js_node_Fs.renameSync("" + _gthis.cache.cacheDir + "/" + tmp,"" + _gthis.cache.cacheDir + "/" + outName);
@@ -6645,7 +6664,7 @@ server_cache_YoutubeCache.prototype = {
});
};
this.getInfoAsync(url,useCookies).then(onGetInfo).catch(function(err) {
- haxe_Log.trace(err,{ fileName : "src/server/cache/YoutubeCache.hx", lineNumber : 214, className : "server.cache.YoutubeCache", methodName : "cacheYoutubeVideo"});
+ haxe_Log.trace(err,{ fileName : "src/server/cache/YoutubeCache.hx", lineNumber : 215, className : "server.cache.YoutubeCache", methodName : "cacheYoutubeVideo"});
useCookies = true;
return _gthis.getInfoAsync(url,useCookies).then(onGetInfo).catch(function(err) {
_gthis.cleanYtInputFiles(inVideoName);
diff --git a/src/server/HttpServer.hx b/src/server/HttpServer.hx
index b339059..f7c6d8c 100644
--- a/src/server/HttpServer.hx
+++ b/src/server/HttpServer.hx
@@ -409,17 +409,21 @@ class HttpServer {
function proxyUrl(req:IncomingMessage, res:ServerResponse):Bool {
final url = req.url.replace("/proxy?url=", "");
final proxy = proxyRequest(url, req, res, proxyRes -> {
- final url = proxyRes.headers["location"] ?? return false;
- final proxy2 = proxyRequest(url, req, res, proxyRes -> false);
+ final redirectUrl = proxyRes.headers["location"] ?? return false;
+ final proxy2 = proxyRequest(redirectUrl, req, res, proxyRes -> false);
if (proxy2 == null) {
- res.end('Proxy error: multiple redirects for url $url');
+ if (!res.headersSent) {
+ res.end('Proxy error: multiple redirects for url $redirectUrl');
+ }
return true;
}
req.pipe(proxy2);
+ req.on("error", () -> proxy2.destroy());
return true;
});
if (proxy == null) return false;
req.pipe(proxy);
+ req.on("error", () -> proxy.destroy());
return true;
}
@@ -443,16 +447,34 @@ class HttpServer {
};
req.headers["referer"] = url.toString();
req.headers["host"] = url.hostname;
+
final request = url.protocol == "https:" ? Https.request : Http.request;
final proxy = request(options, proxyRes -> {
- if (cancelProxyRequest(proxyRes)) return;
+ if (cancelProxyRequest(proxyRes)) {
+ proxyRes.destroy();
+ return;
+ }
proxyRes.headers["content-type"] = "application/octet-stream";
res.writeHead(proxyRes.statusCode, proxyRes.headers);
proxyRes.pipe(res);
+
+ // clean up when response ends
+ proxyRes.on("end", () -> {
+ if (!res.writableEnded) res.end();
+ });
});
+
proxy.on("error", err -> {
- res.end('Proxy error: ${url.href}');
+ proxy.destroy();
+ if (!res.headersSent) {
+ res.end('Proxy error: ${url.href}');
+ }
});
+ // clean up when client disconnects (seeking/abort)
+ res.on("close", () -> {
+ if (!proxy.destroyed) proxy.destroy();
+ });
+
return proxy;
}
diff --git a/src/server/cache/YoutubeCache.hx b/src/server/cache/YoutubeCache.hx
index 0618d00..158cfe1 100644
--- a/src/server/cache/YoutubeCache.hx
+++ b/src/server/cache/YoutubeCache.hx
@@ -198,9 +198,10 @@ class YoutubeCache {
});
dlVideo.then((v) -> {
- final name = cache.findFile(n -> n.startsWith(inVideoName) && n.endsWith(".mp4")) ?? {
+ final name = cache.findFile(n -> n.startsWith(inVideoName)) ?? {
final err = 'Error: cannot find downloaded file with prefix $inVideoName';
cache.logWithAdmins(client, err);
+ cancelProgress(clientName);
return;
};
FileSystem.rename('${cache.cacheDir}/$name', '${cache.cacheDir}/$outName');
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage