Skip to content

Commit fad4d2b

Browse files
committed
Separate add-on id parse function
1 parent 3418f18 commit fad4d2b

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎src/server/handlers/addons.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ exports.setup = function (App) {
6767
htmlVars.request_result = (ok ? 'ok-msg' : (error ? 'error-msg' : ''));
6868
htmlVars.request_msg = (ok ? ok : (error || ""));
6969

70-
context.endWithWebPage(listTemplate.make(htmlVars), {title: "Add-ons - Showdown ChatBot"});
70+
context.endWithWebPage(listTemplate.make(htmlVars), { title: "Add-ons - Showdown ChatBot" });
7171
});
7272

7373
function newAddonHandler(context, parts) {
7474
let ok = null, error = null;
7575

7676
if (context.post.add) {
77-
let addon = Text.toCmdid(context.post.addon);
77+
let addon = Text.toAddOnId(context.post.addon);
7878
let file = App.addonsDir + '/' + addon + ".js";
7979
let content = (context.post.content || "").trim();
8080
try {
@@ -94,7 +94,7 @@ exports.setup = function (App) {
9494
error = "Failed to install the add-on";
9595
} else {
9696
App.logServerAction(context.user.id, 'Add-on installed: ' + file);
97-
context.response.writeHead(302, {'Location': '/addons/'});
97+
context.response.writeHead(302, { 'Location': '/addons/' });
9898
context.response.end();
9999
return;
100100
}
@@ -106,7 +106,7 @@ exports.setup = function (App) {
106106
htmlVars.request_result = (ok ? 'ok-msg' : (error ? 'error-msg' : ''));
107107
htmlVars.request_msg = (ok ? ok : (error || ""));
108108

109-
context.endWithWebPage(addingTemplate.make(htmlVars), {title: "New Add-on - Showdown ChatBot"});
109+
context.endWithWebPage(addingTemplate.make(htmlVars), { title: "New Add-on - Showdown ChatBot" });
110110
}
111111

112112
function editAddonHandler(context, parts) {
@@ -157,6 +157,6 @@ exports.setup = function (App) {
157157
htmlVars.request_result = (ok ? 'ok-msg' : (error ? 'error-msg' : ''));
158158
htmlVars.request_msg = (ok ? ok : (error || ""));
159159

160-
context.endWithWebPage(editTemplate.make(htmlVars), {title: "Add-ons - Showdown ChatBot"});
160+
context.endWithWebPage(editTemplate.make(htmlVars), { title: "Add-ons - Showdown ChatBot" });
161161
}
162162
};

‎src/tools/text.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ exports.toCmdid = exports.toCmdId = function (str) {
3434
return ('' + str).replace(/[^_a-zA-Z0-9-]+/g, '').toLowerCase();
3535
};
3636

37+
/**
38+
* Transforms string to add-on ID
39+
* @param {String} str
40+
* @returns {String} add-on id
41+
*/
42+
exports.toAddonid = exports.toAddOnId = function (str) {
43+
if (!str) return '';
44+
return ('' + str).replace(/[^_a-zA-Z0-9-]+/g, '').toLowerCase();
45+
};
46+
3747
/**
3848
* Transforms string to Command Token ID
3949
* @param {String} str

0 commit comments

Comments
 (0)