Steemauto - backend improvement

in utopian-io •  6 months ago





As you know, Steemauto is written by PHP and it is hard to add more features to it!
I want to re-code Steemauto with Javascript (backend) and Angular 6 (frontend)
After re-coding Steemauto with Javascript, anyone will be able to contribute more features! Working with Javascript is easier in the Steemauto!

The backend is almost done!


There were some problems (and bugs) in the backend API (this backend is not live in the production) and I just fixed all of that problems.
After developing the backend, I should test my development with Steemauto! So, I re-coded functions of curation_trail, fanbase, and schedule_post to use in the development tests then use in the production.

Also, in the coming updates, because of so many problems with steemconnect, I will change the login method in the Steemauto!
Users still will log in by steemconnect, but we will check the login information every 7 days (and not on every site refresh which causes high load on the steemconnect and sometimes requires users to login multiple times!).



In the MySQL SELECT EXISTS() queries, MySQL will return something like: [{someLongQuery: result(1 or 0)}]
We should select the result from that array then object:

let exists = await con.query(
  'SELECT EXISTS(SELECT `follower` FROM `fanbase` WHERE `fan`=? AND `follower`=?)',
  [fan, username]
for (let i in exists[0]) {
  exists = exists[0][i]

Received numbers from the post requests are in the string format ( '1212' not 1212)
I converted these variables from string to the number by Javascript Number() method:

weight = Number(weight)
minute = Number(minute)
enable = Number(enable)

I used to send tags of posts to the API with an array which is converted to the string by JSON.stringify()
We should convert received array-string in the server side to an array by using JSON.parse()

const tags = JSON.parse(req.body.tags)


We created a main function for making post calls to the backend API and displaying result or error with notifications and reloading website.
(Since Steemauto is written by PHP, we should reload website to see changes in all variables)

function callApi(url, body){
    const xmlhttp = new XMLHttpRequest()
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            if (JSON.parse(this.responseText).id == 1) {
                    icon: 'pe-7s-check',
                    message: JSON.parse(this.responseText).result
                    type: 'success',
                    timer: 8000
            } else {
                    icon: 'pe-7s-attention',
                    message: JSON.parse(this.responseText).error
                    type: 'danger',
                    timer: 8000
    }"POST", url, true)
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

    return 1

Other functions now are simpler and some of them are even 1-2 lines!
Some examples:
Follow function:

function follow(user){ //follow a trail
    callApi('api/v1/dashboard/curation_trail/follow', 'trail=' + encodeURIComponent(user))
    return 1

And unfollow function:

function unfollow(user){ //unfollow a trail
    callApi('api/v1/dashboard/curation_trail/unfollow', 'trail=' + encodeURIComponent(user))
    return 1

Also, I explained enough in the commit messages or inside codes if there was anything hard to understand.

Please continue supporting Steemauto
Thanks for your great support:)

This post is submitted to the


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for your contribution.

Not sure what you meant by this, are you updating the code in the main site and then selecting few parts and then updating it?

"We will use mahdiyari/steemauto-backend in curation_trail, fanbase, and schedule_posts
After finishing development of all sections in the mahdiyari/steemauto-backend (comment_upvote and claim_reward), I will remove all methods from /dash.php"

  • +1 for using let and const instead of var.
  • You can try using .map instead of for here

One more thing I have seen is that you are using the similar code in the number of files, can they be created as a function in a util class and then called it individually.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.

Need help? Write a ticket on
Chat with us on Discord.


Let me explain
I just finished development of curation_trail, fanbase, and schedule_post in the mahdiyari/steemauto-backend
So, I just updated the code which was related to this parts in the main repository (mahdiyari/steemauto)
That similar codes are the old codes. I'm just re-coding steemauto (and I will fix that codes in the coming updates).
Also, I think using map is not possible in that case

// mysql will return this result
const result = [{'SELECT EXISTS(SELECT `test` FROM `posts`)': 1}] => console.log(res)) // {SELECT EXISTS(SELECT `test` FROM `posts`): 1}
result[0].map(res => console.log(res)) // Uncaught TypeError: result[0].map is not a function

Thanks for your review


Thank you for your review, @codingdefined!

So far this week you've reviewed 9 contributions. Keep up the good work!

I recently signed up on website and am amazed! How come I didn't took @surpassinggoogle's advice to use this website instead of steemvoter?! This website is more efficient. I could have saved a lot of time, manually working with my votes on steemvoter with 328 accounts where I paid for a full year of service January this year! Now I don't know how long it's going to take me to input those accounts to steemauto. Am so upset I want to cry!!

Voted you as a witness and following you now. Will share this with my friends. Thank you for the wonderful work!


much appreciated
I will try to make an option to travel easier from steemvoter to steemauto


Omg! That would be great! I'll keep an eye on new updates. Thanks a lot.

More power to you!

Despite tiny, here my full upvote for you @mahdiyari .
Keep supporting all the steemians around.

Very useful product - looking forward to future feature additions.

Host of Here Comes The News on MSP Waves Radio.

Host of The Alternative Lifestyle Show on MSP Waves Radio.

Founder of the A Dollar A Day charitable giving project.

Thanks for your effort and love, @mahdiyari! <3

A big hug from @amico!

Hi @mahdiyari!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

I have a question?

Can I pay you steem to create and run a bot for me


Sorry, I'm busy


Thanks anyway

@mahdiyari thanks for shearing with us, you are doing a great job

Hey, @mahdiyari!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support!
Simply set as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord

Vote for Utopian Witness!

Excellent article!