Use tiletype for detecting content-type headers.
This commit is contained in:
@@ -7,6 +7,7 @@ var qs = require('querystring');
|
||||
var Buffer = require('buffer').Buffer;
|
||||
var sm = new (require('sphericalmercator'));
|
||||
var sqlite3 = require('sqlite3');
|
||||
var tiletype = require('tiletype');
|
||||
|
||||
function noop(err) {
|
||||
if (err) throw err;
|
||||
@@ -150,12 +151,10 @@ MBTiles.prototype.getTile = function(z, x, y, callback) {
|
||||
} else if (err) {
|
||||
return callback(err);
|
||||
} else {
|
||||
var options = {
|
||||
'Content-Type': MBTiles.utils.getMimeType(row.tile_data),
|
||||
'Last-Modified': new Date(mbtiles._stat.mtime).toUTCString(),
|
||||
'ETag': mbtiles._stat.size + '-' + Number(mbtiles._stat.mtime)
|
||||
};
|
||||
return callback(null, row.tile_data, options);
|
||||
var headers = tiletype.headers(tiletype.type(row.tile_data));
|
||||
headers['Last-Modified'] = new Date(mbtiles._stat.mtime).toUTCString();
|
||||
headers['ETag'] = mbtiles._stat.size + '-' + Number(mbtiles._stat.mtime);
|
||||
return callback(null, row.tile_data, headers);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
15
lib/utils.js
15
lib/utils.js
@@ -20,21 +20,6 @@ utils.table = function(fields) {
|
||||
});
|
||||
};
|
||||
|
||||
utils.getMimeType = function(data) {
|
||||
if (data[0] === 0x89 && data[1] === 0x50 && data[2] === 0x4E &&
|
||||
data[3] === 0x47 && data[4] === 0x0D && data[5] === 0x0A &&
|
||||
data[6] === 0x1A && data[7] === 0x0A) {
|
||||
return 'image/png';
|
||||
} else if (data[0] === 0xFF && data[1] === 0xD8 &&
|
||||
data[data.length - 2] === 0xFF && data[data.length - 1] === 0xD9) {
|
||||
return 'image/jpeg';
|
||||
} else if (data[0] === 0x47 && data[1] === 0x49 && data[2] === 0x46 &&
|
||||
data[3] === 0x38 && (data[4] === 0x39 || data[4] === 0x37) &&
|
||||
data[5] === 0x61) {
|
||||
return 'image/gif';
|
||||
}
|
||||
};
|
||||
|
||||
function Queue(callback, concurrency) {
|
||||
this.callback = callback;
|
||||
this.concurrency = concurrency || 10;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"Konstantin Käfer <kkaefer>"
|
||||
],
|
||||
"dependencies": {
|
||||
"tiletype": "0.0.x",
|
||||
"sqlite3": "~2.2.0",
|
||||
"sphericalmercator": "~1.0.1"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user