Przeglądaj źródła

update file date on hash update (face only)

jomo 10 lat temu
rodzic
commit
939d8f10a4
2 zmienionych plików z 26 dodań i 5 usunięć
  1. 25 4
      modules/cache.js
  2. 1 1
      modules/helpers.js

+ 25 - 4
modules/cache.js

@@ -1,9 +1,10 @@
 var config = require("./config");
 var redis = null;
+var fs = require("fs");
 
 
 function connect_redis() {
-  console.log("connecting to redis");
+  console.log("connecting to redis...");
   if (process.env.REDISCLOUD_URL) {
     var redisURL = require("url").parse(process.env.REDISCLOUD_URL);
     redis = require("redis").createClient(redisURL.port, redisURL.hostname);
@@ -12,7 +13,7 @@ function connect_redis() {
     redis = require("redis").createClient();
   }
   redis.on("ready", function() {
-    console.log("Redis connection established.");
+    console.log("Redis connection established. Flushing all data.");
     redis.flushall();
   });
   redis.on("error", function (err) {
@@ -23,17 +24,37 @@ function connect_redis() {
   });
 }
 
+// sets the date of the face file belonging to +hash+ to now
+function update_file_date(hash) {
+  if (hash) {
+    var path = config.faces_dir + hash + ".png";
+    fs.exists(path, function(exists) {
+      if (exists) {
+        var date = new Date();
+        fs.utimes("path", date, date, function(err){
+          if (err) {
+            console.error(err);
+          }
+        });
+      } else {
+        console.error("Tried to update " + path + " date, but it doesn't exist");
+      }
+    });
+  }
+}
+
 var exp = {};
 
 exp.get_redis = function() {
   return redis;
 };
 
-// sets the timestamp for +uuid+ to now
-exp.update_timestamp = function(uuid) {
+// sets the timestamp for +uuid+ and its face file's date to now
+exp.update_timestamp = function(uuid, hash) {
   console.log(uuid + " cache: updating timestamp");
   var time = new Date().getTime();
   redis.hmset(uuid, "t", time);
+  update_file_date(hash);
 };
 
 // create the key +uuid+, store +hash+ and time

+ 1 - 1
modules/helpers.js

@@ -30,7 +30,7 @@ function store_images(uuid, details, callback) {
         if (details && details.hash == hash) {
           // hash hasn't changed
           console.log(uuid + " hash has not changed");
-          cache.update_timestamp(uuid);
+          cache.update_timestamp(uuid, hash);
           callback(null, hash);
         } else {
           // hash has changed