Remove last bit of hard-coded format names from app controller

This commit is contained in:
Sandro Santilli 2013-09-05 17:07:11 +02:00
parent 615151528c
commit a0ff7ee10c
2 changed files with 5 additions and 26 deletions

View File

@ -99,8 +99,6 @@ function sanitize_filename(filename) {
// request handlers // request handlers
function handleQuery(req, res) { function handleQuery(req, res) {
//var supportedFormats = ['json', 'geojson', 'topojson', 'csv', 'svg', 'shp', 'kml', 'arraybuffer'];
// extract input // extract input
var body = (req.body) ? req.body : {}; var body = (req.body) ? req.body : {};
var params = _.extend({}, req.query, body); // clone so don't modify req.params or req.body so oauth is not broken var params = _.extend({}, req.query, body); // clone so don't modify req.params or req.body so oauth is not broken
@ -252,7 +250,7 @@ function handleQuery(req, res) {
// configure headers for given format // configure headers for given format
var use_inline = !requestedFormat && !requestedFilename; var use_inline = !requestedFormat && !requestedFilename;
res.header("Content-Disposition", getContentDisposition(format, filename, use_inline)); res.header("Content-Disposition", getContentDisposition(formatter, filename, use_inline));
res.header("Content-Type", formatter.getContentType()); res.header("Content-Type", formatter.getContentType());
// allow cross site post // allow cross site post
@ -321,27 +319,8 @@ function handleCacheStatus(req, res){
} }
// TODO: delegate to formats function getContentDisposition(formatter, filename, inline) {
function getContentDisposition(format, filename, inline) { var ext = formatter.getFileExtension();
var ext = 'json';
if (format === 'geojson'){
ext = 'geojson';
}
else if (format === 'topojson'){
ext = 'topojson';
}
else if (format === 'csv'){
ext = 'csv';
}
else if (format === 'svg'){
ext = 'svg';
}
else if (format === 'shp'){
ext = 'zip';
}
else if (format === 'kml'){
ext = 'kml';
}
var time = new Date().toUTCString(); var time = new Date().toUTCString();
return ( inline ? 'inline' : 'attachment' ) +'; filename=' + filename + '.' + ext + '; modification-date="' + time + '";'; return ( inline ? 'inline' : 'attachment' ) +'; filename=' + filename + '.' + ext + '; modification-date="' + time + '";';
} }

View File

@ -1,5 +1,5 @@
Format classes are required to expose a constructor with no arguments Format classes are required to expose a constructor with no arguments,
and a sendResponse(opts,callback) method. a getFileExtension() and a sendResponse(opts, callback) method.
The ``opts`` parameter contains: The ``opts`` parameter contains: