Browse Source

Merge branch 'live-load'

Noah 7 years ago
parent
commit
e4d5bfdb38
5 changed files with 42 additions and 18 deletions
  1. 0 4
      THEMES.md
  2. 1 1
      bin/worker
  3. 26 10
      client/index.js
  4. 14 2
      server/index.js
  5. 1 1
      test/server-test.js

+ 0 - 4
THEMES.md View File

75
 * `foregroundColor` - A convenience option for setting `waveColor` and `captionColor` to the same thing.
75
 * `foregroundColor` - A convenience option for setting `waveColor` and `captionColor` to the same thing.
76
 * `maxDuration` - Maximum duration of an audiogram, in seconds (e.g. set this to `30` to enforce a 30-second time limit). The default is `300` (5 minutes).
76
 * `maxDuration` - Maximum duration of an audiogram, in seconds (e.g. set this to `30` to enforce a 30-second time limit). The default is `300` (5 minutes).
77
 
77
 
78
-### Making changes
79
-
80
-After you've edited `settings/themes.json`, you'll want to run either `npm run rebuild` or `npm start` to rebundle the new themes for the editor.
81
-
82
 ### A note about fonts
78
 ### A note about fonts
83
 
79
 
84
 By default, Audiogram will already have access to fonts on your system.  This might be fine for local use, but it will become a problem on a server without the fonts you're used to, or if you want to use a specific font across lots of installations.
80
 By default, Audiogram will already have access to fonts on your system.  This might be fine for local use, but it will become a problem on a server without the fonts you're used to, or if you want to use a specific font across lots of installations.

+ 1 - 1
bin/worker View File

36
 
36
 
37
     if (err) {
37
     if (err) {
38
       audiogram.status("error");
38
       audiogram.status("error");
39
-      audiogram.set("error", err);
39
+      audiogram.set("error", err.toString());
40
       throw err;
40
       throw err;
41
     }
41
     }
42
 
42
 

+ 26 - 10
client/index.js View File

1
 var d3 = require("d3"),
1
 var d3 = require("d3"),
2
     $ = require("jquery"),
2
     $ = require("jquery"),
3
-    themes = require("../settings/themes.json"),
4
     preview = require("./preview.js"),
3
     preview = require("./preview.js"),
5
     video = require("./video.js"),
4
     video = require("./video.js"),
6
     audio = require("./audio.js");
5
     audio = require("./audio.js");
7
 
6
 
8
-preloadImages();
7
+d3.json("/settings/themes.json", function(err, themes){
8
+
9
+  if (err) {
10
+    throw err;
11
+  }
12
+
13
+  for (var key in themes) {
14
+    themes[key] = $.extend({}, themes.default, themes[key]);
15
+  }
16
+
17
+  preloadImages(themes);
18
+
19
+});
9
 
20
 
10
 function submitted() {
21
 function submitted() {
11
 
22
 
76
         if (result && result.status && result.status === "ready" && result.url) {
87
         if (result && result.status && result.status === "ready" && result.url) {
77
           video.update(result.url, preview.theme().name);
88
           video.update(result.url, preview.theme().name);
78
           setClass("rendered");
89
           setClass("rendered");
90
+        } else if (result.status === "error") {
91
+          error(result.error);
79
         } else {
92
         } else {
80
           d3.select("#loading-message").text(statusMessage(result));
93
           d3.select("#loading-message").text(statusMessage(result));
81
           poll(id);
94
           poll(id);
97
     msg = JSON.stringify(msg);
110
     msg = JSON.stringify(msg);
98
   }
111
   }
99
 
112
 
113
+  if (!msg) {
114
+    msg = "Unknown error";
115
+  }
116
+
100
   d3.select("#loading-message").text("Loading...");
117
   d3.select("#loading-message").text("Loading...");
101
   setClass("error", msg);
118
   setClass("error", msg);
102
 
119
 
192
 }
209
 }
193
 
210
 
194
 function updateTheme() {
211
 function updateTheme() {
195
-  var extended = $.extend({}, themes.default, d3.select(this.options[this.selectedIndex]).datum());
196
-  preview.theme(extended);
212
+  preview.theme(d3.select(this.options[this.selectedIndex]).datum());
197
 }
213
 }
198
 
214
 
199
-function preloadImages() {
215
+function preloadImages(themes) {
200
 
216
 
201
   // preload images
217
   // preload images
202
   var imageQueue = d3.queue();
218
   var imageQueue = d3.queue();
215
 
231
 
216
   imageQueue.awaitAll(initialize);
232
   imageQueue.awaitAll(initialize);
217
 
233
 
218
-  function getImage(theme,cb) {
234
+  function getImage(theme, cb) {
219
 
235
 
220
     if (!theme.backgroundImage) {
236
     if (!theme.backgroundImage) {
221
-      return cb(null,theme);
237
+      return cb(null, theme);
222
     }
238
     }
223
 
239
 
224
     theme.backgroundImageFile = new Image();
240
     theme.backgroundImageFile = new Image();
225
     theme.backgroundImageFile.onload = function(){
241
     theme.backgroundImageFile.onload = function(){
226
-      return cb(null,theme);
242
+      return cb(null, theme);
227
     };
243
     };
228
     theme.backgroundImageFile.onerror = function(e){
244
     theme.backgroundImageFile.onerror = function(e){
229
       console.warn(e);
245
       console.warn(e);
230
-      return cb(null,theme);
246
+      return cb(null, theme);
231
     };
247
     };
232
 
248
 
233
-    theme.backgroundImageFile.src = "img/" + theme.backgroundImage;
249
+    theme.backgroundImageFile.src = "/settings/backgrounds/" + theme.backgroundImage;
234
 
250
 
235
   }
251
   }
236
 
252
 

+ 14 - 2
server/index.js View File

62
 // Check the status of a current video
62
 // Check the status of a current video
63
 app.get("/status/:id/", status);
63
 app.get("/status/:id/", status);
64
 
64
 
65
-// Serve background images and everything else statically
66
-app.use("/img/", express.static(path.join(__dirname, "..", "settings", "backgrounds")));
65
+
66
+// Serve background images and themes JSON statically
67
+app.use("/settings/", function(req, res, next) {
68
+
69
+  // Limit to themes.json and bg images
70
+  if (req.url.match(/^\/?themes.json$/i) || req.url.match(/^\/?backgrounds\/[^/]+$/i)) {
71
+    return next();
72
+  }
73
+
74
+  return res.status(404).send("Cannot GET " + path.join("/settings", req.url));
75
+
76
+}, express.static(path.join(__dirname, "..", "settings")));
77
+
78
+// Serve editor files statically
67
 app.use(express.static(path.join(__dirname, "..", "editor")));
79
 app.use(express.static(path.join(__dirname, "..", "editor")));
68
 
80
 
69
 app.use(errorHandlers);
81
 app.use(errorHandlers);

+ 1 - 1
test/server-test.js View File

69
 tape("Server static background", function(test) {
69
 tape("Server static background", function(test) {
70
 
70
 
71
   request(server)
71
   request(server)
72
-    .get("/img/nyc.png")
72
+    .get("/settings/backgrounds/nyc.png")
73
     .expect(200)
73
     .expect(200)
74
     .expect("Content-Type", /image/)
74
     .expect("Content-Type", /image/)
75
     .end(function(err, res){
75
     .end(function(err, res){