Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Create upvote_server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdiyari committed Jan 29, 2018
1 parent d61c1ac commit 9ae0600
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions nodejs/upvote_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const steem = require("steem");
const http = require('http');
var url = require('url');
const hostname = '0.0.0.0';
const port = 123;//port

steem.api.setOptions({ url: 'ws://127.0.0.1:8090' }); //Local private node

const server = http.createServer((req, res) => {
var params = url.parse(req.url,true).query;
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');

var wif = params.wif;
var voter = params.voter;
var author = params.author;
var permlink = params.permlink;
var weight = parseInt(params.weight);
if(wif && voter && author && permlink && weight){
steem.api.getContentAsync(author, permlink, function(erz, rez) { //checking if post already upvoted or not
if(!erz && rez){
var voted = 0;
for(j in rez['active_votes']){
if(rez['active_votes'][j].voter == voter){
voted = 1;
break;
}
}
if(voted == 0){
steem.broadcast.vote(wif,voter,author,permlink,weight,function(downerr, result){ //broadcasting upvote
if(!downerr && result){
res.end('1');
}else{
res.end('0');
}
});
}else{
res.end('0');
}
}else{
res.end('0');
}

});

}
});

server.listen(port, hostname, () => { //running server
console.log(`Server running at http://${hostname}:${port}/`);
});

0 comments on commit 9ae0600

Please sign in to comment.