2015-02-27 00:25:57 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var name = 'node-ff-assets';
|
|
|
|
var downloadTimeout = (1000*10) * 6; // 1min
|
|
|
|
var downloadMaxSize = (1024*1024) * 10; // 10mb
|
|
|
|
|
|
|
|
var template = {
|
|
|
|
downloadStartDelay: null,
|
|
|
|
downloadForce: false,
|
|
|
|
downloadOptions: {
|
|
|
|
timeout: downloadTimeout,
|
|
|
|
maxResponseLength: downloadMaxSize,
|
|
|
|
agent: name+' remote fetcher',
|
|
|
|
},
|
|
|
|
|
|
|
|
linkTargetSingleResult: true,
|
|
|
|
linkTarget: null,
|
|
|
|
linkSources: [],
|
|
|
|
linkMapping: [],
|
|
|
|
|
|
|
|
assetType: null,
|
|
|
|
assetHeader: '\n/* '+name+': begin */\n\n',
|
|
|
|
assetFooter: '\n/* '+name+': end */\n\n',
|
|
|
|
assetSeperator: '\n/* '+name+': next */\n',
|
|
|
|
};
|
|
|
|
|
|
|
|
function checkConfig(config,callback) {
|
|
|
|
if (!config) {
|
|
|
|
callback(new Error('no config'));
|
|
|
|
}
|
|
|
|
if (!config.linkTarget) {
|
|
|
|
callback(new Error('no config.linkTarget'));
|
|
|
|
}
|
|
|
|
if (!config.linkSources) {
|
|
|
|
callback(new Error('no config.linkSources'));
|
|
|
|
}
|
|
|
|
if (!config.linkMapping) {
|
|
|
|
callback(new Error('no config.linkMapping'));
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
function fillDefaults(config,callback) {
|
|
|
|
if (config.downloadOptions === undefined) {
|
|
|
|
config.downloadOptions = template.downloadOptions;
|
|
|
|
}
|
|
|
|
if (config.assetHeader === undefined) {
|
|
|
|
config.assetHeader = template.assetHeader;
|
|
|
|
}
|
|
|
|
if (config.assetFooter === undefined) {
|
|
|
|
config.assetFooter = template.assetFooter;
|
|
|
|
}
|
|
|
|
if (config.assetSeperator === undefined) {
|
|
|
|
config.assetSeperator = template.assetSeperator;
|
|
|
|
}
|
2015-02-27 20:50:19 +00:00
|
|
|
if (config.linkTargetSingleResult === undefined) {
|
|
|
|
config.linkTargetSingleResult = template.linkTargetSingleResult;
|
|
|
|
}
|
|
|
|
if (config.downloadForce === undefined) {
|
|
|
|
config.downloadForce = template.downloadForce;
|
|
|
|
}
|
2015-02-27 00:25:57 +00:00
|
|
|
callback(null,config);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
template: template,
|
|
|
|
checkConfig: checkConfig,
|
|
|
|
fillDefaults: fillDefaults,
|
|
|
|
};
|