forked from Laboratoria/bog001-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
35 lines (32 loc) · 1020 Bytes
/
validate.js
File metadata and controls
35 lines (32 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const axios = require('axios');
//valido mis links con su status
const validateLink = (listaLinks) => {
let analiticsLinks = listaLinks.map((nuevoObjeto) =>{
return axios.get(nuevoObjeto.href)
.then((res) =>{
if(res.status = 200){
let creandoObjeto = {};
creandoObjeto.href = nuevoObjeto.href;
creandoObjeto.text = nuevoObjeto.text;
creandoObjeto.file = nuevoObjeto.file;
creandoObjeto.status = res.status;
creandoObjeto.validate = 'ok';
return creandoObjeto
}
}).catch((err) => {
if(err.status = 404){
let creandoObjeto = {};
creandoObjeto.href = nuevoObjeto.href;
creandoObjeto.text = nuevoObjeto.text;
creandoObjeto.file = nuevoObjeto.file;
creandoObjeto.status = err.status;
creandoObjeto.validate = 'fail';
return creandoObjeto
}
})
})
return Promise.all(analiticsLinks).then(results => {
return results
})
};
module.exports = validateLink