Browse Source

Kinda working

Noah 8 years ago
parent
commit
17a13a5483
4 changed files with 16 additions and 23 deletions
  1. 4 6
      audiogram/index.js
  2. 4 1
      bin/worker
  3. 8 7
      server/render.js
  4. 0 9
      test/frame-test.js

+ 4 - 6
audiogram/index.js View File

@@ -12,12 +12,10 @@ var path = require("path"),
12 12
     combineFrames = require("./combine-frames.js"),
13 13
     trimAudio = require("./trim.js");
14 14
 
15
-function Audiogram(settings) {
15
+function Audiogram(id) {
16 16
 
17 17
   // Unique audiogram ID
18
-  this.id = settings.id;
19
-
20
-  this.settings = settings;
18
+  this.id = id;
21 19
 
22 20
   // File locations to use
23 21
   this.dir = path.join(serverSettings.workingDirectory, this.id);
@@ -66,7 +64,7 @@ Audiogram.prototype.getWaveform = function(cb) {
66 64
     samplesPerFrame: this.settings.samplesPerFrame
67 65
   }, function(err, waveform){
68 66
 
69
-    return cb(err, self.settings.waveform = waveform);
67
+    return cb(err, self.waveform = waveform);
70 68
 
71 69
   });
72 70
 
@@ -120,7 +118,7 @@ Audiogram.prototype.drawFrames = function(cb) {
120 118
       numFrames: self.numFrames,
121 119
       frameDir: self.frameDir,
122 120
       caption: self.settings.caption,
123
-      waveform: self.settings.waveform,
121
+      waveform: self.waveform,
124 122
       tick: function() {
125 123
         transports.incrementField(self.id, "framesComplete");
126 124
       }

+ 4 - 1
bin/worker View File

@@ -30,7 +30,10 @@ function pluckJob(){
30 30
 
31 31
 function render(settings) {
32 32
 
33
-  var audiogram = new Audiogram(settings);
33
+  var audiogram = new Audiogram(settings.id);
34
+
35
+  // TODO rename to theme
36
+  audiogram.settings = settings;
34 37
 
35 38
   audiogram.render(function(err){
36 39
 

+ 8 - 7
server/render.js View File

@@ -2,7 +2,6 @@ var serverSettings = require("../settings/"),
2 2
     spawn = require("child_process").spawn,
3 3
     path = require("path"),
4 4
     _ = require("underscore"),
5
-    Audiogram = require("../audiogram/"),
6 5
     logger = require("../lib/logger"),
7 6
     transports = require("../lib/transports");
8 7
 
@@ -22,8 +21,6 @@ function validate(req, res, next) {
22 21
     return res.status(500).send("No valid audio received.");
23 22
   }
24 23
 
25
-  req.body.settings.id = req.file.destination.split(path.sep).pop();
26
-
27 24
   // Start at the beginning, or specified time
28 25
   if (req.body.settings.start) {
29 26
     req.body.settings.start = +req.body.settings.start;
@@ -39,18 +36,22 @@ function validate(req, res, next) {
39 36
 
40 37
 function route(req, res) {
41 38
 
42
-  var audiogram = new Audiogram(req.body.settings);
39
+  var id = req.file.destination.split(path.sep).pop();
43 40
 
44
-  transports.uploadAudio(audiogram.audioPath, "audio/" + audiogram.id,function(err) {
41
+  transports.uploadAudio(path.join(req.file.destination, "audio"), "audio/" + id,function(err) {
45 42
 
46 43
     if (err) {
47 44
       throw err;
48 45
     }
49 46
 
50 47
     // Queue up the job with a timestamp
51
-    transports.addJob(_.extend({ created: (new Date()).getTime() }, req.body.settings));
48
+    transports.addJob({
49
+      created: (new Date()).getTime(),
50
+      settings: req.body.settings,
51
+      caption: req.body.caption
52
+    });
52 53
 
53
-    res.json({ id: req.body.settings.id });
54
+    res.json({ id: id });
54 55
 
55 56
     // If there's no separate worker, spawn one right away
56 57
     if (!serverSettings.worker) {

+ 0 - 9
test/frame-test.js View File

@@ -25,9 +25,6 @@ tape.test("Draw frame", function(test){
25 25
   initializeCanvas(options, function(err, renderer){
26 26
 
27 27
     test.error(err);
28
-    test.assert(renderer.context.canvas instanceof Canvas);
29
-    test.assert(renderer.context.canvas.width === options.width);
30
-    test.assert(renderer.context.canvas.height === options.height);
31 28
 
32 29
     drawFrames(renderer, {
33 30
       numFrames: 2,
@@ -54,9 +51,6 @@ tape.test("Default colors", function(test){
54 51
   initializeCanvas(options, function(err, renderer){
55 52
 
56 53
     test.error(err);
57
-    test.assert(renderer.context.canvas instanceof Canvas);
58
-    test.assert(renderer.context.canvas.width === options.width);
59
-    test.assert(renderer.context.canvas.height === options.height);
60 54
 
61 55
     drawFrames(renderer, {
62 56
       numFrames: 2,
@@ -85,9 +79,6 @@ tape.test("Square frame", function(test){
85 79
   initializeCanvas(options, function(err, renderer){
86 80
 
87 81
     test.error(err);
88
-    test.assert(renderer.context.canvas instanceof Canvas);
89
-    test.assert(renderer.context.canvas.width === options.width);
90
-    test.assert(renderer.context.canvas.height === options.height);
91 82
 
92 83
     drawFrames(renderer, {
93 84
       numFrames: 2,