forked from Laboratoria/bog001-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateLinks.js
More file actions
53 lines (46 loc) · 1.73 KB
/
validateLinks.js
File metadata and controls
53 lines (46 loc) · 1.73 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const fs = require('fs');
const path = require('path');
let MarkdownIt = require('markdown-it');
const fsPromises = require('fs').promises;
const axios = require('axios').default;
// Validar los links
function validateLinks(acaVaPrueba) {
let arrayValidados = acaVaPrueba.map((objeto) => {
return axios.get(objeto.Url)
.then(
function (response) {
if (response.status = 200) {
let newArray = new Object();
newArray.Url = objeto.Url;
newArray.text = objeto.text;
newArray.file = objeto.file;
newArray.status = response.status;
newArray.okfail = 'ok';
return newArray
}
else {
let newArray = new Object();
newArray.Url = objeto.Url;
newArray.text = objeto.text;
newArray.file = objeto.file;
newArray.status = response.status;
newArray.okfail = 'fail'
return newArray
}
})
.catch(function (error) {
let newArray = new Object();
newArray.Url = objeto.Url;
newArray.text = objeto.text;
newArray.file = objeto.file;
newArray.status = 503;
newArray.okfail = 'fail'
return newArray
//console.log(error.message)
})
})
return Promise.all(arrayValidados)
}
module.exports = validateLinks