webfast 0.1.54 → 0.1.56
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
|
|
1
|
+
module.exports = async function(program, url, body) {
|
2
|
+
console.log(`Fetch Post`);
|
3
|
+
// Register websocket url
|
4
|
+
try {
|
5
|
+
const headers = {
|
6
|
+
accept: 'application/json',
|
7
|
+
'content-type': 'application/json'
|
8
|
+
};
|
9
|
+
|
10
|
+
let theOptions = {
|
11
|
+
method: 'get',
|
12
|
+
headers: headers,
|
13
|
+
body: JSON.stringify(body),
|
14
|
+
};
|
15
|
+
|
16
|
+
// Using standard fetch function
|
17
|
+
const response = await fetch(url, theOptions);
|
18
|
+
// Get response body
|
19
|
+
const respBody = await response.json(); // Assuming the response is JSON
|
20
|
+
|
21
|
+
// Get response headers
|
22
|
+
const respHeaders = response.headers;
|
23
|
+
|
24
|
+
if (!response.ok) {
|
25
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
26
|
+
}
|
27
|
+
|
28
|
+
const responseData = respBody;
|
29
|
+
console.log('Response Data:', responseData);
|
30
|
+
|
31
|
+
// Return response data or true to indicate success
|
32
|
+
return responseData || true;
|
33
|
+
} catch (err) {
|
34
|
+
console.error('Error in post:', err.message);
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
};
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module.exports = async function(program, url, callback,ws,json) {
|
2
|
+
console.log(`Meta get`);
|
3
|
+
// Register websocket url
|
4
|
+
try {
|
5
|
+
await program.fetch.fetchUrl(url, {}, function(error, meta, body) {
|
6
|
+
if (error) {
|
7
|
+
console.error('Error fetching URL:', error);
|
8
|
+
} else {
|
9
|
+
console.log('Metadata:', meta);
|
10
|
+
const bodyString = body.toString('utf8'); // Convert buffer to string
|
11
|
+
console.log('Body data:', bodyString);
|
12
|
+
const metaRegex = /<meta[^>]*>/gi;
|
13
|
+
const metaTags = bodyString.match(metaRegex);
|
14
|
+
|
15
|
+
const metaObjects = metaTags.reduce((result, tag) => {
|
16
|
+
const matches = tag.match(/(name|property)\s*=\s*"([^"]*)"\s*content\s*=\s*"([^"]*)"/i);
|
17
|
+
if (matches && matches.length === 4) {
|
18
|
+
const property = matches[2];
|
19
|
+
const content = matches[3];
|
20
|
+
result[property] = content;
|
21
|
+
}
|
22
|
+
return result;
|
23
|
+
}, {});
|
24
|
+
|
25
|
+
//console.log(metaObjects);
|
26
|
+
|
27
|
+
let metas = {}
|
28
|
+
const metaSend = [`og:title`,`og:description`,`og:image`,`al:ios:url`,`al:android:url`]
|
29
|
+
// Create object loop
|
30
|
+
function decodeHtmlEntities(str) {
|
31
|
+
return str.replace(/&#(\d+);/g, function(match, dec) {
|
32
|
+
return String.fromCharCode(dec);
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
const filteredMetaObjects = Object.keys(metaObjects).reduce((result, key) => {
|
37
|
+
if (metaSend.includes(key)) {
|
38
|
+
result[key] = decodeHtmlEntities(metaObjects[key]);
|
39
|
+
}
|
40
|
+
return result;
|
41
|
+
}, {});
|
42
|
+
|
43
|
+
metas = filteredMetaObjects;
|
44
|
+
console.log(`Metas`,metas);
|
45
|
+
|
46
|
+
if (callback != undefined) {
|
47
|
+
return callback(metas,ws,json);
|
48
|
+
} else {
|
49
|
+
return bodyString;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
});
|
53
|
+
} catch (err) {
|
54
|
+
console.error('Error in post:', err.message);
|
55
|
+
return false;
|
56
|
+
}
|
57
|
+
};
|