tileblaster 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/tileblaster.js +20 -29
- package/package.json +4 -4
package/lib/tileblaster.js
CHANGED
|
@@ -11,7 +11,7 @@ var stream = require("stream");
|
|
|
11
11
|
var debug = require("debug")("tileblaster");
|
|
12
12
|
var phin = require("phin");
|
|
13
13
|
var queue = require("quu");
|
|
14
|
-
var
|
|
14
|
+
var walk = require("klaw");
|
|
15
15
|
var dur = require("dur");
|
|
16
16
|
|
|
17
17
|
// optional dependencies; if only
|
|
@@ -198,7 +198,7 @@ tileblaster.prototype.reconfigure = function(config){
|
|
|
198
198
|
// cleanup timer
|
|
199
199
|
self.config.cleanup = (!!self.config.cleanup) ? dur(self.config.cleanup) : false;
|
|
200
200
|
if (!!self.cleaner) clearInterval(self.cleaner);
|
|
201
|
-
if (self.config.cleanup && self.expiration) self.cleaner = setInterval(function(){ self.cleanup(); }, self.config.cleanup).unref();
|
|
201
|
+
if (self.config.cleanup && self.expiration) self.cleaner = setInterval(function(){ self.cleanup(); }, self.config.cleanup).unref(), self.cleanup();
|
|
202
202
|
|
|
203
203
|
};
|
|
204
204
|
|
|
@@ -351,41 +351,32 @@ tileblaster.prototype.cleanup = function(){
|
|
|
351
351
|
|
|
352
352
|
// clean up error cache
|
|
353
353
|
var d = Date.now();
|
|
354
|
-
self.errcache = self.errcache.
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
self.errcache = Object.entries(self.errcache).reduce(function(errcache, [ key, value ]){
|
|
355
|
+
if (value.until < d) errcache[key] = value;
|
|
356
|
+
return errcache;
|
|
357
|
+
},{});
|
|
357
358
|
|
|
358
|
-
//
|
|
359
|
+
// delete queue
|
|
360
|
+
var deletequeue = queue(1000);
|
|
361
|
+
var now = Date.now();
|
|
359
362
|
|
|
360
363
|
// clean up map tiles
|
|
361
364
|
Object.keys(self.maps).filter(function(mapid){
|
|
362
365
|
return (!!self.maps[mapid].expires);
|
|
363
366
|
}).forEach(function(mapid){
|
|
364
367
|
self.queue.push(function(done){
|
|
365
|
-
debug("<cleanup>
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
var d = 0;
|
|
371
|
-
var q = queue(5).done(function(n){
|
|
372
|
-
return debug("<cleanup> [%s] checked %d files, deleted %d", mapid, n, d), done();
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
files.forEach(function(f){
|
|
376
|
-
q.push(function(next){
|
|
377
|
-
fs.stat(f, function(err, stat){
|
|
378
|
-
if (err) return debug("<cleanup> [%s] err: %s", mapid, err), next();
|
|
379
|
-
// debug("<cleanup> [%s] %d <> %d", f, (Date.now() - (stat.birthtimeMs || stat.ctimeMs)), self.maps[mapid].expires);
|
|
380
|
-
if ((Date.now() - (stat.birthtimeMs || stat.ctimeMs)) < self.maps[mapid].expires) return next();
|
|
381
|
-
fs.unlink(f, function(err){
|
|
382
|
-
if (err) return debug("<cleanup> [%s] err: %s", mapid, err), next();
|
|
383
|
-
d++;
|
|
384
|
-
next();
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
});
|
|
368
|
+
debug("<cleanup> start: %s", mapid);
|
|
369
|
+
walk(path.resolve(self.config.tiles, mapid)).on("data", function(f){
|
|
370
|
+
if (f.stats.isFile() && f.stats.mtimeMs+self.maps[mapid].expires < now) deletequeue.push(function(done){
|
|
371
|
+
fs.unlink(f.path, done);
|
|
388
372
|
});
|
|
373
|
+
}).on("error", function(err){
|
|
374
|
+
if (err.code !== "ENOENT") debug("<cleanup> err: %s", err);
|
|
375
|
+
else debug("<cleanup> done: %s", mapid);
|
|
376
|
+
done();
|
|
377
|
+
}).on("end", function(){
|
|
378
|
+
debug("<cleanup> done: %s", mapid);
|
|
379
|
+
done();
|
|
389
380
|
});
|
|
390
381
|
});
|
|
391
382
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tileblaster",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "pretty fast optimizing & compressing tile caching proxy",
|
|
5
5
|
"main": "lib/tileblaster.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"debug": "^4.3.4",
|
|
21
21
|
"dur": "^0.0.3",
|
|
22
|
-
"
|
|
22
|
+
"klaw": "^4.1.0",
|
|
23
23
|
"minimist": "^1.2.7",
|
|
24
24
|
"node-watch": "^0.7.3",
|
|
25
25
|
"nsa": "^0.2",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"quu": "^0.4.3"
|
|
28
28
|
},
|
|
29
29
|
"optionalDependencies": {
|
|
30
|
-
"versatiles": "^0.2.0",
|
|
31
30
|
"jpck": "^1.0.2",
|
|
32
31
|
"node-zopfli": "^2.1.4",
|
|
33
|
-
"pnck": "^1.0.1"
|
|
32
|
+
"pnck": "^1.0.1",
|
|
33
|
+
"versatiles": "^0.2.0"
|
|
34
34
|
}
|
|
35
35
|
}
|