diff --git a/.env.sample b/.env.sample index 4f36271..ccdcb8a 100644 --- a/.env.sample +++ b/.env.sample @@ -2,6 +2,10 @@ # HTTPS is assumed for security reasons DAEMON_URL= +# These are for powering the LBRY Developer Program +GITHUB_APP_ID= +GITHUB_APP_TOKEN= + # https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app # We use this to show the GitHub feed on the homepage GITHUB_OAUTH_TOKEN= diff --git a/app/client.js b/app/client.js index 9b8d032..76e4235 100755 --- a/app/client.js +++ b/app/client.js @@ -35,7 +35,6 @@ function main() { app.route("/", page(require("./views/home"))); app.route("/api/*", page(require("./views/api"))); - app.route("/dev-program", page(require("./views/dev"))); app.route("/spec", page(require("./views/spec"))); app.route("/*", page(require("./views/redirect"))); diff --git a/app/components/client/playground-scripts.js b/app/components/client/playground-scripts.js index 8b82406..db3b836 100644 --- a/app/components/client/playground-scripts.js +++ b/app/components/client/playground-scripts.js @@ -131,9 +131,9 @@ function initializePlayground() { document.querySelector("#fetch-claim-uri").focus(); document.querySelector(".playground-navigation__example:nth-child(1)").classList.add("active"); - send(JSON.stringify({ + send({ message: "landed on playground" - })); + }); setTimeout(() => { document.querySelector(".playground-navigation__example:nth-child(1)").click(); @@ -146,12 +146,12 @@ function fetchMetadata(exampleNumber, data) { switch(exampleNumber) { case 1: - send(JSON.stringify({ + send({ claim: data, message: "fetch metadata", method: "resolve", example: exampleNumber - })); + }); document.getElementById("fetch-claim-uri").value = data; document.getElementById("playground-results").innerHTML = playgroundResponseForExample1(data); @@ -159,24 +159,24 @@ function fetchMetadata(exampleNumber, data) { break; case 2: - send(JSON.stringify({ + send({ data: data, message: "fetch metadata", method: "publish", example: exampleNumber - })); + }); document.getElementById("playground-results").innerHTML = playgroundResponseForExample2(getMemeInfo()); document.getElementById("playground-loader").style.display = "none"; break; case 3: - send(JSON.stringify({ + send({ claim: data, message: "fetch metadata", method: "claim_tip", example: exampleNumber - })); + }); document.getElementById("fetch-claim-uri").value = data; document.getElementById("playground-results").innerHTML = playgroundResponseForExample3(data); @@ -279,9 +279,9 @@ const handleExamples = debounce(event => { document.getElementById("playground-loader").removeAttribute("style"); document.getElementById("playground-results").removeAttribute("style"); - send(JSON.stringify({ + send({ message: `request for ${data.action}` - })); + }); break; @@ -305,9 +305,9 @@ const handleExamples = debounce(event => { document.getElementById("playground-loader").removeAttribute("style"); document.getElementById("playground-results").removeAttribute("style"); - send(JSON.stringify({ + send({ message: `request for ${data.action}` - })); + }); break; @@ -334,9 +334,9 @@ const handleExamples = debounce(event => { document.getElementById("playground-loader").removeAttribute("style"); document.getElementById("playground-results").removeAttribute("style"); - send(JSON.stringify({ + send({ message: `request for ${data.action}` - })); + }); break; diff --git a/app/dist/scripts/app.js b/app/dist/scripts/app.js index 3dc9a18..26293d5 100755 --- a/app/dist/scripts/app.js +++ b/app/dist/scripts/app.js @@ -63,10 +63,10 @@ document.querySelector("[data-action='subscribe to newsletter']").onclick = () = document.getElementById("emailMessage").classList.remove("error"); - send(JSON.stringify({ + send({ email: email, message: "subscribe" - })); + }); }; diff --git a/app/helpers/github.js b/app/helpers/github.js index 7e6ec59..381eebb 100644 --- a/app/helpers/github.js +++ b/app/helpers/github.js @@ -336,12 +336,21 @@ function generateUrl(type, event) { } } -function getGitHubUserToken() { +async function getGitHubUserToken() { // const clientWithAuth = new Octokit({ - // auth: `token ${GITHUB_APP_TOKEN}` + // auth: `token ${process.env.GITHUB_APP_TOKEN}` // }); - // console.log(clientWithAuth); + const result = await octokit.oauthAuthorizations.createAuthorization({ // eslint-disable-line no-unused-vars + client_id: process.env.GITHUB_APP_ID, + client_secret: process.env.GITHUB_APP_TOKEN, + note: "LBRY Developer Auth", + scopes: [ + "public_repo" + ] + }); + + // console.log(result); // console.log("—————"); } @@ -355,8 +364,10 @@ function updateGithubFeed() { const eventString = JSON.stringify(item); client.zrank("events", eventString, (err, reply) => { - if (reply === null) client.zadd("events", item.id, eventString, callback); - else callback(); + if (reply === null) + client.zadd("events", item.id, eventString, callback); + else + callback(); }); }, () => client.zremrangebyrank("events", 0, -51)); // Keep the latest 50 events }) diff --git a/app/sockets.js b/app/sockets.js index f34c855..5869b13 100644 --- a/app/sockets.js +++ b/app/sockets.js @@ -10,7 +10,7 @@ import html from "choo/html"; // U T I L S import fetchMetadata from "@helper/fetch-metadata"; -import { generateGitHubFeed } from "@helper/github"; +import { generateGitHubFeed, getGitHubUserToken } from "@helper/github"; import messageSlack from "@helper/slack"; @@ -21,9 +21,11 @@ export default (socket, action) => { if (typeof socket !== "object" && typeof action !== "object") return; - action = JSON.parse(action); - switch(true) { + case action.message === "auth me with github": + getGitHubUserToken(); + break; + case action.message === "fetch metadata": fetchMetadata(action, socket); break; diff --git a/app/views/dev.js b/app/views/dev.js deleted file mode 100644 index d41a15f..0000000 --- a/app/views/dev.js +++ /dev/null @@ -1,41 +0,0 @@ -"use strict"; - - - -// I M P O R T - -import html from "choo/html"; - - - -// E X P O R T - -export default () => html` -
- - -
-
-

When developing for LBRY, having LBC (LBRY credits) makes it easier to develop applications and interface with our APIs.

-

To qualify for free LBC you must:

- -
    -
  • have a GitHub account, and
  • -
  • have a public PR (pull request) in the past year
  • -
- -

If this sounds like you, get started here!

- -

- If you have not downloaded our SDK yet, you should and generate a wallet address so we know where to send your LBC! -

-
-
-
-`;