forked from apostrophecms/uploadfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed-test.js
80 lines (71 loc) · 1.6 KB
/
speed-test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var uploadfs = require('./uploadfs.js')();
var fs = require('fs');
var _ = require('lodash');
var async = require('async');
var localOptions = { backend: 'local', uploadsPath: __dirname + '/test', uploadsUrl: 'http://localhost:3000/test' };
var imageSizes = [
{
name: 'full',
width: 1140,
height: 1140
},
{
name: 'two-thirds',
width: 760,
height: 760
},
{
name: 'one-half',
width: 570,
height: 700
},
{
name: 'one-third',
width: 380,
height: 700
},
// Handy for thumbnailing
{
name: 'one-sixth',
width: 190,
height: 350
}
];
var tempPath = __dirname + '/temp';
localOptions.imageSizes = imageSizes;
localOptions.tempPath = tempPath;
var options;
var start = (new Date()).getTime();
async.series({
init: function(callback) {
options = localOptions;
console.log('Initializing uploadfs for the ' + options.backend + ' backend');
return uploadfs.init(options, function(e) {
if (e) {
console.log('uploadfs.init failed:');
console.log(e);
process.exit(1);
}
return callback(null);
});
},
copyImageIn: function(callback) {
// Note copyImageIn adds an extension for us
uploadfs.copyImageIn('test.jpg', '/images/profiles/me', function(e, info) {
if (e) {
console.log('testCopyImageIn failed:');
console.log(e);
process.exit(1);
}
return callback(null);
});
}
}, function(err) {
if (err) {
console.error('Failed');
process.exit(1);
}
var end = (new Date()).getTime();
console.log((end - start) + 'ms');
process.exit(0);
});