diff --git a/app/components/client/devprogram-scripts.js b/app/components/client/devprogram-scripts.js index 3f5afc4..0dc1f05 100644 --- a/app/components/client/devprogram-scripts.js +++ b/app/components/client/devprogram-scripts.js @@ -56,9 +56,10 @@ function syncWithApi(data) { // eslint-disable-line no-unused-vars const address = data.address; const code = data.code; - if (code === null) + if (code === null) { document.querySelector("developer-program").innerHTML = "
There was an issue with accessing GitHub's API. Please try again later.
"; + } fetch(`https://api.lbry.com/reward/new?github_token=${code}&reward_type=github_developer&wallet_address=${address}`) .then(response => response.json()) diff --git a/app/components/client/playground-scripts.js b/app/components/client/playground-scripts.js index 0cab01f..3ff07e9 100644 --- a/app/components/client/playground-scripts.js +++ b/app/components/client/playground-scripts.js @@ -249,11 +249,11 @@ curl --header "Content-Type: application/json" } const handleExamples = debounce(event => { - let exampleNumber; + const exampleNumber = parseInt(document.querySelector(".playground-navigation__example.active").dataset.example || 0); const data = event.dataset; - if (!parseInt(document.querySelector(".playground-navigation__example.active").dataset.example)) return; - exampleNumber = parseInt(document.querySelector(".playground-navigation__example.active").dataset.example); + if (!exampleNumber || exampleNumber === 0) + return; switch(data.action) { case "choose claim": @@ -398,9 +398,9 @@ function updateCanvas(imageSource) { if (imageSource) { ctx.drawImage(imageSource, 0, 0, canvasWidth, canvasHeight); img.src = imageSource.src; - } else { + } else ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight); - } + positionCanvasText(ctx, canvasHeight, canvasWidth); } diff --git a/app/components/head.js b/app/components/head.js index 463a025..773f2e4 100644 --- a/app/components/head.js +++ b/app/components/head.js @@ -68,11 +68,3 @@ export default (state, emit) => { `; }; - - - -// H E L P E R - -String.prototype.capitalize = function() { - return this.charAt(0).toUpperCase() + this.slice(1); -}; diff --git a/app/helpers/fetch-metadata.js b/app/helpers/fetch-metadata.js index a6fcced..044403d 100644 --- a/app/helpers/fetch-metadata.js +++ b/app/helpers/fetch-metadata.js @@ -55,10 +55,10 @@ export default async(data, socket) => { let dataDetails = ""; let explorerNotice = ""; - if (data.example === 1 && !data.claim || !data.method) return; + if (data.example === 1 && (!data.claim || !data.method)) return; if (data.example === 2 && !data.data) return; if (data.example === 2) dataDetails = data.data; // file upload - if (data.example === 3 && !data.claim || !data.method) return; + if (data.example === 3 && (!data.claim || !data.method)) return; const claimAddress = data.claim; const resolveMethod = data.method; @@ -155,9 +155,7 @@ export default async(data, socket) => { message: "show result", selector: `#example${data.example}-result` }); - } - - catch(memePublishError) { + } catch(memePublishError) { send(socket, { details: "Meme publish failed", message: "notification", @@ -174,9 +172,7 @@ export default async(data, socket) => { return; } - } - - catch(imageUploadError) { + } catch(imageUploadError) { send(socket, { details: "Image upload failed", message: "notification", @@ -259,9 +255,7 @@ export default async(data, socket) => { } return response.body.result[Object.keys(response.body.result)[0]].claim; - } - - catch(error) { + } catch(error) { messageSlack({ message: "```" + error + "```", pretext: "_Someone is going through the Playground and the daemon is not running_", diff --git a/app/helpers/github.js b/app/helpers/github.js index 51e0be8..29d6155 100644 --- a/app/helpers/github.js +++ b/app/helpers/github.js @@ -16,15 +16,15 @@ import relativeDate from "~module/relative-date"; let octokit; -String.prototype.escape = function() { - const tagsToReplace = { - "&": "&", - "<": "<", - ">": ">" - }; +// String.prototype.escape = function() { +// const tagsToReplace = { +// "&": "&", +// "<": "<", +// ">": ">" +// }; - return this.replace(/[&<>]/g, tag => tagsToReplace[tag] || tag); -}; +// return this.replace(/[&<>]/g, tag => tagsToReplace[tag] || tag); +// }; // R E D I S @@ -142,7 +142,7 @@ function generateEvent(event) { rel="noopener noreferrer" target="_blank" title="View this comment on GitHub" - >${event.payload.issue.title.escape()} in + >${escapeSpecialCharacters(event.payload.issue.title)} in `; } else { return ` @@ -153,7 +153,7 @@ function generateEvent(event) { rel="noopener noreferrer" target="_blank" title="View this comment on GitHub" - >${event.payload.issue.title.escape()} in + >${escapeSpecialCharacters(event.payload.issue.title)} in `; } @@ -171,7 +171,7 @@ function generateEvent(event) { rel="noopener noreferrer" target="_blank" title="View this issue on GitHub" - >${event.payload.issue.title.escape()} in + >${escapeSpecialCharacters(event.payload.issue.title)} in `; case "PullRequestEvent": @@ -188,7 +188,7 @@ function generateEvent(event) { rel="noopener noreferrer" target="_blank" title="View this pull request on GitHub" - >${event.payload.pull_request.title.escape()} in + >${escapeSpecialCharacters(event.payload.pull_request.title)} in `; case "PullRequestReviewCommentEvent": @@ -205,7 +205,7 @@ function generateEvent(event) { rel="noopener noreferrer" target="_blank" title="View this comment on GitHub" - >${event.payload.pull_request.title.escape()} in + >${escapeSpecialCharacters(event.payload.pull_request.title)} in `; case "PushEvent": @@ -346,6 +346,9 @@ function updateGithubFeed() { const eventString = JSON.stringify(item); client.zrank("events", eventString, (err, reply) => { + if (err) + return; + if (reply === null) client.zadd("events", item.id, eventString, callback); else @@ -366,6 +369,16 @@ function updateGithubFeed() { // H E L P E R +function escapeSpecialCharacters(contentToEscape) { + const tagsToReplace = { + "&": "&", + "<": "<", + ">": ">" + }; + + return contentToEscape.replace(/[&<>]/g, tag => tagsToReplace[tag] || tag); +} + function refToBranch(ref) { if (ref) return ref.replace("refs/heads/", ""); diff --git a/app/index.js b/app/index.js index de4b60d..a788ffc 100755 --- a/app/index.js +++ b/app/index.js @@ -22,7 +22,7 @@ import redirects from "~data/redirects.json"; const server = fastify({ logger: { level: "warn", - prettyPrint: process.env.NODE_ENV === "development" ? true : false, + prettyPrint: process.env.NODE_ENV === "development", redact: ["req.headers.authorization"], serializers: { req(req) { diff --git a/app/modules/markdown-it-sup.js b/app/modules/markdown-it-sup.js index 5835136..ac2c580 100644 --- a/app/modules/markdown-it-sup.js +++ b/app/modules/markdown-it-sup.js @@ -16,16 +16,20 @@ function superscript(state, silent) { const max = state.posMax; const start = state.pos; let found; - let content; let token; - if (state.src.charCodeAt(start) !== 0x5E/* ^ */) return false; - if (silent) return false; // do not run pairs in validation mode - if (start + 2 >= max) return false; + if (state.src.charCodeAt(start) !== 0x5E/* ^ */) + return false; + + if (silent) + return false; // do not run pairs in validation mode + + if (start + 2 >= max) + return false; state.pos = start + 1; - while (state.pos < max) { + while(state.pos < max) { if (state.src.charCodeAt(state.pos) === 0x5E/* ^ */) { found = true; break; @@ -39,7 +43,7 @@ function superscript(state, silent) { return false; } - content = state.src.slice(start + 1, state.pos); + const content = state.src.slice(start + 1, state.pos); // do not allow unescaped spaces/newlines inside if (content.match(/(^|[^\\])(\\\\)*\s/)) { @@ -59,16 +63,14 @@ function superscript(state, silent) { if (content.match(regexForIds)) { const theLink = supText.match(regexForIds)[0].replace("(#", "").replace(")", ""); - - token.attrPush([ "id", theLink ]); + token.attrPush(["id", theLink]); // eslint-disable-line padding-line-between-statements } token = state.push("text", "", 0); if (content.match(regexForIds)) { const theText = supText.match(regexForTextBeforeLink)[0]; - - token.content = theText; + token.content = theText; // eslint-disable-line padding-line-between-statements } else token.content = supText; token = state.push("sup_close", "sup", -1); @@ -84,6 +86,6 @@ function superscript(state, silent) { // E X P O R T -module.exports = exports = function sup_plugin(md) { +module.exports = exports = function sup_plugin(md) { // eslint-disable-line camelcase md.inline.ruler.after("emphasis", "sup", superscript); }; diff --git a/app/modules/relative-date.js b/app/modules/relative-date.js index e37647c..7a981f7 100644 --- a/app/modules/relative-date.js +++ b/app/modules/relative-date.js @@ -14,23 +14,23 @@ const relativeDate = (() => { const MONTH = YEAR / 12; const formats = [ - [ 0.7 * MINUTE, "just now" ], - [ 1.5 * MINUTE, "a minute ago" ], - [ 60 * MINUTE, "minutes ago", MINUTE ], - [ 1.5 * HOUR, "an hour ago" ], - [ DAY, "hours ago", HOUR ], - [ 2 * DAY, "yesterday" ], - [ 7 * DAY, "days ago", DAY ], - [ 1.5 * WEEK, "a week ago" ], - [ MONTH, "weeks ago", WEEK ], - [ 1.5 * MONTH, "a month ago" ], - [ YEAR, "months ago", MONTH ], - [ 1.5 * YEAR, "a year ago" ], - [ Number.MAX_VALUE, "years ago", YEAR ] + [0.7 * MINUTE, "just now"], + [1.5 * MINUTE, "a minute ago"], + [60 * MINUTE, "minutes ago", MINUTE], + [1.5 * HOUR, "an hour ago"], + [DAY, "hours ago", HOUR], + [2 * DAY, "yesterday"], + [7 * DAY, "days ago", DAY], + [1.5 * WEEK, "a week ago"], + [MONTH, "weeks ago", WEEK], + [1.5 * MONTH, "a month ago"], + [YEAR, "months ago", MONTH], + [1.5 * YEAR, "a year ago"], + [Number.MAX_VALUE, "years ago", YEAR] ]; function relativeDate(input, reference) { - !reference && (reference = (new Date).getTime()); + !reference && (reference = (new Date()).getTime()); reference instanceof Date && (reference = reference.getTime()); input instanceof Date && (input = input.getTime()); @@ -40,9 +40,8 @@ const relativeDate = (() => { for (let i = -1; ++i < len;) { const format = formats[i]; - if (delta < format[0]) { + if (delta < format[0]) return format[2] === undefined ? format[1] : Math.round(delta / format[2]) + " " + format[1]; - } } } diff --git a/app/sockets.js b/app/sockets.js index 94a7cb3..52fb9fc 100644 --- a/app/sockets.js +++ b/app/sockets.js @@ -124,12 +124,13 @@ function generateContent(exampleNumber, displayTrendingContent) { const renderedContentCollection = []; const trendingContentData = response.data; - for (const data of trendingContentData) + for (const data of trendingContentData) { rawContentCollection.push(fetchMetadata({ claim: data.url, example: exampleNumber, method: "resolve" })); + } Promise.all(rawContentCollection).then(collection => { for (const part of collection) { diff --git a/app/views/api.js b/app/views/api.js index 4ec9166..1f5de32 100644 --- a/app/views/api.js +++ b/app/views/api.js @@ -45,9 +45,10 @@ export default async(state) => { }; const tags = await getTags(repository); + const currentTag = tag.length ? tag : tags[0]; try { - const apiResponse = await parseApiFile({ repo: repository, tag: tag ? tag : tags[0] }); + const apiResponse = await parseApiFile({ repo: repository, tag: currentTag }); return asyncHtml`