Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix:upload large file timeout #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
```sh
npm install -g node-file-manager
node-file-manager -p 8080 -d /path/to/
node-file-manager -p 8080 -d /path/to/ --user yourname --password yourpwd
```

Or
Expand All @@ -15,7 +16,7 @@ Or
cd node-file-manager
npm i
cd lib
node --harmony index.js -p 8080 -d /path/to
node --harmony index.js -p 8080 -d /path/to --user yourname --password yourpwd
```

We can run node-file-manager in terminal directly. We can specify prot add data root dir by `-p` and `-d`, default with 5000 and scripts directory.
Expand Down
40 changes: 40 additions & 0 deletions lib/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = function (app, user, password) {
app.use(function* (next) {
const challenge = `Basic realm="Node File Manager"`
let authorization = this.header['authorization']
if (authorization != null && authorization.slice(0, 6) === 'Basic ') {
authorization = new Buffer(authorization.slice(6), 'base64').toString('utf8')
const splitIndex = authorization.indexOf(':')
if (splitIndex > -1) {
const user = authorization.slice(0, splitIndex)
const password = authorization.slice(splitIndex + 1)
this.request.auth = {
user: user,
password: password
}
}
}

yield next

if (this.request.auth == null) {
this.status = 401
this.response.set('WWW-Authenticate', challenge)
}
})

app.use(function* (next) {
if (!this.request.auth) {
this.body = 'Please log in.'
return // 401 response
}

if (this.request.auth.user !== user || this.request.auth.password !== password) {
this.body = 'Invalid user.'
delete this.request.auth
return // 401 response
}

yield next
})
}
19 changes: 18 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var koaStatic = require('koa-static');
// Config
var argv = require('optimist')
.usage([
'USAGE: $0 [-p <port>] [-d <directory>]']
'USAGE: $0 [-p <port>] [-d <directory>] [--user <user>] [--password <password>]']
)
.option('port', {
alias: 'p',
Expand All @@ -29,6 +29,12 @@ var argv = require('optimist')
alias: 'h',
description: "Display This Help Message"
})
.option('user', {
description: "Username for basic http auth"
})
.option('password', {
description: "Password for basic http auth"
})
.argv;

if (argv.help) {
Expand All @@ -41,6 +47,11 @@ if (argv.version) {
process.exit(0);
}

if ((argv.user && !argv.password) || (argv.password && !argv.user)) {
console.log('Both username and password are required to enable http auth')
process.exit(0);
}

global.C = {
data: {
root: argv.directory || path.dirname('.')
Expand All @@ -58,6 +69,12 @@ var startServer = function (app, port) {
};

var app = koa();

if (argv.user && argv.password) {
var enableAuth = require('./auth')
enableAuth(app, argv.user, argv.password)
}

app.proxy = true;
app.use(Tools.handelError);
app.use(Tools.realIp);
Expand Down
2 changes: 1 addition & 1 deletion lib/public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FMApp.controller('FileManagerCtr', ['$scope', '$http', '$location',
url: url,
params: params,
data: data,
timeout: 10000
timeout: 1000000
};
for (var k in config) {
if (config.hasOwnProperty(k)) {
Expand Down