@@ -6,18 +6,33 @@ var isDev = require('../libs/debug').isDev;
66var isDbg = require ( '../libs/debug' ) . isDbg ;
77
88//
9+
10+ //--- Dependency inclusions
911var fs = require ( 'fs' ) ;
1012var PEG = require ( 'pegjs' ) ;
1113var AWS = require ( 'aws-sdk' ) ;
1214
15+ //--- Model inclusions
1316var Script = require ( '../models/script' ) . Script ;
1417var User = require ( '../models/user' ) . User ;
18+
19+ //--- Controller inclusions
20+
21+ //--- Library inclusions
22+ // var scriptStorageLib = require('../libs/scriptStorage');
23+
1524var RepoManager = require ( '../libs/repoManager' ) ;
1625
1726var cleanFilename = require ( '../libs/helpers' ) . cleanFilename ;
1827var findDeadorAlive = require ( '../libs/remove' ) . findDeadorAlive ;
28+
29+ //--- Configuration inclusions
1930var userRoles = require ( '../models/userRoles.json' ) ;
2031
32+ //---
33+
34+ // Load in the pegjs configuration files synchronously to detect immediate change errors.
35+ // NOTE: These aren't JSON so not included in configuration inclusions but nearby
2136var parsers = ( function ( ) {
2237 return {
2338 UserScript : PEG . buildParser ( fs . readFileSync ( './public/pegjs/blockUserScript.pegjs' , 'utf8' ) ,
@@ -61,13 +76,14 @@ function caseInsensitive(aInstallName) {
6176exports . caseInsensitive = caseInsensitive ;
6277
6378function caseSensitive ( aInstallName , aMoreThanInstallName ) {
64-
79+ //
6580 var rMatchExpression = aMoreThanInstallName ? / ^ ( .* ) \/ ( .* ) \/ ( .* ) \/ ( .* ) $ / : / ^ ( .* ) \/ ( .* ) $ / ;
81+ var matches = aInstallName . match ( rMatchExpression ) ;
82+
6683 var char = null ;
6784 var username = '' ;
6885 var rExpression = null ;
6986
70- var matches = aInstallName . match ( rMatchExpression ) ;
7187 if ( matches ) {
7288 if ( aMoreThanInstallName ) {
7389
@@ -127,7 +143,8 @@ exports.getSource = function (aReq, aCallback) {
127143 // WARNING: Partial error handling at this stage
128144
129145 if ( ! aScript ) {
130- return aCallback ( null ) ;
146+ aCallback ( null ) ;
147+ return ;
131148 }
132149
133150 s3Object = s3 . getObject ( { Bucket : bucketName , Key : installName } ) . createReadStream ( ) .
@@ -136,7 +153,8 @@ exports.getSource = function (aReq, aCallback) {
136153 console . error ( 'S3 Key Not Found ' + installName ) ;
137154 }
138155
139- return aCallback ( null ) ;
156+ aCallback ( null ) ;
157+ return ;
140158 } ) ;
141159
142160 // Get the script
@@ -148,13 +166,15 @@ exports.sendScript = function (aReq, aRes, aNext) {
148166 var accept = aReq . headers . accept ;
149167
150168 if ( 0 !== aReq . url . indexOf ( '/libs/' ) && accept === 'text/x-userscript-meta' ) {
151- return exports . sendMeta ( aReq , aRes , aNext ) ;
169+ exports . sendMeta ( aReq , aRes , aNext ) ;
170+ return ;
152171 }
153172
154173 exports . getSource ( aReq , function ( aScript , aStream ) {
155174
156175 if ( ! aScript ) {
157- return aNext ( ) ;
176+ aNext ( ) ;
177+ return ;
158178 }
159179
160180 // Send the script
@@ -192,7 +212,8 @@ exports.sendMeta = function (aReq, aRes, aNext) {
192212 var whitespace = '\u0020\u0020\u0020\u0020' ;
193213
194214 if ( ! aScript ) {
195- return aNext ( ) ;
215+ aNext ( ) ;
216+ return ;
196217 }
197218
198219 meta = aScript . meta ; // NOTE: Watchpoint
@@ -371,7 +392,8 @@ exports.getMeta = function (aBufs, aCallback) {
371392 blocks [ parser ] = parseMeta ( parsers [ parser ] , blocksContent [ parser ] ) ;
372393 }
373394 }
374- return aCallback ( blocks ) ;
395+ aCallback ( blocks ) ;
396+ return ;
375397 }
376398 }
377399
@@ -397,15 +419,17 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
397419
398420
399421 if ( ! aMeta || process . env . READ_ONLY_SCRIPT_STORAGE === 'true' ) {
400- return aCallback ( null ) ;
422+ aCallback ( null ) ;
423+ return ;
401424 }
402425
403426 if ( ! isLibrary ) {
404427 name = findMeta ( aMeta , 'UserScript.name' ) ;
405428
406429 // Can't install a script without a @name (maybe replace with random value)
407430 if ( ! name ) {
408- return aCallback ( null ) ;
431+ aCallback ( null ) ;
432+ return ;
409433 }
410434
411435 name . forEach ( function ( aElement , aIndex , aArray ) {
@@ -417,7 +441,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
417441
418442 // Can't install a script without a cleaned @name (maybe replace with random value)
419443 if ( ! scriptName ) {
420- return aCallback ( null ) ;
444+ aCallback ( null ) ;
445+ return ;
421446 }
422447
423448 author = findMeta ( aMeta , 'OpenUserJS.author.0.value' ) ;
@@ -450,7 +475,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
450475 } else {
451476 scriptName = cleanFilename ( aMeta . replace ( / ^ \s + | \s + $ / g, '' ) , '' ) ;
452477 if ( ! scriptName ) {
453- return aCallback ( null ) ;
478+ aCallback ( null ) ;
479+ return ;
454480 }
455481
456482 installName += scriptName + '.js' ;
@@ -462,7 +488,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
462488 var script = null ;
463489
464490 if ( aRemoved || ( ! aScript && ( aUpdate || collaboration ) ) ) {
465- return aCallback ( null ) ;
491+ aCallback ( null ) ;
492+ return ;
466493 } else if ( ! aScript ) {
467494 // New script
468495 aScript = new Script ( {
@@ -496,7 +523,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
496523 JSON . stringify ( findMeta ( script . meta , 'OpenUserJS.collaborator.value' ) ) !==
497524 JSON . stringify ( collaborators ) ) ) {
498525
499- return aCallback ( null ) ;
526+ aCallback ( null ) ;
527+ return ;
500528 }
501529 aScript . meta = aMeta ;
502530 aScript . uses = libraries ;
@@ -523,7 +551,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
523551 console . error ( aUser . name , '-' , installName ) ;
524552 console . error ( JSON . stringify ( aErr ) ) ;
525553 console . error ( JSON . stringify ( aScript . toObject ( ) ) ) ;
526- return aCallback ( null ) ;
554+ aCallback ( null ) ;
555+ return ;
527556 }
528557
529558 if ( aUser . role === userRoles . length - 1 ) {
0 commit comments