@@ -77,28 +77,44 @@ app.get('/generate/:data', async (req, res) => { // Because URL PARAMS ARE COOLE
7777 } )
7878} )
7979
80- app . get ( '/add-sha/:sha' , async ( req , res ) => {
81- const encoded = Base64 . encode ( 1 ) ;
82- await Axios . put ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
80+ app . get ( '/add-sha/:sha' , ( req , res ) => {
81+ const encoded = Base64 . encode ( 1 )
82+ Axios . put ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
8383 message : "Added a document" ,
8484 content : encoded
8585 } , {
8686 headers : { 'Authorization' : "token " + KEY }
87- } ) . then ( res => {
88- return res . json ( { message : "created" } )
87+ } ) . then ( result => {
88+ res . json ( { message : "created" } )
8989 } ) . catch ( e => {
90- return res . json ( { message : "exists" } )
90+ Axios . get ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
91+ headers : { 'Authorization' : "token " + KEY }
92+ } ) . then ( result => {
93+ const contentSHA = result . data . sha ;
94+ let visits = Base64 . decode ( result . data . content )
95+ let newVisit = Base64 . encode ( parseInt ( visits ) + 1 )
96+ Axios . put ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
97+ message : "UPDATED COUNT" ,
98+ sha : contentSHA ,
99+ content : newVisit
100+ } , { headers : { 'Authorization' : "token " + KEY } } ) . then ( done => {
101+ console . log ( done . data )
102+ res . json ( { visits : Base64 . decode ( newVisit ) } )
103+ } )
104+ . catch ( e => console . log ( e ) )
105+ } )
106+ . catch ( e => { console . log ( e ) } )
91107 } )
92108} )
93109
94110app . get ( "/get-count/:sha" , async ( req , res ) => {
95- const sha = req . params . sha ;
111+ const sha = req . params . sha
96112 await Axios . get ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + sha , {
97113 headers : { 'Authorization' : "token " + KEY }
98114 } ) . then ( res => {
99- console . log ( res )
115+ console . log ( Base64 . decode ( res . data . content ) )
100116 } ) . catch ( e => {
101- res . json ( { message : "ERRRR" } )
117+ res . status ( 400 ) . json ( { message : "ERRRR" } )
102118 } )
103119} )
104120
0 commit comments