Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter sendMeta to accept json extension #719

Merged
merged 1 commit into from
Aug 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ exports.sendScript = function (aReq, aRes, aNext) {

// Send user script metadata block
exports.sendMeta = function (aReq, aRes, aNext) {
var installName = getInstallName(aReq).replace(/\.meta\.js$/, '.user.js');
var installName = getInstallName(aReq).replace(/\.meta\.(?:js|json)$/, '.user.js');

Script.findOne({ installName: caseSensitive(installName) },
function (aErr, aScript) {
Expand All @@ -194,32 +194,38 @@ exports.sendMeta = function (aReq, aRes, aNext) {
return aNext();
}

aRes.set('Content-Type', 'text/javascript; charset=UTF-8');
meta = aScript.meta; // NOTE: Watchpoint

// Disable *express-minify* for this response
aRes._skip = true;
if (/\.json$/.test(aReq.params.scriptname)) {
aRes.set('Content-Type', 'application/json; charset=UTF-8');

meta = aScript.meta; // NOTE: Watchpoint
aRes.end(JSON.stringify(meta, null, ''));
} else {
aRes.set('Content-Type', 'text/javascript; charset=UTF-8');

// Disable *express-minify* for this response
aRes._skip = true;

Object.keys(meta).reverse().forEach(function (aBlock) {
aRes.write('// ==' + aBlock + '==\n');
Object.keys(meta).reverse().forEach(function (aBlock) {
aRes.write('// ==' + aBlock + '==\n');

Object.keys(meta[aBlock]).reverse().forEach(function (aKey) {
Object.keys(meta[aBlock][aKey]).forEach(function (aIndex) {
var header = meta[aBlock][aKey][aIndex];
var key = null;
var value = null;
Object.keys(meta[aBlock]).reverse().forEach(function (aKey) {
Object.keys(meta[aBlock][aKey]).forEach(function (aIndex) {
var header = meta[aBlock][aKey][aIndex];
var key = null;
var value = null;

key = (header ? header.key : null) || aKey;
value = (header ? header.value : null);
key = (header ? header.key : null) || aKey;
value = (header ? header.value : null);

aRes.write('// @' + key + (value ? whitespace + value : '') + '\n');
aRes.write('// @' + key + (value ? whitespace + value : '') + '\n');
});
});
});

aRes.write('// ==/' + aBlock + '==\n\n');
});
aRes.end();
aRes.write('// ==/' + aBlock + '==\n\n');
});
aRes.end();
}
});
};

Expand Down