-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add basic support for (site/project) key prefixing #226
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b217490
Add basic support for key prefixing
5134914
Readd `@author`... need this for testing
b6fd452
Swap out `@collaborator` and `@author` for prefixed keys
550993d
Remove some duplicated `meta.oujs` checks... the remaining one should…
42f9c30
Change add/scripts page to reflect these changes.
f7ff675
Missed an instruction on the page to use prefix
d6f4302
I could have swore that this was committed a few days ago... No idea …
b4bde68
Missed identifier change
c9e5e0e
Merge branch 'master' into allowPrefixedMetadataKeys
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,20 +131,39 @@ exports.sendMeta = function (req, res, next) { | |
Script.findOne({ installName: caseInsensitive(installName) }, | ||
function (err, script) { | ||
var meta = null; | ||
var name = null; | ||
var data = null; | ||
var prefix = null; | ||
var key = null; | ||
var whitespace = ' '; | ||
|
||
if (!script) { return next(); } | ||
|
||
res.set('Content-Type', 'text/javascript; charset=UTF-8'); | ||
meta = script.meta; | ||
|
||
res.write('// ==UserScript==\n'); | ||
Object.keys(meta).reverse().forEach(function (key) { | ||
if (meta[key] instanceof Array) { | ||
meta[key].forEach(function (value) { | ||
res.write('// @' + key + ' ' + value + '\n'); | ||
Object.keys(meta).reverse().forEach(function (name) { | ||
if (meta[name] instanceof Array) { | ||
meta[name].forEach(function (value) { | ||
res.write('// @' + name + (value ? whitespace + value : '') + '\n'); | ||
}); | ||
} else if (meta[name] instanceof Object) { | ||
prefix = name; | ||
for (key in meta[name]) { | ||
data = meta[prefix][key]; | ||
if (data instanceof Array) { | ||
meta[prefix][key].forEach(function (value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixered. Thanks again. |
||
res.write('// @' + prefix + ':' + key + (value ? whitespace + value : '') + '\n'); | ||
}); | ||
} | ||
else { | ||
res.write('// @' + prefix + ':' + key + (data ? whitespace + data : '') + '\n'); | ||
} | ||
} | ||
} else { | ||
res.write('// @' + key + ' ' + meta[key] + '\n'); | ||
data = meta[name]; | ||
res.write('// @' + name + (data ? whitespace + data : '') + '\n'); | ||
} | ||
}); | ||
res.end('// ==/UserScript==\n'); | ||
|
@@ -157,18 +176,22 @@ function parseMeta(aString) { | |
var re = /\/\/ @(\S+)(?:\s+(.*))?/; | ||
var headers = {}; | ||
var name = null; | ||
var prefix = null; | ||
var key = null; | ||
var value = null; | ||
var line = null; | ||
var lineMatches = null; | ||
var lines = {}; | ||
var unique = { | ||
var uniques = { | ||
'name': true, | ||
'namespace': true, | ||
'description': true, | ||
'version': true, | ||
'author': true | ||
'oujs:author': true | ||
}; | ||
var unique = null; | ||
var one = null; | ||
var matches = null; | ||
|
||
lines = aString.split(/[\r\n]+/).filter(function (e, i, a) { | ||
return (e.match(re)); | ||
|
@@ -187,16 +210,41 @@ function parseMeta(aString) { | |
name = 'homepageURL'; | ||
break; | ||
} | ||
if (!headers[name] || unique[name]) { | ||
headers[name] = value || ''; | ||
} else { | ||
if (!(headers[name] instanceof Array)) { | ||
headers[name] = [headers[name]]; | ||
name = name.split(/:/).reverse(); | ||
key = name[0]; | ||
prefix = name[1]; | ||
if (key) { | ||
if (prefix) { | ||
if (!headers[prefix]) { | ||
headers[prefix] = {}; | ||
} | ||
header = headers[prefix]; | ||
unique = {}; | ||
for (one in uniques) { | ||
matches = one.match(/(.*):(.*)$/); | ||
if (uniques[one] && matches && matches[1] === prefix) { | ||
unique[matches[2]] = true; | ||
} | ||
} | ||
} else { | ||
header = headers; | ||
unique = {}; | ||
for (one in uniques) { | ||
if (uniques[one] && !/:/.test(one)) { | ||
unique[one] = true; | ||
} | ||
} | ||
} | ||
if (!header[key] || unique[key]) { | ||
header[key] = value || ''; | ||
} else { | ||
if (!(header[key] instanceof Array)) { | ||
header[key] = [header[key]]; | ||
} | ||
header[key].push(value || ''); | ||
} | ||
headers[name].push(value || ''); | ||
} | ||
} | ||
|
||
return headers; | ||
} | ||
exports.parseMeta = parseMeta; | ||
|
@@ -242,14 +290,14 @@ exports.storeScript = function (user, meta, buf, callback, update) { | |
// Can't install a script without a @name (maybe replace with random value) | ||
if (!scriptName) { return callback(null); } | ||
|
||
if (!isLibrary && meta.author | ||
&& meta.author != user.name && meta.collaborator) { | ||
collaborators = meta.collaborator; | ||
if (!isLibrary && meta.oujs && meta.oujs.author | ||
&& meta.oujs.author != user.name && meta.oujs.collaborator) { | ||
collaborators = meta.oujs.collaborator; | ||
if ((typeof collaborators === 'string' | ||
&& collaborators === user.name) | ||
|| (collaborators instanceof Array | ||
&& collaborators.indexOf(user.name) > -1)) { | ||
installName = meta.author + '/'; | ||
installName = meta.oujs.author + '/'; | ||
} else { | ||
collaborators = null; | ||
} | ||
|
@@ -300,9 +348,9 @@ exports.storeScript = function (user, meta, buf, callback, update) { | |
}); | ||
} else { | ||
if (!script.isLib) { | ||
if (collaborators && (script.meta.author != meta.author | ||
|| JSON.stringify(script.meta.collaborator) != | ||
JSON.stringify(meta.collaborator))) { | ||
if (collaborators && (script.meta.oujs && script.meta.oujs.author != meta.oujs.author | ||
|| (script.meta.oujs && JSON.stringify(script.meta.oujs.collaborator) != | ||
JSON.stringify(meta.oujs.collaborator)))) { | ||
return callback(null); | ||
} | ||
script.meta = meta; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a tab or multiple spaces? Maybe a comment would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it was a tab I would use
'\t'
... but it's a good point on whether we should be using this or just keep the spaces... I did see something a few months back about something likestring(char, count)
type method but I lost the link to it. Might have been a different language too. heh... and I'm just about done searching for the evening. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A-ha... finally refound the bugger in ES6 draft ... applies to #226 and changed in #267 to Unicode notation of space manually repeating string... time to see if V8 currently supports this in node.js... nope... that's too bad.
See also: