Kaynağa Gözat

Add semantic filenames before uploading to S3.

parisminton 7 yıl önce
ebeveyn
işleme
0d76b2235b
2 değiştirilmiş dosya ile 11 ekleme ve 4 silme
  1. 5 3
      audiogram/index.js
  2. 6 1
      client/index.js

+ 5 - 3
audiogram/index.js Dosyayı Görüntüle

@@ -145,7 +145,9 @@ Audiogram.prototype.combineFrames = function(cb) {
145 145
 Audiogram.prototype.render = function(cb) {
146 146
 
147 147
   var self = this,
148
-      q = queue(1);
148
+      q = queue(1),
149
+      identifier = self.settings.identifier;
150
+ ;
149 151
 
150 152
   this.status("audio-download");
151 153
 
@@ -170,7 +172,7 @@ Audiogram.prototype.render = function(cb) {
170 172
   q.defer(this.combineFrames.bind(this));
171 173
 
172 174
   // Upload video to S3 or move to local storage
173
-  q.defer(transports.uploadVideo, this.videoPath, "video/" + this.id + ".mp4");
175
+  q.defer(transports.uploadVideo, this.videoPath, "video/" + identifier + ".mp4");
174 176
 
175 177
   // Delete working directory
176 178
   q.defer(rimraf, this.dir);
@@ -179,7 +181,7 @@ Audiogram.prototype.render = function(cb) {
179 181
   q.await(function(err){
180 182
 
181 183
     if (!err) {
182
-      self.set("url", transports.getURL(self.id));
184
+      self.set("url", transports.getURL(identifier));
183 185
     }
184 186
 
185 187
     logger.debug(self.profiler.print());

+ 6 - 1
client/index.js Dosyayı Görüntüle

@@ -61,7 +61,11 @@ function submitted() {
61 61
       citation = preview.citation(),
62 62
       label = preview.label(),
63 63
       selection = preview.selection(),
64
-      file = preview.file();
64
+      file = preview.file(),
65
+      identifier;
66
+
67
+  // for easy-to-scan filenames
68
+  identifier = caption.replace(/\s+/g, '_').replace(/\'|\"|\.|\?|\!/g, '').toLowerCase().slice(0, 20);
65 69
 
66 70
   if (!file) {
67 71
     d3.select("#row-audio").classed("error", true);
@@ -94,6 +98,7 @@ function submitted() {
94 98
   formData.append("caption", caption);
95 99
   formData.append("citation", citation);
96 100
   formData.append("label", label);
101
+  formData.append("identifier", identifier);
97 102
 
98 103
   setClass("loading");
99 104
   d3.select("#loading-message").text("Uploading audio...");