diff --git a/app/client.js b/app/client.js index 1bf2802..8bae0e8 100755 --- a/app/client.js +++ b/app/client.js @@ -2,19 +2,17 @@ -// P A C K A G E S +// I M P O R T S import async from "choo-async"; import asyncHtml from "choo-async/html"; import choo from "choo"; -import devtools from "choo-devtools"; -import { require as local } from "app-root-path"; import ssr from "choo-ssr"; // U T I L S -const head = local("/app/components/head").default; -const wrapper = local("/app/components/wrapper").default; +import head from "./components/head"; +import wrapper from "./components/wrapper"; @@ -23,8 +21,6 @@ const wrapper = local("/app/components/wrapper").default; function main() { const app = async(choo()); - if (process.env.NODE_ENV !== "production") app.use(devtools()); - const page = view => ( shell( ssr.head( @@ -53,6 +49,7 @@ if (typeof window !== "undefined") main(); // E X P O R T module.exports = exports = main; +// export default main(); diff --git a/app/components/api/header-blockchain.js b/app/components/api/header-blockchain.js index 34a9a85..ec05019 100644 --- a/app/components/api/header-blockchain.js +++ b/app/components/api/header-blockchain.js @@ -2,7 +2,7 @@ -// P A C K A G E +// I M P O R T import html from "choo/html"; diff --git a/app/components/api/header-sdk.js b/app/components/api/header-sdk.js index 4ac685c..5e4dd50 100644 --- a/app/components/api/header-sdk.js +++ b/app/components/api/header-sdk.js @@ -2,7 +2,7 @@ -// P A C K A G E +// I M P O R T import html from "choo/html"; diff --git a/app/components/client/ecosystem-scripts.js b/app/components/client/ecosystem-scripts.js index 07914c7..8fd87f5 100644 --- a/app/components/client/ecosystem-scripts.js +++ b/app/components/client/ecosystem-scripts.js @@ -1,4 +1,4 @@ -/* global document, localStorage */ "use strict"; +"use strict"; /* global document, localStorage */ @@ -199,18 +199,14 @@ for (const module of mainModules) { if ( module[Object.keys(module)] === "true" && document.querySelector(`.ecosystem__module.${Object.keys(module)} h2 span`) - ) { - document.querySelector(`.ecosystem__module.${Object.keys(module)} h2 span`).click(); - } + ) document.querySelector(`.ecosystem__module.${Object.keys(module)} h2 span`).click(); } for (const subModule of subModules) { if ( subModule[Object.keys(subModule)] === "true" && document.querySelector(`.ecosystem__submodule.${Object.keys(subModule)} h3`) - ) { - document.querySelector(`.ecosystem__submodule.${Object.keys(subModule)} h3`).click(); - } + ) document.querySelector(`.ecosystem__submodule.${Object.keys(subModule)} h3`).click(); } diff --git a/app/components/client/glossary-scripts.js b/app/components/client/glossary-scripts.js index cdccd8b..8973286 100644 --- a/app/components/client/glossary-scripts.js +++ b/app/components/client/glossary-scripts.js @@ -1,4 +1,4 @@ -/* global document */ "use strict"; +"use strict"; /* global document */ diff --git a/app/components/client/playground-scripts.js b/app/components/client/playground-scripts.js index cf9af68..99f4bf9 100644 --- a/app/components/client/playground-scripts.js +++ b/app/components/client/playground-scripts.js @@ -1,4 +1,4 @@ -/* global document, navigator, send, window */ "use strict"; +"use strict"; /* global document, navigator, send, window */ @@ -6,10 +6,10 @@ initializePlayground(); -if (window.location.href.search && window.location.href.split("?url=")[1]) { // pre-fill example one if search parameter exists +// pre-fill example one if search parameter exists +if (window.location.href.search && window.location.href.split("?url=")[1]) { const searchParameter = window.location.href.split("?url=")[1]; - - fetchMetadata(1, searchParameter); + fetchMetadata(1, searchParameter); // eslint-disable-line padding-line-between-statements } @@ -34,17 +34,19 @@ document.querySelector("body").addEventListener("click", event => { }); document.getElementById("fetch-claim-uri").addEventListener("keyup", event => { - const key = event.keyCode ? event.keyCode : event.which; + const key = event.keyCode ? + event.keyCode : + event.which; switch(true) { - case (document.querySelector("[data-example='1']").classList.contains("active")): + case document.querySelector("[data-example='1']").classList.contains("active"): if ( key === 13 && document.getElementById("fetch-claim-uri").value.length > 0 ) fetchMetadata(1, document.getElementById("fetch-claim-uri").value); break; - case (document.querySelector("[data-example='3']").classList.contains("active")): + case document.querySelector("[data-example='3']").classList.contains("active"): if ( key === 13 && document.getElementById("fetch-claim-uri").value.length > 0 @@ -79,7 +81,7 @@ function clearCanvas(canvas) { ctx.restore(); } -function detectLanguageAndUpdate() { // eslint-disable-line +function detectLanguageAndUpdate() { // eslint-disable-line no-unused-vars const compare = (array1, array2) => array2.filter(value => array2.indexOf(value)); // compare two arrays and get match(es) const memeLocaleObject = document.getElementById("meme-language").children; const memeLocales = []; @@ -115,8 +117,8 @@ function debounce(func, wait, immediate) { const callNow = immediate && !timeout; clearTimeout(timeout); - timeout = setTimeout(later, wait); + if (callNow) func.apply(context, args); }; } @@ -136,8 +138,6 @@ function initializePlayground() { }, 300); } - - function fetchMetadata(exampleNumber, data) { if (!exampleNumber) return; @@ -151,17 +151,7 @@ function fetchMetadata(exampleNumber, data) { })); document.getElementById("fetch-claim-uri").value = data; - - document.getElementById("playground-results").innerHTML = ` -
-# With the LBRY app/daemon running locally, you can use this in your Terminal
-curl --header "Content-Type: application/json" --data '{ "method": "resolve", "params": { "uri": "${data}" }}' http://localhost:5279
-
-
-
-
- `;
-
+ document.getElementById("playground-results").innerHTML = playgroundResponseForExample1(data);
document.getElementById("playground-loader").style.display = "none";
break;
@@ -173,16 +163,7 @@ curl --header "Content-Type: application/json"
example: exampleNumber
}));
- document.getElementById("playground-results").innerHTML = `
-
-# With the LBRY app/daemon running locally, you can use this in your Terminal
-curl --header "Content-Type: application/json" --data '{ "method": "publish", "params": { "name": "${getMemeInfo().name}", "file_path": "ABSOLUTE_PATH_TO_MEDIA_ON_YOUR_COMPUTER", "bid": "0.001", "metadata": { "description": "${getMemeInfo().description}", "title": "${getMemeInfo().title}", "language": "${getMemeInfo().language}", "license": "${getMemeInfo().license}", "nsfw": ${getMemeInfo().nsfw} }}}' http://localhost:5279
-
-
-
-
- `;
-
+ document.getElementById("playground-results").innerHTML = playgroundResponseForExample2(getMemeInfo());
document.getElementById("playground-loader").style.display = "none";
break;
@@ -195,17 +176,7 @@ curl --header "Content-Type: application/json"
}));
document.getElementById("fetch-claim-uri").value = data;
-
- document.getElementById("playground-results").innerHTML = `
-
-# With the LBRY app/daemon running locally, you can use this in your Terminal
-curl --header "Content-Type: application/json" --data '{ "method": "claim_tip", "params": { "amount": "0.001", "claim_id": "${data}" }}' http://localhost:5279
-
-
-
-
- `;
-
+ document.getElementById("playground-results").innerHTML = playgroundResponseForExample3(data);
document.getElementById("playground-loader").style.display = "none";
break;
@@ -226,6 +197,42 @@ function getMemeInfo() { // TODO: Error handling
};
}
+function playgroundResponseForExample1(source) {
+ return `
+
+# With the LBRY app/daemon running locally, you can use this in your Terminal
+curl --header "Content-Type: application/json" --data '{ "method": "resolve", "params": { "uri": "${source}" }}' http://localhost:5279
+
+
+
+
+ `;
+}
+
+function playgroundResponseForExample2(source) {
+ return `
+
+# With the LBRY app/daemon running locally, you can use this in your Terminal
+curl --header "Content-Type: application/json" --data '{ "method": "publish", "params": { "name": "${source.name}", "file_path": "ABSOLUTE_PATH_TO_MEDIA_ON_YOUR_COMPUTER", "bid": "0.001", "metadata": { "description": "${source.description}", "title": "${source.title}", "language": "${source.language}", "license": "${source.license}", "nsfw": ${source.nsfw} }}}' http://localhost:5279
+
+
+
+
+ `;
+}
+
+function playgroundResponseForExample3(source) {
+ return `
+
+# With the LBRY app/daemon running locally, you can use this in your Terminal
+curl --header "Content-Type: application/json" --data '{ "method": "claim_tip", "params": { "amount": "0.001", "claim_id": "${source}" }}' http://localhost:5279
+
+
+
+
+ `;
+}
+
const handleExamples = debounce(event => {
let exampleNumber;
const data = event.dataset;
@@ -340,7 +347,7 @@ const handleExamples = debounce(event => {
}
}, 10);
-function initCanvas() { // eslint-disable-line
+function initCanvas() { // eslint-disable-line no-unused-vars
const canvas = document.getElementById("meme-canvas");
const canvasHeight = 600;
const canvasWidth = 800;
diff --git a/app/components/ecosystem.js b/app/components/ecosystem.js
deleted file mode 100644
index 585b518..0000000
--- a/app/components/ecosystem.js
+++ /dev/null
@@ -1,43 +0,0 @@
-"use strict";
-
-
-
-// P A C K A G E
-
-const local = require("app-root-path").require;
-
-// U T I L S
-
-const applications = local("/app/components/ecosystem/module-applications");
-const chainquery = local("/app/components/ecosystem/submodule-chainquery");
-const lbry = local("/app/components/ecosystem/module-lbry");
-const lbrycrd = local("/app/components/ecosystem/module-lbrycrd");
-const lighthouse = local("/app/components/ecosystem/submodule-lighthouse");
-const reflector = local("/app/components/ecosystem/submodule-reflector");
-const wallet = local("/app/components/ecosystem/submodule-wallet");
-
-
-
-// E X P O R T
-
-export default () => {
- return `
- Tipping creators not in the whitelist for this example is not allowed.
+ `),
+ message: "show result",
+ selector: `#example${data.example}-result`
}));
-
- if (process.env.NODE_ENV !== "development") {
- logSlackError(
- "\n" +
- "> *DAEMON ERROR:*\n" +
- "> _Cause: Someone attempted to upload a meme to the web daemon_\n"
- );
- }
-
- return;
}
- body.file_path = uploadResponse.filename;
+ apiRequestMethod = "POST";
+ body.amount = "0.001"; // Hardcoded tip amount
+ body.claim_id = claimAddress;
- return publishMeme(body).then(publishResponse => {
- let explorerNotice = "";
+ break;
- if (publishResponse.error) {
+
+
+ // P U B L I S H
+ // E X A M P L E
+ case resolveMethod === "publish":
+ apiRequestMethod = "PUT";
+
+ // Required for publishing
+ body.author = "lbry.tech";
+ body.bid = "0.001"; // Hardcoded publish amount
+ body.description = dataDetails.description;
+ body.language = dataDetails.language;
+ body.license = dataDetails.license;
+ body.name = dataDetails.name + "-" + randomString(10);
+ body.nsfw = dataDetails.nsfw;
+ body.title = dataDetails.title;
+
+ // Gotta let the blockchain know what to save
+ body.file_path = dataDetails.file_path;
+
+ try {
+ const imageUploadResponse = await uploadImage(body.file_path);
+ body.file_path = imageUploadResponse.filename; // eslint-disable-line padding-line-between-statements
+
+ try {
+ const memePublishResponse = await publishMeme(body);
+
+ switch(true) {
+ case memePublishResponse.result:
+ case memePublishResponse.result.claim_address:
+ explorerNotice = memePublishMessaging(memePublishResponse);
+ break;
+
+ default:
+ break;
+ }
+
+ delete memePublishResponse.result.lbrytech_claim_name;
+
+ const renderedCode = prism.highlight(
+ stringifyObject(memePublishResponse, { indent: " ", singleQuotes: false }),
+ prism.languages.json,
+ "json"
+ );
+
+ return socket.send(JSON.stringify({
+ example: data.example,
+ html: raw(`
+ ${renderedCode}
+ `),
+ message: "show result",
+ selector: `#example${data.example}-result`
+ }));
+ }
+
+ catch(memePublishError) {
socket.send(JSON.stringify({
details: "Meme publish failed",
message: "notification",
@@ -118,81 +159,49 @@ module.exports = exports = async(data, socket) => {
}));
if (process.env.NODE_ENV !== "development") {
- logSlackError(
- "\n" +
- "> *DAEMON ERROR:* ```" + JSON.parse(JSON.stringify(publishResponse.error)) + "```" + "\n" +
- "> _Cause: Someone is going through the Playground after a response has been parsed_\n"
- );
+ messageSlack({
+ message: "```" + JSON.parse(JSON.stringify(memePublishError.error)) + "```",
+ pretext: "_Someone is going through the Playground after a response has been parsed_",
+ title: "DAEMON ERROR"
+ });
}
return;
}
+ }
- if (
- publishResponse.result &&
- publishResponse.result.claim_address
- ) explorerNotice = `
-
- Nicely done, you've published to lbry://${publishResponse.result.lbrytech_claim_name}
.
-
- To see Proof of Work (lol) that your meme is on the LBRY blockchain, check it out on our blockchain explorer! Please note that it may take a couple minutes for the transaction to be confirmed.
-
- You can also check out your meme (once the transaction is confirmed) on LBRY or Spee.ch!
-
${renderedCode}
- `),
- message: "show result",
- selector: `#example${data.example}-result`
+ catch(imageUploadError) {
+ socket.send(JSON.stringify({
+ details: "Image upload failed",
+ message: "notification",
+ type: "error"
}));
- });
- });
- }
- // R E S O L V E
- // E X A M P L E
+ if (process.env.NODE_ENV !== "development") {
+ messageSlack({
+ message: "```" + imageUploadError.status + "```",
+ pretext: "_Someone attempted to upload a meme to the web daemon and it failed_",
+ title: "DAEMON ERROR"
+ });
+ }
- if (resolveMethod === "resolve") {
- apiRequestMethod = "GET";
- body.uri = claimAddress;
- }
+ return;
+ }
- // T I P
- // E X A M P L E
- if (resolveMethod === "claim_tip") {
- if (!approvedContentIdsForTipping.includes(claimAddress)) {
- return socket.send(JSON.stringify({
- example: data.example,
- html: raw(`
- Tipping creators not in the whitelist for this example is not allowed.
- `),
- message: "show result",
- selector: `#example${data.example}-result`
- }));
- }
- apiRequestMethod = "POST";
+ // R E S O L V E
+ // E X A M P L E
+ case resolveMethod === "resolve":
+ apiRequestMethod = "GET";
+ body.uri = claimAddress;
- body.amount = "0.001"; // Hardcoded tip amount
- body.claim_id = claimAddress;
+ break;
+
+
+
+ default:
+ break;
}
@@ -206,19 +215,23 @@ module.exports = exports = async(data, socket) => {
method: apiRequestMethod
};
- const queryUrl = `${process.env.NODE_ENV === "development" ? `http://localhost:5200/${resolveMethod}` : `https://${process.env.DAEMON_URL}/${resolveMethod}`}`;
+ const queryUrl = process.env.NODE_ENV === "development" ?
+ `http://localhost:5200/${resolveMethod}` :
+ `https://${process.env.DAEMON_URL}/${resolveMethod}`;
try {
const response = await got(queryUrl, queryOptions);
- let explorerNotice = "";
- if (
- data.example === 3 &&
- response.body.result &&
- response.body.result.txid
- ) explorerNotice = `
- If you want proof of the tip you just gave on behalf of LBRY, check it out on our blockchain explorer! Please note that it may take a couple minutes for the transaction to be confirmed.
+ Nicely done, you've published to lbry://${source.result.lbrytech_claim_name}
.
+
+
+
+ To see Proof of Work (lol) that your meme is on the LBRY blockchain, check it out on our blockchain explorer! Please note that it may take a couple minutes for the transaction to be confirmed.
+
+
+
+ You can also check out your meme (once the transaction is confirmed) on LBRY or Spee.ch!
+
+ If you want proof of the tip you just gave on behalf of LBRY, check it out on our blockchain explorer! Please note that it may take a couple minutes for the transaction to be confirmed. +