Second step of tour blocked by lbrynet error

This commit is contained in:
ポール ウェッブ 2018-07-25 13:35:59 -05:00
parent 91c1954949
commit 9b761cea5b
3 changed files with 139 additions and 101 deletions

View file

@ -50,7 +50,7 @@
"choo-devtools": "^2.5.1",
"nodemon": "^1.18.3",
"npm-run-all": "^4.1.3",
"sass": "^1.10.0",
"sass": "^1.10.1",
"snazzy": "^7.1.1",
"standardx": "^2.1.0",
"updates": "^4.1.0"

205
server.js
View file

@ -135,6 +135,123 @@ start();
// H E L P E R S
function fetchMetadata(data, socket) {
let dataDetails = "";
if (data.step === 1 && !data.claim || !data.method) return;
if (data.step === 2 && !data.data) return;
if (data.step === 2) dataDetails = data.data;
const claimAddress = data.claim;
const resolveMethod = data.method;
const allowedClaims = [
"fortnite-top-stream-moments-nickatnyte",
"itsadisaster",
"six",
"unbubbled1-1"
];
const allowedMethods = [
"publish",
"resolve",
"wallet_send"
];
if (allowedMethods.indexOf(resolveMethod) < 0) return socket.send(JSON.stringify({
"details": "Unallowed resolve method for tutorial",
"message": "notification",
"type": "error"
}));
if (data.step === 1 && allowedClaims.indexOf(claimAddress) < 0) return socket.send(JSON.stringify({
"details": "Invalid claim ID for tutorial",
"message": "notification",
"type": "error"
}));
const body = {};
body.access_token = process.env.LBRY_DAEMON_ACCESS_TOKEN;
body.method = resolveMethod;
if (data.step === 1) body.uri = claimAddress;
if (resolveMethod === "publish") {
body.bid = 0.001; // Hardcoded publish amount
body.description = dataDetails.description;
body.file_path = process.env.LBRY_DAEMON_IMAGES_PATH + dataDetails.file_path; // TODO: Fix the internal image path in daemon (original comment, check to see if still true)
body.language = dataDetails.language;
body.license = dataDetails.license;
body.name = dataDetails.name;
body.nsfw = dataDetails.nsfw;
body.title = dataDetails.title;
return uploadImage(body.file_path).then(uploadResponse => {
if (uploadResponse.status !== "ok") return;
body.file_path = uploadResponse.filename;
body.method = resolveMethod;
// console.log(body);
return new Promise((resolve, reject) => {
request({
qs: body,
url: "http://daemon.lbry.tech/images.php"
}, (error, response, body) => {
if (error) reject(error);
body = JSON.parse(body);
resolve(body);
});
});
}).catch(uploadError => {
// component.isLoading = false;
// component.jsonData = JSON.stringify(uploadError, null, " ");
socket.send(JSON.stringify({
"details": "Image upload failed",
"message": "notification",
"type": "error"
}));
logSlackError("[daemon error]\n", "```" + JSON.stringify(uploadError) + "```");
return;
});
}
return new Promise((resolve, reject) => {
request({
url: "http://daemon.lbry.tech",
qs: body
}, (error, response, body) => {
if (error) {
reject(error);
logSlackError("[daemon error]\n", "```" + JSON.stringify(error) + "```");
return;
}
body = JSON.parse(body);
if (typeof body.error !== "undefined") {
reject(body.error);
logSlackError("[daemon error]\n", "```" + JSON.stringify(body.error) + "```");
return;
}
socket.send(JSON.stringify({
"html": html`
<p style="text-align: center;">Success! Here is the response for <strong>lbry://${claimAddress}</strong>:</p>
<pre><code class="json">${stringifyObject(body, { indent: " ", singleQuotes: false })}</code></pre>
<button class="__button-black" data-action="tour, step 2" type="button">Go to next step</button>
<script>$('#temp-loader').remove();</script>
`,
"message": "updated html",
"selector": "#step1-result"
}));
});
});
}
function generateGitHubFeed(displayGitHubFeed) {
if (typeof process.env.REDISCLOUD_URL !== "undefined") {
client.zrevrange("events", 0, 9, (err, reply) => {
@ -173,86 +290,22 @@ function generateGitHubFeed(displayGitHubFeed) {
}
}
function uploadImage(imageSource, callback) {
// return upload response
}
// TODO: Data parameter should include which step of tour is requesting metadata
function fetchMetadata(data, socket) {
if (data.step === 1 && !data.claim || !data.method) return;
const claimAddress = data.claim;
const resolveMethod = data.method;
const allowedClaims = [
"fortnite-top-stream-moments-nickatnyte",
"itsadisaster",
"six",
"unbubbled1-1"
];
const allowedMethods = [
"publish",
"resolve",
"wallet_send"
];
if (!allowedMethods.includes(resolveMethod)) return socket.send(JSON.stringify({
"details": "Unallowed resolve method for tutorial",
"message": "notification",
"type": "error"
}));
if (!allowedClaims.includes(claimAddress)) return socket.send(JSON.stringify({
"details": "Invalid claim ID for tutorial",
"message": "notification",
"type": "error"
}));
const body = {};
if (resolveMethod === "publish") {
body.bid = 0.001; // Hardcode the publish amount
// Fix the internal image path in daemon
// body.file_path = process.env.LBRY_DAEMON_IMAGES_PATH + body.file_path; // TODO: needed for step 2, check for `file_path`
}
body.access_token = process.env.LBRY_DAEMON_ACCESS_TOKEN;
body.method = resolveMethod;
body.uri = claimAddress;
function uploadImage(imageSource) {
return new Promise((resolve, reject) => {
request({
url: "http://daemon.lbry.tech",
qs: body
body: imageSource,
headers: {
"Content-Type": "text/plain"
},
method: "PUT",
qs: {
access_token: process.env.LBRY_DAEMON_ACCESS_TOKEN
},
url: "http://daemon.lbry.tech/images.php"
}, (error, response, body) => {
if (error) {
reject(error);
logSlackError("[daemon error]\n", "```" + JSON.stringify(error) + "```");
return;
}
if (error) reject(error);
body = JSON.parse(body);
if (typeof body.error !== "undefined") {
reject(body.error);
logSlackError("[daemon error]\n", "```" + JSON.stringify(body.error) + "```");
return;
}
socket.send(JSON.stringify({
"html": html`
<p style="text-align: center;">Success! Here is the response for <strong>lbry://${claimAddress}</strong>:</p>
<pre><code class="json">${stringifyObject(body, { indent: " ", singleQuotes: false })}</code></pre>
<button class="__button-black" data-action="tour, step 2" type="button">Go to next step</button>
<script>$('#temp-loader').remove();</script>
`,
"message": "updated html",
"selector": "#step1-result"
}));
resolve(body);
});
});
}

View file

@ -100,7 +100,6 @@ function fetchMetadata(stepNumber, data) {
- Style code with highlightjs
*/
console.log(typeof data);
if (!stepNumber) return;
switch(stepNumber) {
@ -128,7 +127,13 @@ function fetchMetadata(stepNumber, data) {
break;
case 2:
console.log(stepNumber, data);
send(JSON.stringify({
"data": data,
"message": "fetch metadata",
"method": "publish",
"step": stepNumber
}));
break;
default:
@ -136,21 +141,7 @@ function fetchMetadata(stepNumber, data) {
}
}
function getMemeInfo() {
/*
- description: component.description,
- file_path: uploadResponse.body.filename,
- language: component.language,
- license: component.license,
- name: component.title,
- nsfw: component.nsfw,
- title: component.title
// Set on back-end
- bid: 0.001,
- method: "publish"
*/
function getMemeInfo() { // TODO: Error handling
const info = {};
info.description = $("#meme-description").val();
@ -158,7 +149,7 @@ function getMemeInfo() {
info.language = $("#meme-language").val();
info.license = $("#meme-license").val();
info.name = $("#meme-title").val();
info.nsfw = $("#meme-nsfw-flag").val();
info.nsfw = $("#meme-nsfw-flag")[0].checked;
info.title = $("#meme-title").val();
return info;
@ -220,9 +211,3 @@ function updateCanvas(imageSource) {
ctx.fillText($("#meme-top-line").val().toUpperCase(), canvasWidth / 2, 20);
ctx.fillText($("#meme-bottom-line").val().toUpperCase(), canvasWidth / 2, (canvasHeight - 40));
}
send(JSON.stringify({ // TODO: Remove this
"message": "Landed on Tour"
}));