diff --git a/helpers/fetch-metadata.js b/helpers/fetch-metadata.js index f5b07ba..97f2dd3 100644 --- a/helpers/fetch-metadata.js +++ b/helpers/fetch-metadata.js @@ -15,6 +15,7 @@ const stringifyObject = require("stringify-object"); const randomString = local("/helpers/random-string"); const loadLanguages = require("prismjs/components/"); const logSlackError = local("/helpers/slack"); +const publishMeme = local("/helpers/publish-meme"); const uploadImage = local("/helpers/upload-image"); loadLanguages(["json"]); @@ -56,43 +57,81 @@ module.exports = exports = (data, socket) => { if (resolveMethod === "publish") { apiRequestMethod = "PUT"; - body.bid = 0.001; // Hardcoded publish amount + // Required for publishing + body.author = "lbry.tech"; + body.bid = 0.0001; // Hardcoded publish amount body.description = dataDetails.description; - body.file_path = dataDetails.file_path; // just base64 string body.language = dataDetails.language; body.license = dataDetails.license; - body.name = dataDetails.name.replace(/\s/g, "") + randomString(10); + body.name = dataDetails.name.replace(/\s/g, "-") + randomString(10); // underscores are not allowed? body.nsfw = dataDetails.nsfw; body.title = dataDetails.title; + // Gotta let the blockchain know what to save + body.file_path = dataDetails.file_path; // just base64 string + return uploadImage(body.file_path).then(uploadResponse => { - // if (uploadResponse.status !== "ok") return; - // console.log("————— RESPONSE"); - // console.log(uploadResponse); + if (!uploadResponse.status || uploadResponse.status !== "ok") { + socket.send(JSON.stringify({ + "details": "Image upload failed", + "message": "notification", + "type": "error" + })); + + 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; - body.filename = uploadResponse.filename; - // Reference: - // https://github.com/lbryio/lbry.tech/blob/legacy/content/.vuepress/components/Tour/Step2.vue - // https://github.com/lbryio/lbry.tech/blob/legacy/server.js - }).catch(uploadError => { - // console.log("————— ERROR"); - // console.log(uploadError); + return publishMeme(body).then(publishResponse => { + let explorerNotice = ""; - socket.send(JSON.stringify({ - "details": "Image upload failed", - "message": "notification", - "type": "error" - })); + if (publishResponse.error) { + socket.send(JSON.stringify({ + "details": "Meme publish failed", + "message": "notification", + "type": "error" + })); - logSlackError( - "\n" + - "> *DAEMON ERROR:* ```" + JSON.parse(JSON.stringify(uploadError)) + "```" + "\n" + - "> _Cause: Someone attempted to publish a meme via the Tour_\n" - ); + if (process.env.NODE_ENV !== "development") { + logSlackError( + "\n" + + "> *DAEMON ERROR:* ```" + JSON.parse(JSON.stringify(publishResponse.error)) + "```" + "\n" + + "> _Cause: Someone is going through the Tour after a response has been parsed_\n" + ); + } - return; + return; + } + + if ( + publishResponse.result && + publishResponse.result.txid + ) explorerNotice = ` +

If you want proof of the tip you just gave, check it out on our blockchain explorer!

+ `; + + const renderedCode = prism.highlight(stringifyObject(publishResponse, { indent: " ", singleQuotes: false }), prism.languages.json, "json"); + + return socket.send(JSON.stringify({ + "html": raw(` +

Response

+ ${explorerNotice} +
${renderedCode}
+ + `), + "message": "updated html", + "selector": `#example${data.example}-result` + })); + }); }); } diff --git a/helpers/publish-meme.js b/helpers/publish-meme.js new file mode 100644 index 0000000..1eb5260 --- /dev/null +++ b/helpers/publish-meme.js @@ -0,0 +1,26 @@ +"use strict"; + + + +// P A C K A G E + +const request = require("request-promise-native"); + + + +// E X P O R T + +module.exports = exports = publishMetadata => new Promise((resolve, reject) => { // eslint-disable-line + return request({ + body: { + authorization: process.env.LBRY_DAEMON_ACCESS_TOKEN, + metadata: publishMetadata + }, + json: true, + method: "PUT", + url: `${process.env.NODE_ENV === "development" ? "http://localhost:5200/publish" : "https://daemon.lbry.tech/publish" }` + }, (error, response, body) => { + if (error) resolve(error); + resolve(body); + }); +}); diff --git a/helpers/upload-image.js b/helpers/upload-image.js index 25dd75b..b47a231 100644 --- a/helpers/upload-image.js +++ b/helpers/upload-image.js @@ -21,7 +21,6 @@ module.exports = exports = imageSource => new Promise((resolve, reject) => { // url: `${process.env.NODE_ENV === "development" ? "http://localhost:5200/image" : "https://daemon.lbry.tech/image" }` }, (error, response, body) => { if (error) resolve(error); - body = JSON.parse(body); resolve(body); }); }); diff --git a/views/pages/--tour.js b/views/pages/--tour.js deleted file mode 100644 index 67e98b1..0000000 --- a/views/pages/--tour.js +++ /dev/null @@ -1,376 +0,0 @@ -"use strict"; - - - -// P A C K A G E - -const fs = require("graceful-fs"); -const html = require("choo-async/html"); -const raw = require("nanohtml/raw"); - - - -// E X P O R T - -module.exports = exports = () => async () => html` -
- - - ${step1()} - ${step2()} - ${step3()} -
- - -`; - - - -function step1() { - /** - Step 1 loading steps: - - exampleCode !== "" -
- - - isLoading -
- - - jsonData -

Success! Here is the response for lbry://{{ address }}:

-
- Go to next step - - - TODO: - [✓] Create message for error - [ ] Scroll to top of page when selecting a claim - */ - - return html` -
-
-
-

Learn the LBRY protocol by examples

-

Let's start by getting the associated metadata for a claim.

- -
- lbry:// - -
-
-
- -
- -
-

…or select a live example from below

- -
- - -
-

It's a Disaster

- -
-
- -
- - -
-

Unbubbled with Jamie King, Ep1.1 — Bitcoin, Boom or Bust

- -
-
- -
- - -
-

FORTNITE TOP STREAM MOMENTS — Nickatnyte & GamingwithMolt

- -
-
- -
- - -
-

LBRY Coin (LBC) GPU Miner for AMD and NVIDIA

- -
-
-
-
- `; -} - - - -function step2() { - /** - Step 2 loading steps: - - exampleCode !== '' -
- - - isLoading -
- - - jsonData -

Success!
- See the transaction on explorer.lbry.io -

- -

Here is the raw response:

-
- - Meme submission process: - - `PUT` request to `http://daemon.lbry.tech/images.php`: - - headers: "Content-Type": "text/plain" - - qs: access_token: process.env.LBRY_DAEMON_ACCESS_TOKEN - - body: document.getElementById("meme-canvas").toDataURL("image/jpeg", 0.6) - - response should be parsed as JSON - - // - - socket emit "fetch metadata": - - bid: 0.001, // hard-coded on the back-end - - description: component.description, - - file_path: uploadResponse.body.filename, - - language: component.language, - - license: component.license, - - method: "publish", - - name: component.title, - - nsfw: component.nsfw, - - title: component.title - - socket emit error from back-end if any field is missing - - Process after submitting meme: - - isLoading appears - - exampleCode and jsonData replace `#step2-placeholder` contents - - next button should exist - - Issues: - - image isn't uploaded to spee.ch - - response is blank - - response should have link to upload on Blockchain Explorer - - NSFW flag should work - */ - - const images = [ - { - alt: "Carl Sagan", - src: "/assets/media/images/carlsagan2.jpg" - }, - { - alt: "Doge", - src: "/assets/media/images/doge-meme.jpg" - }, - { - alt: "LBRY Logo With Green Background", - src: "/assets/media/images/lbry-green.png" - } - ]; - - const memePlaceholderData = { - bottomLine: { - placeholder: "Top line", - value: "that I made" - }, - description: { - placeholder: "Description", - value: "Check out this image I published to LBRY via lbry.tech" - }, - topLine: { - placeholder: "Top line", - value: "This is an example meme" - }, - title: { - placeholder: "Title", - value: "Dank Meme Supreme da Cheese" - } - }; - - const renderedImages = []; - - for (const image of images) { - renderedImages.push(`${image.alt}`); - } - - return html` - - `; -} - - - -function step3() { - /** - Step 3 loading steps: - - exampleCode !== '' -
- - - isLoading -
- - - jsonData -

Success! Here is the response:

-
- */ - - return html` - - `; -} diff --git a/views/partials/tour-scripts.js b/views/partials/tour-scripts.js index 7eac1a7..145dbd1 100644 --- a/views/partials/tour-scripts.js +++ b/views/partials/tour-scripts.js @@ -43,8 +43,8 @@ $("body").on("click", "[data-action]", event => { $(".tour__sidebar__example").removeClass("active"); $(".tour__sidebar__example:nth-child(1)").addClass("active"); - $("#tour-loader").empty().show(); // .html(""); - $("#tour-results").empty().show(); // .html(""); + $("#tour-loader").empty().show(); + $("#tour-results").empty().show(); send(JSON.stringify({ "message": `request for ${data.action}` @@ -63,8 +63,8 @@ $("body").on("click", "[data-action]", event => { $(".tour__sidebar__example").removeClass("active"); $(".tour__sidebar__example:nth-child(2)").addClass("active"); - $("#tour-loader").empty().show(); // .html(""); - $("#tour-results").empty().show(); // .html(""); + $("#tour-loader").empty().show(); + $("#tour-results").empty().show(); send(JSON.stringify({ "message": `request for ${data.action}` @@ -83,8 +83,8 @@ $("body").on("click", "[data-action]", event => { $(".tour__sidebar__example").removeClass("active"); $(".tour__sidebar__example:nth-child(3)").addClass("active"); - $("#tour-loader").empty().show(); // .html(""); - $("#tour-results").empty().show(); // .html(""); + $("#tour-loader").empty().show(); + $("#tour-results").empty().show(); send(JSON.stringify({ "message": `request for ${data.action}` @@ -108,8 +108,8 @@ $("body").on("click", ".tour__content__meme__canvas__thumbnail", event => { updateCanvas(event.currentTarget); }); -$("#fetch-claim-uri").on("keyup", function (e) { - const key = e.keyCode ? e.keyCode : e.which; +$("#fetch-claim-uri").on("keyup", event => { + const key = event.keyCode ? event.keyCode : event.which; if (key === 13 && $("#fetch-claim-uri").val()) fetchMetadata(1, $("#fetch-claim-uri").val()); }); @@ -189,6 +189,16 @@ curl --header "Content-Type: application/json" "example": exampleNumber })); + $("#tour-results").html(` +

+# This will be updated soon
+        
+ +
+
+ `); + + $("#tour-loader").hide(); break; case 3: @@ -230,16 +240,6 @@ function getMemeInfo() { // TODO: Error handling title: $("#meme-title").val() }; - /* - info.description = $("#meme-description").val(); - info.file_path = $("#meme-canvas")[0].toDataURL("image/jpeg", 0.6); - info.language = $("#meme-language").val(); - info.license = $("#meme-license").val(); - info.name = $("#meme-title").val(); - info.nsfw = $("#meme-nsfw-flag")[0].checked; - info.title = $("#meme-title").val(); - */ - return info; }