Skip to content

Commit

Permalink
Standardize on "base" for identifier structure
Browse files Browse the repository at this point in the history
* This is a mix between WordPress base/slug nomenclature and well established file name with extension concepts where as the "file name" is considered the base name since we are using multiple paths for this identifier e.g. username and scriptname which makes up installName

Applies to OpenUserJS#819
  • Loading branch information
Martii committed Nov 17, 2015
1 parent 4d23b72 commit da435f7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions controllers/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports.flag = function (aReq, aRes, aNext) {
var type = aReq.params[0];
var isLib = null;

var installName = null;
var installNameBase = null;
var username = null;

var authedUser = aReq.session.user;
Expand Down Expand Up @@ -88,10 +88,10 @@ exports.flag = function (aReq, aRes, aNext) {
aReq.params.username = aReq.params[2];
aReq.params.scriptname = aReq.params[3]

installName = scriptStorage.getScriptBaseName(aReq);
installNameBase = scriptStorage.getInstallNameBase(aReq);

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(isLib ? '.js' : '.user.js'))
},
function (aErr, aScript) {
Expand All @@ -103,7 +103,7 @@ exports.flag = function (aReq, aRes, aNext) {
}

fn(Script, aScript, authedUser, reason, function (aFlagged) {
aRes.redirect((isLib ? '/libs/' : '/scripts/') + scriptStorage.getScriptBaseName(
aRes.redirect((isLib ? '/libs/' : '/scripts/') + scriptStorage.getInstallNameBase(
aReq, { encoding: 'uri' }));
});

Expand Down
30 changes: 15 additions & 15 deletions controllers/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ var orderDir = require('../libs/templateHelpers').orderDir;
// List script issues
exports.list = function (aReq, aRes, aNext) {
//
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);
var type = aReq.params.type;

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(type === 'libs' ? '.js' : '.user.js'))
}, function (aErr, aScript) {
function preRender() {
Expand Down Expand Up @@ -119,7 +119,7 @@ exports.list = function (aReq, aRes, aNext) {

// Category
category = {};
category.slug = type + '/' + installName + '/issues';
category.slug = type + '/' + installNameBase + '/issues';
category.name = 'Issues';
category.description = '';
category = modelParser.parseCategory(category);
Expand Down Expand Up @@ -188,11 +188,11 @@ exports.list = function (aReq, aRes, aNext) {
// Show the discussion on an issue
exports.view = function (aReq, aRes, aNext) {
//
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);
var type = aReq.params.type;

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(type === 'libs' ? '.js' : '.user.js'))
}, function (aErr, aScript) {
//
Expand All @@ -219,7 +219,7 @@ exports.view = function (aReq, aRes, aNext) {

// Category
category = {};
category.slug = type + '/' + installName + '/issues';
category.slug = type + '/' + installNameBase + '/issues';
category.name = 'Issues';
category.description = '';
category = modelParser.parseCategory(category);
Expand Down Expand Up @@ -311,11 +311,11 @@ exports.view = function (aReq, aRes, aNext) {
// Open a new issue
exports.open = function (aReq, aRes, aNext) {
//
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);
var type = aReq.params.type;

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(type === 'libs' ? '.js' : '.user.js'))
}, function (aErr, aScript) {
function preRender() {
Expand Down Expand Up @@ -358,7 +358,7 @@ exports.open = function (aReq, aRes, aNext) {

// Category
category = {};
category.slug = type + '/' + installName + '/issues';
category.slug = type + '/' + installNameBase + '/issues';
category.name = 'Issues';
category.description = '';
category = modelParser.parseCategory(category);
Expand Down Expand Up @@ -403,16 +403,16 @@ exports.open = function (aReq, aRes, aNext) {
// Post route to add a new comment to a discussion on an issue
exports.comment = function (aReq, aRes, aNext) {
//
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);
var type = aReq.params.type;

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(type === 'libs' ? '.js' : '.user.js'))
}, function (aErr, aScript) {
//
var content = aReq.body['comment-content'];
var category = type + '/' + installName + '/issues';
var category = type + '/' + installNameBase + '/issues';
var topic = aReq.params.topic;

if (aErr || !aScript) {
Expand Down Expand Up @@ -448,14 +448,14 @@ exports.comment = function (aReq, aRes, aNext) {

// Open or close an issue you are allowed
exports.changeStatus = function (aReq, aRes, aNext) {
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);
var type = aReq.params.type;

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(type === 'libs' ? '.js' : '.user.js'))
}, function (aErr, aScript) {
var category = type + '/' + installName + '/issues';
var category = type + '/' + installNameBase + '/issues';
var topic = aReq.params.topic;
var action = aReq.params.action;
var changed = false;
Expand Down
14 changes: 7 additions & 7 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ var setupScriptSidePanel = function (aOptions) {
// View a detailed description of a script
// This is the most intensive page to render on the site
exports.view = function (aReq, aRes, aNext) {
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);
var isLib = aReq.params.isLib;

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(isLib ? '.js' : '.user.js'))
}, function (aErr, aScriptData) {
function preRender() {
Expand Down Expand Up @@ -377,7 +377,7 @@ exports.view = function (aReq, aRes, aNext) {
options.script = script = modelParser.parseScript(aScriptData);
options.isOwner = authedUser && authedUser._id == script._authorId;
modelParser.renderScript(script);
script.installNameSlug = installName;
script.installNameSlug = installNameBase;
script.scriptPermalinkInstallPageUrl = 'https://' + aReq.get('host') +
script.scriptInstallPageUrl;

Expand All @@ -404,12 +404,12 @@ exports.view = function (aReq, aRes, aNext) {
// route to edit a script
exports.edit = function (aReq, aRes, aNext) {
//
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);
var isLib = aReq.params.isLib;

//---
Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(isLib ? '.js' : '.user.js'))
}, function (aErr, aScriptData) {
function preRender() {
Expand Down Expand Up @@ -498,7 +498,7 @@ exports.vote = function (aReq, aRes, aNext) {
var unvote = false;

var isLib = aReq.params.isLib;
var installName = scriptStorage.getScriptBaseName(aReq);
var installNameBase = scriptStorage.getInstallNameBase(aReq);

// ---
if (url.length > 5) {
Expand All @@ -520,7 +520,7 @@ exports.vote = function (aReq, aRes, aNext) {
}

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(isLib ? '.js' : '.user.js'))
}, function (aErr, aScript) {
//
Expand Down
16 changes: 8 additions & 8 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (isPro) {
});
}

function getScriptBaseName(aReq, aOptions) {
function getInstallNameBase(aReq, aOptions) {
//
var base = null;

Expand Down Expand Up @@ -94,7 +94,7 @@ function getScriptBaseName(aReq, aOptions) {

return base;
}
exports.getScriptBaseName = getScriptBaseName;
exports.getInstallNameBase = getInstallNameBase;

function caseInsensitive(aInstallName) {
return new RegExp('^' + aInstallName.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1") + '$', 'i');
Expand Down Expand Up @@ -160,11 +160,11 @@ function caseSensitive(aInstallName, aMoreThanInstallName) {
exports.caseSensitive = caseSensitive;

exports.getSource = function (aReq, aCallback) {
var installName = getScriptBaseName(aReq, { hasExtension: true });
var installNameBase = getInstallNameBase(aReq, { hasExtension: true });
var isLib = aReq.params.isLib;

Script.findOne({
installName: caseSensitive(installName +
installName: caseSensitive(installNameBase +
(isLib ? '.js' : '.user.js'))
}, function (aErr, aScript) {
var s3Object = null;
Expand All @@ -178,10 +178,10 @@ exports.getSource = function (aReq, aCallback) {
return;
}

s3Object = s3.getObject({ Bucket: bucketName, Key: installName + (isLib ? '.js' : '.user.js') }).createReadStream().
s3Object = s3.getObject({ Bucket: bucketName, Key: installNameBase + (isLib ? '.js' : '.user.js') }).createReadStream().
on('error', function () {
if (isPro) {
console.error('S3 Key Not Found ' + installName);
console.error('S3 Key Not Found ' + installNameBase + (isLib ? '.js' : '.user.js'));
}

aCallback(null);
Expand Down Expand Up @@ -240,9 +240,9 @@ exports.sendScript = function (aReq, aRes, aNext) {

// Send user script metadata block
exports.sendMeta = function (aReq, aRes, aNext) {
var installName = getScriptBaseName(aReq, { hasExtension: true });
var installNameBase = getInstallNameBase(aReq, { hasExtension: true });

Script.findOne({ installName: caseSensitive(installName + '.user.js') },
Script.findOne({ installName: caseSensitive(installNameBase + '.user.js') },
function (aErr, aScript) {
var meta = null;
var whitespace = '\u0020\u0020\u0020\u0020';
Expand Down
10 changes: 5 additions & 5 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ exports.editScript = function (aReq, aRes, aNext) {
var options = {};
var authedUser = aReq.session.user;
var isNew = aReq.params.isNew;
var installName = null;
var installNameBase = null;
var isLib = aReq.params.isLib;
var tasks = [];

Expand All @@ -1619,10 +1619,10 @@ exports.editScript = function (aReq, aRes, aNext) {
});

if (!isNew) {
installName = scriptStorage.getScriptBaseName(aReq);
installNameBase = scriptStorage.getInstallNameBase(aReq);

Script.findOne({
installName: scriptStorage.caseSensitive(installName +
installName: scriptStorage.caseSensitive(installNameBase +
(isLib ? '.js' : '.user.js'))
}, function (aErr, aScriptData) {
//
Expand All @@ -1639,11 +1639,11 @@ exports.editScript = function (aReq, aRes, aNext) {
options.script = script = modelParser.parseScript(aScriptData);
options.isOwner = authedUser && authedUser._id == script._authorId;
modelParser.renderScript(script);
script.installNameSlug = installName;
script.installNameSlug = installNameBase;
script.scriptPermalinkInstallPageUrl = 'https://' + aReq.get('host') +
script.scriptInstallPageUrl;
script.scriptRawPageUrl = '/src/' + (isLib ? 'libs' : 'scripts') + '/'
+ scriptStorage.getScriptBaseName(aReq, { encoding: 'uri' }) +
+ scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }) +
(isLib ? '.js#' : '.user.js#');

// Page metadata
Expand Down

0 comments on commit da435f7

Please sign in to comment.