forked from radiofrequency/jquery-file-upload-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (50 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var _ = require('lodash'),
EventEmitter = require('events').EventEmitter,
os = require("os");
var JqueryFileUploadMiddleware = function () {
EventEmitter.call(this);
// setting default options
this.options = this.prepareOptions({});
};
require('util').inherits(JqueryFileUploadMiddleware, EventEmitter);
JqueryFileUploadMiddleware.prototype.prepareOptions = function (options) {
options = _.extend({
tmpDir: os.tmpdir(),
uploadDir: __dirname + '/public/files',
uploadUrl: '/files/',
maxPostSize: 11000000000, // 11 GB
minFileSize: 1,
maxFileSize: 10000000000, // 10 GB
acceptFileTypes: /.+/i,
imageTypes: /\.(gif|jpe?g|png)$/i,
imageVersions: {
// thumbnail: {
// width: 80,
// height: 80
// }
},
accessControl: {
allowOrigin: '*',
allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE'
}
}, options);
_.each(['uploadDir', 'uploadUrl'], function (key) {
if (!_.isFunction(options[key])) {
var originalValue = options[key];
options[key] = function () {
return originalValue
};
}
});
return options;
}
JqueryFileUploadMiddleware.prototype.configure = function (options) {
this.options = this.prepareOptions(options);
};
JqueryFileUploadMiddleware.prototype.fileHandler = function (options) {
return require('./lib/filehandler')(this, this.prepareOptions(_.extend(this.options, options)));
};
JqueryFileUploadMiddleware.prototype.fileManager = function (options) {
return require('./lib/filemanager')(this, this.prepareOptions(_.extend(this.options, options)));
};
module.exports = new JqueryFileUploadMiddleware();