Kaynağa Gözat

Add timestamp to front of semantic filename.

parisminton 7 yıl önce
ebeveyn
işleme
5c57b9e04d
2 değiştirilmiş dosya ile 29 ekleme ve 9 silme
  1. 28 7
      client/index.js
  2. 1 2
      client/video.js

+ 28 - 7
client/index.js Dosyayı Görüntüle

@@ -2,7 +2,31 @@ var d3 = require("d3"),
2 2
     $ = require("jquery"),
3 3
     preview = require("./preview.js"),
4 4
     video = require("./video.js"),
5
-    audio = require("./audio.js");
5
+    audio = require("./audio.js"),
6
+    timestamp,
7
+    identifier;
8
+
9
+
10
+function addZero (digit) {
11
+  if (digit.toString().length === 1) {
12
+    return '0' + digit.toString();
13
+  }
14
+  else {
15
+    return digit.toString();
16
+  }
17
+}
18
+
19
+function timestamp () {
20
+  var d = new Date();
21
+
22
+  return addZero(d.getMonth() + 1)
23
+  + addZero(d.getDate())
24
+  + d.getFullYear().toString().slice(2,4) + '_'
25
+  + addZero(d.getHours())
26
+  + addZero(d.getMinutes())
27
+  + addZero(d.getSeconds()) + '_';
28
+}
29
+
6 30
 
7 31
 d3.json("/settings/labels.json", function(err, labels){
8 32
 
@@ -61,11 +85,10 @@ function submitted() {
61 85
       citation = preview.citation(),
62 86
       label = preview.label(),
63 87
       selection = preview.selection(),
64
-      file = preview.file(),
65
-      identifier;
88
+      file = preview.file();
66 89
 
67
-  // for easy-to-scan filenames
68
-  identifier = caption.replace(/\s+/g, '_').replace(/\'|\"|\.|\?|\!/g, '').toLowerCase().slice(0, 20);
90
+  // combine timestamp and caption for easy-to-scan filenames
91
+  identifier = timestamp() + preview.caption().replace(/\s+/g, '_').replace(/\'|\"|\.|\?|\!/g, '').toLowerCase().slice(0, 20);
69 92
 
70 93
   if (!file) {
71 94
     d3.select("#row-audio").classed("error", true);
@@ -121,8 +144,6 @@ function submitted() {
121 144
 }
122 145
 
123 146
 function poll(id) {
124
-  var identifier = preview.caption().replace(/\s+/g, '_').replace(/\'|\"|\.|\?|\!/g, '').toLowerCase().slice(0, 20);
125
-
126 147
   setTimeout(function(){
127 148
     $.ajax({
128 149
       url: "/status/" + id + "/",

+ 1 - 2
client/video.js Dosyayı Görüntüle

@@ -15,8 +15,7 @@ function kill() {
15 15
 
16 16
 function update(url, name) {
17 17
 
18
-  var timestamp = d3.timeFormat("%m%d%y_AG_")(new Date).toLowerCase(),
19
-      filename = timestamp + (name || "Audiogram") + ".mp4";
18
+  var filename = (name || "Audiogram") + ".mp4";
20 19
 
21 20
   d3.select("#download")
22 21
     .attr("download", filename)