Skip to content
Snippets Groups Projects
Commit 38365fd5 authored by echicken's avatar echicken :chicken:
Browse files

Fixed busted file transfer crap.

parent 427406b2
Branches
Tags
No related merge requests found
...@@ -4,10 +4,8 @@ load(settings.web_lib + 'files.js'); ...@@ -4,10 +4,8 @@ load(settings.web_lib + 'files.js');
load('filebase.js'); load('filebase.js');
var reply = {}; var reply = {};
if ((http_request.method === 'GET' || http_request.method === 'POST') && if ((http_request.method === 'GET' || http_request.method === 'POST') &&
typeof http_request.query.call !== 'undefined' && typeof http_request.query.call !== 'undefined' && user.number > 0
user.number > 0 && user.alias !== settings.guest
) { ) {
switch (http_request.query.call[0].toLowerCase()) { switch (http_request.query.call[0].toLowerCase()) {
...@@ -30,16 +28,15 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') && ...@@ -30,16 +28,15 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') &&
} }
); );
if (file === null) break; if (file === null) break;
client.socket.send('HTTP/1.0 Status: 200 OK\r\n'); http_reply.header['Content-Type'] = 'application/octet-stream';
client.socket.send('Content-Type: application/octet-stream\r\n'); http_reply.header['Content-Disposition'] = 'attachment; filename="' + file.base + '.' + file.ext + '"';
client.socket.send('Content-Disposition: attachment; filename="' + file.base + '.' + file.ext + '";\r\n'); http_reply.header['Content-Encoding'] = 'binary';
client.socket.send('Content-Transfer-Encoding: binary\r\n'); http_reply.header['Content-Length'] = file_size(file.path);
client.socket.send('Content-Length: ' + file_size(file.path) + '\r\n');
client.socket.send('\r\n');
var f = new File(file.path); var f = new File(file.path);
f.open('r+b'); f.open('rb');
while (!f.eof) { for (var n = 0; n < file_size(file.path); n++) {
client.socket.sendBin(f.readBin(1), 1); var r = f.length - f.position;
write(f.read(r > 512 ? 512 : r));
} }
f.close(); f.close();
reply = false; reply = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment