@@ -109,41 +109,15 @@ app.get('/add-sha/:sha', (req, res) => {
109109app . get ( '/collect-sha/:sha' , ( req , res ) => {
110110 // const ip = req.headers['x-forwarded-for']
111111 const ip = "176.10.112.40" ;
112- Item . create ( { sha : req . params . sha , ip : ip } )
113- const encoded = Base64 . encode ( 1 )
114- Axios . put ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
115- message : "Added a document" ,
116- content : encoded
117- } , {
118- headers : { 'Authorization' : "token " + KEY }
119- } ) . then ( result => {
120- res . json ( { visits : 1 } )
121- } ) . catch ( e => {
122- Axios . get ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
123- headers : { 'Authorization' : "token " + KEY }
124- } ) . then ( result => {
125- const contentSHA = result . data . sha ;
126- let visits = Base64 . decode ( result . data . content )
127- let newVisit = Base64 . encode ( parseInt ( visits ) + 1 )
128- Axios . put ( "https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req . params . sha , {
129- message : "UPDATED COUNT" ,
130- sha : contentSHA ,
131- content : newVisit
132- } , { headers : { 'Authorization' : "token " + KEY } } ) . then ( done => {
133- res . json ( { visits : Base64 . decode ( newVisit ) } )
134- } )
135- . catch ( e => console . log ( e ) )
136- } )
137- . catch ( e => { console . log ( e ) } )
138- } )
112+ const item = await Item . create ( { sha : req . params . sha , ip : ip } )
113+ return res . json ( { item} )
139114} )
140115
141116app . get ( '/scan/:ip' , async ( req , res ) => {
142117 const ip = req . params . ip
143118 const items = await Item . findAll ( {
144119 where : { ip : ip }
145120 } )
146- console . log ( JSON . stringify ( items , null , 2 ) )
147121 return res . json ( { items} )
148122} )
149123
0 commit comments