mirror of
				https://git.coolaj86.com/coolaj86/telebit.js.git
				synced 2025-11-03 10:12:46 +00:00 
			
		
		
		
	v0.20.0-wip: enable direct download of files via serve-index/serve-static
This commit is contained in:
		
							parent
							
								
									fb8aa998b3
								
							
						
					
					
						commit
						687b2a3567
					
				@ -362,21 +362,47 @@ module.exports.assign = function (state, tun, cb) {
 | 
				
			|||||||
        state._serveIndex = require('serve-index');
 | 
					        state._serveIndex = require('serve-index');
 | 
				
			||||||
        var serveIndex;
 | 
					        var serveIndex;
 | 
				
			||||||
        var serveStatic;
 | 
					        var serveStatic;
 | 
				
			||||||
 | 
					        var dlStatic;
 | 
				
			||||||
        if (isFile) {
 | 
					        if (isFile) {
 | 
				
			||||||
          serveStatic = state._serveStatic(path.dirname(conf.handler), { dotfiles: 'allow', index: [ 'index.html' ] });
 | 
					          serveStatic = state._serveStatic(path.dirname(conf.handler), { dotfiles: 'allow', index: [ 'index.html' ] });
 | 
				
			||||||
 | 
					          dlStatic = state._serveStatic(path.dirname(conf.handler), { acceptRanges: false, dotfiles: 'allow', index: [ 'index.html' ] });
 | 
				
			||||||
          serveIndex = function (req, res, next) { next(); };
 | 
					          serveIndex = function (req, res, next) { next(); };
 | 
				
			||||||
          isFile = path.basename(conf.handler);
 | 
					          isFile = path.basename(conf.handler);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          serveStatic = state._serveStatic(conf.handler, { dotfiles: 'allow', index: [ 'index.html' ] });
 | 
					          serveStatic = state._serveStatic(conf.handler, { dotfiles: 'allow', index: [ 'index.html' ] });
 | 
				
			||||||
          serveIndex = state._serveIndex(conf.handler, { hidden: true, icons: true, view: 'tiles' });
 | 
					          dlStatic = state._serveStatic(conf.handler, { acceptRanges: false, dotfiles: 'allow', index: [ 'index.html' ] });
 | 
				
			||||||
 | 
					          serveIndex = state._serveIndex(conf.handler, {
 | 
				
			||||||
 | 
					            hidden: true, icons: true
 | 
				
			||||||
 | 
					          , template: require('serve-tpl-attachment')({ privatefiles: 'ignore' })
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        handler = function (req, res) {
 | 
					        handler = function (req, res) {
 | 
				
			||||||
 | 
					          var qIndex = req.url.indexOf('?');
 | 
				
			||||||
 | 
					          var fIndex;
 | 
				
			||||||
 | 
					          var fname;
 | 
				
			||||||
 | 
					          if (-1 === qIndex) {
 | 
				
			||||||
 | 
					            qIndex = req.url.length;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          req.querystring = req.url.substr(qIndex);
 | 
				
			||||||
 | 
					          req.url = req.url.substr(0, qIndex);
 | 
				
			||||||
 | 
					          req.query = require('querystring').parse(req.querystring.substr(1));
 | 
				
			||||||
          if (isFile) {
 | 
					          if (isFile) {
 | 
				
			||||||
            req.url = '/' + isFile;
 | 
					            req.url = '/' + isFile;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          serveStatic(req, res, function () {
 | 
					          //console.log('[req.query]', req.url, req.query);
 | 
				
			||||||
            serveIndex(req, res, state._finalHandler(req, res));
 | 
					          if (req.query.download) {
 | 
				
			||||||
          });
 | 
					            fIndex = req.url.lastIndexOf('/');
 | 
				
			||||||
 | 
					            fname = req.url.substr(fIndex + 1);
 | 
				
			||||||
 | 
					            res.setHeader('Content-Disposition', 'attachment; filename="'+decodeURIComponent(fname)+'"');
 | 
				
			||||||
 | 
					            res.setHeader('Content-Type', 'application/octet-stream');
 | 
				
			||||||
 | 
					            dlStatic(req, res, function () {
 | 
				
			||||||
 | 
					              serveIndex(req, res, state._finalHandler(req, res));
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            serveStatic(req, res, function () {
 | 
				
			||||||
 | 
					              serveIndex(req, res, state._finalHandler(req, res));
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        handlerservers[conf.handler] = http.createServer(handler);
 | 
					        handlerservers[conf.handler] = http.createServer(handler);
 | 
				
			||||||
        handlerservers[conf.handler].emit('connection', tlsSocket);
 | 
					        handlerservers[conf.handler].emit('connection', tlsSocket);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "telebit",
 | 
					  "name": "telebit",
 | 
				
			||||||
  "version": "0.19.28",
 | 
					  "version": "0.20.0-wip",
 | 
				
			||||||
  "description": "Break out of localhost. Connect to any device from anywhere over any tcp port or securely in a browser. A secure tunnel. A poor man's reverse VPN.",
 | 
					  "description": "Break out of localhost. Connect to any device from anywhere over any tcp port or securely in a browser. A secure tunnel. A poor man's reverse VPN.",
 | 
				
			||||||
  "main": "lib/remote.js",
 | 
					  "main": "lib/remote.js",
 | 
				
			||||||
  "files": [
 | 
					  "files": [
 | 
				
			||||||
@ -59,12 +59,13 @@
 | 
				
			|||||||
    "js-yaml": "^3.11.0",
 | 
					    "js-yaml": "^3.11.0",
 | 
				
			||||||
    "jsonwebtoken": "^7.1.9",
 | 
					    "jsonwebtoken": "^7.1.9",
 | 
				
			||||||
    "mkdirp": "^0.5.1",
 | 
					    "mkdirp": "^0.5.1",
 | 
				
			||||||
    "proxy-packer": "^2.0.0",
 | 
					    "proxy-packer": "^2.0.2",
 | 
				
			||||||
    "ps-list": "^5.0.0",
 | 
					    "ps-list": "^5.0.0",
 | 
				
			||||||
    "recase": "^1.0.4",
 | 
					    "recase": "^1.0.4",
 | 
				
			||||||
    "redirect-https": "^1.1.5",
 | 
					    "redirect-https": "^1.1.5",
 | 
				
			||||||
    "serve-index": "^1.9.1",
 | 
					    "serve-index": "^1.9.1",
 | 
				
			||||||
    "serve-static": "^1.13.2",
 | 
					    "serve-static": "^1.13.2",
 | 
				
			||||||
 | 
					    "serve-tpl-attachment": "^1.0.1",
 | 
				
			||||||
    "sni": "^1.0.0",
 | 
					    "sni": "^1.0.0",
 | 
				
			||||||
    "socket-pair": "^1.0.3",
 | 
					    "socket-pair": "^1.0.3",
 | 
				
			||||||
    "ws": "^2.3.1"
 | 
					    "ws": "^2.3.1"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user