Skip to content

Commit

Permalink
Normalize some arguments
Browse files Browse the repository at this point in the history
Applies to OpenUserJS#72
  • Loading branch information
Martii committed Nov 20, 2017
1 parent a4b05d4 commit 4ce7556
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ function isEqualKeyset(aSlaveKeyset, aMasterKeyset) {
return true;
}

exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
var isLibrary = !!findMeta(aMeta, 'UserLibrary');
var name = null;
var thisName = null;
Expand Down Expand Up @@ -1665,7 +1665,7 @@ exports.webhook = function (aReq, aRes) {

// Update modified scripts
repoManager = RepoManager.getManager(null, aUser, repos);
repoManager.loadScripts(function () {
}, true);
repoManager.loadScripts(true, function () {
});
});
};
8 changes: 4 additions & 4 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
);
}
}
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, onScriptStored);
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
} else {
aCallback('Specified file does not contain the proper metadata blocks.');
}
Expand Down Expand Up @@ -1347,7 +1347,7 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
);
}
}
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, onScriptStored);
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
} else {
aCallback('Specified file does not contain the proper metadata blocks.');
}
Expand Down Expand Up @@ -1463,7 +1463,7 @@ exports.uploadScript = function (aReq, aRes, aNext) {
return;
}

scriptStorage.storeScript(aUser, aMeta, bufferConcat, function (aScript) {
scriptStorage.storeScript(aUser, aMeta, bufferConcat, false, function (aScript) {
if (!aScript) {
aRes.redirect(failUri);
return;
Expand Down Expand Up @@ -1510,7 +1510,7 @@ exports.submitSource = function (aReq, aRes, aNext) {
function storeScript(aMeta, aSource) {

User.findOne({ _id: authedUser._id }, function (aErr, aUser) {
scriptStorage.storeScript(aUser, aMeta, aSource, function (aScript) {
scriptStorage.storeScript(aUser, aMeta, aSource, false, function (aScript) {
var redirectUri = aScript
? ((aScript.isLib ? '/libs/' : '/scripts/') +
encodeURIComponent(helpers.cleanFilename(aScript.author)) +
Expand Down
8 changes: 4 additions & 4 deletions libs/repoManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,21 @@ RepoManager.prototype.fetchRecentRepos = function (aCallback) {
};

// Import scripts on GitHub
RepoManager.prototype.loadScripts = function (aCallback, aUpdate) {
RepoManager.prototype.loadScripts = function (aUpdate, aCallback) {
var scriptStorage = require('../controllers/scriptStorage');
var arrayOfRepos = this.makeRepoArray();
var that = this;

// TODO: remove usage of makeRepoArray since it causes redundant looping
arrayOfRepos.forEach(function (aRepo) {
async.each(aRepo.scripts, function (aScript, aCallback) {
async.each(aRepo.scripts, function (aScript, aInnerCallback) {
var url = '/' + encodeURI(aRepo.user) + '/' + encodeURI(aRepo.repo)
+ '/master' + aScript.path;
fetchRaw('raw.githubusercontent.com', url, function (aBufs) {
scriptStorage.getMeta(aBufs, function (aMeta) {
if (aMeta) {
scriptStorage.storeScript(that.user, aMeta, Buffer.concat(aBufs),
aCallback, aUpdate);
scriptStorage.storeScript(that.user, aMeta, Buffer.concat(aBufs), aUpdate,
aInnerCallback);
}
});
});
Expand Down

0 comments on commit 4ce7556

Please sign in to comment.