Steemauto - backend improvement
utopian-io·@mahdiyari·
0.000 HBDSteemauto - backend improvement
<center></center> GitHub1: https://github.com/mahdiyari/steemauto-backend PR: https://github.com/mahdiyari/steemauto-backend/pull/4 GitHub2: https://github.com/mahdiyari/steemauto PR: https://github.com/mahdiyari/steemauto/pull/32 *** #### Explanation: 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! *** #### Changes: 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! <b>Users still will log in by steemconnect</b>, 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!). *** #### Development: #### mahdiyari/steemauto-backend: 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) ... ``` *** #### mahdiyari/steemauto: 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){ $('.btn').attr('disabled','true') const xmlhttp = new XMLHttpRequest() xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (JSON.parse(this.responseText).id == 1) { $.notify({ icon: 'pe-7s-check', message: JSON.parse(this.responseText).result },{ type: 'success', timer: 8000 }) location.reload() } else { $.notify({ icon: 'pe-7s-attention', message: JSON.parse(this.responseText).error },{ type: 'danger', timer: 8000 }) $('.btn').removeAttr('disabled') } } } xmlhttp.open("POST", url, true) xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded") xmlhttp.send(body) 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 https://utopian.io Regards, 2018-09-10
👍 defango, khalilalfamahera, ardian27, makrotheblack, gambit.coin, siyulaters, endee, yudiana, shakailove, safwan10000, jamesmovic, andrelion, mrxplicit, ghevangelist, flozockt, cy23, kim24, befaro, iamjimmy, essteem, steemvests, ekkah, fajarharapan, laboh, silentpartnerio, gangplankhg, foodtaster, anam01, esteem77, good-korma, terry00, walidchabir, jhiecortez, handfree42, sundararaj, fuhreresu, paulo380, rodonlegend, justinzidi3, leyla5, bit6in, ibook-ishare, ita-soa, freemon, virgo27, bhim, belemo, annassatu, hendraman, apartphilosopher, marianadagraca, bdkazi, luckykar, syahhiran, achmadyani, miaplexuscaleb, detromix87, bgmuna, rositasilvia, jpgalih, steem100, supersteemian, raju1, crystalhuman, joanpablo, akram7, tanisha786, ilhampratama, advsamadhan, dennis041713, bangkarnen, polashsen, greenville, emongnovaostia, tysir, foysalahmmed, edundayo, not-a-gamer, ismailrafael, gakimov, ernoldlvb, khalilputra, mayib, calisthenox, dayosoyinka, war-tp, sirmiraculous, faisal003, hakan1988, steem.moon, susyoke, gurujames, oniraphaeleu, ocn, marcozina, obiobi, steem-oon, soyarcoiris, sshowoff, cryptocrib, hamzatuliqbal, dheaulvani, dekna.steem, caristeem, linuxsteem, ira-steem, tutorial.steem, choobymaverick, chukwuebuka, radhitmeldita, abiq, irawatismk, iqbalteampoison, vinakim, baixiian, jinxizhen, mishamardiah, wardatulaini, hafidhiati92, mangaku, steepshoot, phanton, kok.bisa, steemja, ijar85, niena, hasnawati, ardaar, mrs.riyah28, regina80, gozben24, heery, ramadhany, sportlife, rmaulana, bundaniena, hera-b, supremacy126, ebakuglobal, frimpz, ablink, pemburucinta, galaksteem, zulhamtrc, raidal01, tissuesurgeon, kwabeedat, ashmodz, samcofy, ikkelins, rucy, toroo, jazzyon, collinstochukwu, kelvinikke, korkorjkk15, sugarpie, korkorjkk, alqudsid, praserr, stone1010, loversteem, advisor77, mustika, macmaniac77, kwabena1995, fayamba, giddensk7, nanaboateng, steemramos, dacosta, tutchpa, fredrick4u, caxton, aabhi, rosemary4u, aaakosuahumble, eddymania, aaaaaa-aaaaaakay, sarahhhh, christinebeauty, zhangyuze, sparkling1, jcmansah, cuthamza, baroen96, precioussteem, nurily, cryptomythic, abhay.singh, anask559, dreamseller, sagors, tomit, iamindian, raveq, cambridgeport90, cynthyel24, mrogy1, sgbonus, mdsohagm24, umut1905, tuumar, jayb435, raghib, yazannew, mahdiyari, arzy, steeming-ali, czechman, kathegarcia97, mathias240, aejackson, akpos, gangplankhq, sulwati, spoke, peak.endrule, ambika138, blockchaincat, santinhos, zanoni, wealth4good, wakeupnd, luciancovaci, steinz, yuxi, bosjaya, adiona, kumpaiy, steemobserver, foxesal, luigi-tecnologo, benleemusic, botje11, brumest, jejangkit, lamborin, ubahal, bim-bim, tesselart, sitiaishah, dedeleyman, jayboss, patlu, abbyrich, tm50, commenthunter, alvinvoo, armguinan, estourefugiado, talentclub, dresden, alexisvalera, elias15g, assus, dresden1, dresden2, dresden3, marieta88, serlanvet, torkot, oscarps, humoalex, siucatti, clacrax, oscarcc89, fahri, katiuskagomez, galberto, juancar347, introspectiva, rnunez09, armonia, decomoescribir, aleli, ficciones, simnrodrguez, neiraurdaneta, stefanycaldera, dojeda, marpa, kristal24, abnerpantoja, psicomar, valentinagrv, poetarojo, drmaizo, zenkly, bourrbakia, darius86, yimiipsa, elinderzambrano, gusvzla, risckylu, kaizag, zullyscott, dragonflyarrow, miguelfiguera, cesinfenianos, critic-on, mrstrange, moises-moran, gabrielamosqueda, doctortrillo, mariu.espinoza, poesiaempirica, joseacabrerav, salvao, iaberius, wilins, adncabrera, nahupuku, johannfrare, chejonte, rjguerra, zeleiracordero, yosuandoni, marlyncabrera, arcoiris, reyvaj, pushpo, baancap, baandak, baanggal, galaiy67, inr, nature.indonesia, razpor, dream77124, coindzs, csmedia, unalion, crescendoofpeace, nurhasib, garudas, bold42, drakbirkenau, caacupe, fqc, vitkolesnik, d3nv3r, oliverstoney, sextant, taskmanager, prizeportal, ijoel, torico, boyasyie, freerolll, awilix, onelovedtube, blem, zapped, instantvoter, jedimasteryoda, hibernated, hadimemories, kenanqhd, alfajri78, veganroma, jeffandhisguitar, yusmi, rachmaddarmawan, alexabsolute, fireguardian, happymichael, penjahit, digitokash, scottshots, jeffmcmullen, josevallera, darkfuseion, gisi, illuminationst8, ulqu3, vegan4theanimals, techcoderx, brettblue, travellit, nuttapon, romafedorov, mata.lensa, zainenn, inoobgamer, onelove.curation, jrswab, valorforfreedom, spite77, fabian98, cartel, andrespire, mrchef111, bobaphet, adam-aj, melor9, chatwithkat, necroth, onelovecuration, ejgarcia, green07, toofasteddie, hornet-on-tour, sol25, fenola, samaz0r, shanibeer, humanearl, aqli, alphasteem, jeronimorubio, dipoabasch, bibakipcikcam, gooze, samathist, bargolis, reekadoh, trumanity, oneazania, blockgators, moscato, bco, mzuami, ladybirdec, krissy330, chillingotter, amosbastian, teevmoore, big-m, blockgatorsarmy, world-travel-pro, molamola, leguidecrypto, ian19, linguist, nonsqtr, herdi.steemit, molang, ibrasteem, coquiunlimited, bryanj4, theleapingkoala, artax89, kenjidois, lynbabe10, agoha, marcost4, srl-zone, maaz23, silasvogt, teachblogger, haiyangdeperci, felixgarciap, asrizalmustafa, otrip, filmmasochist, gabo.trip, jraysteem, veenang, leverager, hoscker, dlife, phototutorials, altcoinpost, vibelita, elohim4, rasyib, fuzzythumb, bolsfit, princeso, polbot, neeqi, neopatriarch, toddmck, amayahaley21, amymya, crowbarmama, exzorltg, dnews, rogeviolinista, brainpod, pennsif, daeshawn, adventuroussoul, theaudgirl, presidentialline, gwbush, shermanedwards, gwashington, camuel, dsongs, gasparcha, openmind3000, masaitv, carlos-cabeza, joythewanderer, pechichemena, steemtogether, mauriciovite, jduarte, vickaboleyn, pepiflowers, jbrrd, enjoyinglife, graylan, iwanderela, cordeta, scottychams, vincy, bitpizza, osobiggie, vishal007, cryptobols, susantabinod, giosou, greenorange, jonyoudyer, coretan.aksara, steemitqa, holovision, slobberchops, playbox, sheikhsalman, holger80, askari, moneymantra, doughtaker, ultraspace, payelmia, noorsamad, btctop1, glastar, uday20, violetmed, ishan89, krevasilis, berlidaki, abhibroo, ashiknirob, thethreehugs, pankajmaurya, sagheer46, logan9852, bakry, ajaycrypto18, revan746, fractal-team, hirokaushik007, transcript-junky, vasilisapor2, pankajraghav, shyamydv, rashidul10, cryptowarrior88, mixedmentalarts, bitcoinsandgravy, graphyhunt, amico, cryptossi, atimk23, rndness222, lemouth, lesmouths-travel, bitland, drsensor, mdabu, codingdefined, d-pend, jimberttagnepis, fastraveller, steem-ua, mim90, wide, haji, kiaazad, grosslead, spsoofbaf, exif, aoe, marketclob, masoudgh69, wicca, ehsan888, farda, farhadchef, hakimomarkhayyam, saharkhanommi, curves, raha, panahi1353, hosseinrezaei, faked, pouriap2, cafecrypto, paymanmahabad, amiralimahdvi, shahgol, subha193, nituanuj786, iauns, sanks7, asifbeg000, rktechraj, kuldeeprandhawa, alirezaap, jahid1234, mithilsood, taliakerch, binhlinh, emergehealthier, princebrahma, jjaman, sushant769, kuberman, vander, huyngo3008, risingstars, ramnarayan, technos, huma.mirza, asifmirza02, maglerky, gank, jamespradhan, getfreeupvotes, oumfoundation, hunny100dev, fuadfahim, orakzai, shakilebox, podinatutorials, mrshubh, rajrajput, balcon07, tanmoybose, xuhi, firesteem, mdshide, premsan, axellhail, balu1008, usama123, yorsezapata, zemex, khanwriting, niyamulhasanpdc, zafarishafiq, jainlove, memeholic, biomanu, techlife, stevecronin, svetlanaaa, inderjot, candyshop, pranavsood, farukcom, gauravrawat, richboy, rahularyan, srt, cryptojb, dhanu1998, r7trader, grintsch, sandy666, traderr, tech9uru, waliulislam, bitlady, siyaa, bitmycoin, uccakash, sureshnsnet, dotfee, jerry123, jatindembla, primetimewithjd, bradfordtennyson, amorjyoti, lopamudra, jainachwani, kabasakal, rksagar, steemersayu907, superpowerful, sanju007, rayhankabirs, healthgym, censorshipsweden, mitul214, diegor, utopian-io, plumberr, vayalomenor, khankamran, rkrebel73235, laiya, eshan37, kkay05, ziarat, steemit-bank, gkumar, as-abir, arafatsaikatcse, anikas, paigegirl, thecure, bebeth, dcardozo25, luisanahernandez, beanz, zohaib47, mazhar78, francislorong, niteshbaniya, daan, nurulafsar03, eccles, sst,