ソースを参照

Merge branch 'live-load'

Noah 7 年 前
コミット
e4d5bfdb38
共有5 個のファイルを変更した42 個の追加18 個の削除を含む
  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 ファイルの表示

@@ -75,10 +75,6 @@ Note that if you change `waveLeft` or `waveRight` to something other than full-w
75 75
 * `foregroundColor` - A convenience option for setting `waveColor` and `captionColor` to the same thing.
76 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 78
 ### A note about fonts
83 79
 
84 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 ファイルの表示

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

+ 26 - 10
client/index.js ファイルの表示

@@ -1,11 +1,22 @@
1 1
 var d3 = require("d3"),
2 2
     $ = require("jquery"),
3
-    themes = require("../settings/themes.json"),
4 3
     preview = require("./preview.js"),
5 4
     video = require("./video.js"),
6 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 21
 function submitted() {
11 22
 
@@ -76,6 +87,8 @@ function poll(id) {
76 87
         if (result && result.status && result.status === "ready" && result.url) {
77 88
           video.update(result.url, preview.theme().name);
78 89
           setClass("rendered");
90
+        } else if (result.status === "error") {
91
+          error(result.error);
79 92
         } else {
80 93
           d3.select("#loading-message").text(statusMessage(result));
81 94
           poll(id);
@@ -97,6 +110,10 @@ function error(msg) {
97 110
     msg = JSON.stringify(msg);
98 111
   }
99 112
 
113
+  if (!msg) {
114
+    msg = "Unknown error";
115
+  }
116
+
100 117
   d3.select("#loading-message").text("Loading...");
101 118
   setClass("error", msg);
102 119
 
@@ -192,11 +209,10 @@ function updateCaption() {
192 209
 }
193 210
 
194 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 217
   // preload images
202 218
   var imageQueue = d3.queue();
@@ -215,22 +231,22 @@ function preloadImages() {
215 231
 
216 232
   imageQueue.awaitAll(initialize);
217 233
 
218
-  function getImage(theme,cb) {
234
+  function getImage(theme, cb) {
219 235
 
220 236
     if (!theme.backgroundImage) {
221
-      return cb(null,theme);
237
+      return cb(null, theme);
222 238
     }
223 239
 
224 240
     theme.backgroundImageFile = new Image();
225 241
     theme.backgroundImageFile.onload = function(){
226
-      return cb(null,theme);
242
+      return cb(null, theme);
227 243
     };
228 244
     theme.backgroundImageFile.onerror = function(e){
229 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 ファイルの表示

@@ -62,8 +62,20 @@ if (!serverSettings.s3Bucket) {
62 62
 // Check the status of a current video
63 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 79
 app.use(express.static(path.join(__dirname, "..", "editor")));
68 80
 
69 81
 app.use(errorHandlers);

+ 1 - 1
test/server-test.js ファイルの表示

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