Skip to content
This repository was archived by the owner on Mar 25, 2019. It is now read-only.

Commit d363154

Browse files
author
Sjoerd Tieleman
committed
Merge pull request #48 from brain64bit/sanitize-null
sanitize null values before being put into SQL statement
2 parents eb6114f + 290b220 commit d363154

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

lib/job.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ var StatusCodes = {
1919

2020
var JobUtils = {
2121
sql: null,
22-
22+
2323
generateThumbnailPath: function(destinationFile, offset, format) {
24-
return [path.dirname(destinationFile), path.basename(destinationFile, path.extname(destinationFile))].join(path.sep) + "-" + offset + "." + format;
24+
return [path.dirname(destinationFile), path.basename(destinationFile, path.extname(destinationFile))].join(path.sep) + "-" + offset + "." + format;
2525
},
26-
26+
2727
generateRangeFromThumbOpts: function(thumbOpts, duration) {
2828
if (thumbOpts['percentages']) {
2929
// percentage based thumbnails
@@ -35,7 +35,7 @@ var JobUtils = {
3535
return null;
3636
}
3737
},
38-
38+
3939
getDatabase: function() {
4040
if (JobUtils.sql == null) {
4141
if (config['database']['dialect'] == "sqlite") {
@@ -50,6 +50,7 @@ var JobUtils = {
5050
storage: config['database']['database'],
5151
host: config['database']['host'],
5252
port: config['database']['port'],
53+
omitNull: true
5354
pool: false,
5455
logging: false
5556
});
@@ -74,7 +75,7 @@ var JobUtils = {
7475
});
7576
callback(null);
7677
},
77-
78+
7879
migrateDatabase: function(callback) {
7980
var migrator = JobUtils.getDatabase().getMigrator({path: __dirname + "/../migrations" });
8081
migrator.migrate().success(function() {
@@ -83,14 +84,14 @@ var JobUtils = {
8384
callback(err);
8485
});
8586
},
86-
87+
8788
pad: function(orig, padString, length) {
8889
var str = orig;
8990
while (str.length < length)
9091
str = padString + str;
9192
return str;
9293
},
93-
94+
9495
percentagesToRange: function(percentages, duration) {
9596
if (Array.isArray(percentages)) {
9697
// explicit percentages
@@ -104,7 +105,7 @@ var JobUtils = {
104105
return offsets;
105106
}
106107
},
107-
108+
108109
secondsToRange: function(seconds, duration) {
109110
if (Array.isArray(seconds)) {
110111
// explicit percentages
@@ -118,7 +119,7 @@ var JobUtils = {
118119
return offsets;
119120
}
120121
},
121-
122+
122123
verifyDatabase: function(callback) {
123124
JobUtils.getDatabase().getQueryInterface().showAllTables().success(function (tables) {
124125
if (tables.length > 0 && tables.indexOf('SequelizeMeta') == -1) {
@@ -220,12 +221,12 @@ var Job = JobUtils.getDatabase().define('Job', {
220221
if (err) {
221222
fs.stat(destination_dir, function(err, stats) {
222223
if (err) {
223-
job.exitHandler(-1, "unable to create output directory (" + destination_dir + ").");
224+
job.exitHandler(-1, "unable to create output directory (" + destination_dir + ").");
224225
} else {
225226
if (stats.isDirectory()) {
226-
callback("hasOutputDir");
227+
callback("hasOutputDir");
227228
} else {
228-
job.exitHandler(-1, "unable to create output directory (" + destination_dir + ").");
229+
job.exitHandler(-1, "unable to create output directory (" + destination_dir + ").");
229230
}
230231
}
231232
});
@@ -265,8 +266,8 @@ var Job = JobUtils.getDatabase().define('Job', {
265266
var null_file = (!!os.platform().match(/^win/) ? 'nul' : '/dev/null');
266267
args.push('-f', 'null', '-acodec', 'copy', '-vcodec', 'copy', '-y', null_file);
267268
}
268-
269-
var the_process = child_process.spawn(config['encoder'], args);
269+
270+
var the_process = child_process.spawn(config['encoder'], args);
270271

271272
the_process.stderr.on('data', function(data) { job.progressHandler(data); });
272273
the_process.on('error', function(err) { job.lastMessage = 'Unable to execute the ffmpeg binary: ' + err; job.didFinish(1); });
@@ -316,7 +317,7 @@ var Job = JobUtils.getDatabase().define('Job', {
316317
var playlistPath = [playlistDir, playlistName].join(path.sep) + '.m3u8';
317318
var segmentsFormat = [playlistDir, playlistName].join(path.sep) + '-%06d.ts'
318319
var inputFile = (this.parsedOpts()['encoder_options'].length > 0) ? job.tmpFile : this.parsedOpts()['source_file']
319-
320+
320321
args.push('-i', inputFile,
321322
'-codec', 'copy', '-map', '0', '-f', 'segment',
322323
'-vbsf', 'h264_mp4toannexb', '-flags', '-global_header',
@@ -386,19 +387,19 @@ var Job = JobUtils.getDatabase().define('Job', {
386387
return function(callback) {
387388
var thumbOpts = job.parsedOpts()['thumbnail_options'];
388389
var args = ['-ss', offset, '-i', job.parsedOpts()['source_file'], '-vframes', '1', '-y'];
389-
390+
390391
// Explicit size provided
391392
if (thumbOpts['size'] && thumbOpts['size'] != 'src') {
392393
args.push('-s', thumbOpts['size']);
393394
}
394395

395396
var format = thumbOpts['format'] ? thumbOpts['format'] : 'jpg';
396397
var destinationFile = job.parsedOpts()['destination_file'];
397-
398+
398399
// Destination file + offset + extension
399400
var outputFile = JobUtils.generateThumbnailPath(destinationFile, offset, format);
400401
args.push(outputFile);
401-
402+
402403
var thumb_process = child_process.execFile(config['encoder'], args, { maxBuffer: 4096*1024 }, function(error, stdout, stderr) {
403404
if (error) {
404405
callback(new Error('Error while generating thumbnail: ' + error.message), null);
@@ -474,7 +475,7 @@ var Job = JobUtils.getDatabase().define('Job', {
474475
},
475476
progressHandler: function(data) {
476477
if (this.hasExited) return;
477-
478+
478479
this.lastMessage = data.toString().replace("\n",'');
479480

480481
(isNaN(this.duration) || this.duration == 0) ? this.extractDuration(data.toString()) : this.extractProgress(data.toString());
@@ -483,7 +484,7 @@ var Job = JobUtils.getDatabase().define('Job', {
483484
// successfull save
484485
}).error(function(err) {
485486
// error while saving job
486-
});
487+
});
487488
},
488489
extractDuration: function(text) {
489490
if (!this.durationBuffer) this.durationBuffer = "";
@@ -497,11 +498,11 @@ var Job = JobUtils.getDatabase().define('Job', {
497498

498499
this.duration = hours * 3600 + minutes * 60 + seconds;
499500
notifyHandler.notify(this);
500-
}
501+
}
501502
},
502503
extractProgress: function(text) {
503504
// 00:00:00 (hours, minutes, seconds)
504-
var re = new RegExp(/time=(\d{2}):(\d{2}):(\d{2})/);
505+
var re = new RegExp(/time=(\d{2}):(\d{2}):(\d{2})/);
505506
var m = re.exec(text);
506507

507508
if (m != null) {
@@ -510,7 +511,7 @@ var Job = JobUtils.getDatabase().define('Job', {
510511
this.progress = current / this.duration;
511512
} else {
512513
// 00.00 (seconds, hundreds)
513-
re = new RegExp(/time=(\d+).(\d{2})/);
514+
re = new RegExp(/time=(\d+).(\d{2})/);
514515
m = re.exec(text);
515516

516517
if (m != null) {

0 commit comments

Comments
 (0)