react-native-link-preview
Advanced tools
Comparing version 1.3.5 to 1.3.6
34
index.js
@@ -7,3 +7,2 @@ /** | ||
const urlObj = require('url'); | ||
const fetch = require('cross-fetch').fetch; | ||
require('es6-promise').polyfill(); | ||
@@ -30,9 +29,14 @@ | ||
if (detectedUrl) { | ||
fetch(detectedUrl) | ||
.then(function(response) { | ||
var request = new XMLHttpRequest(); | ||
request.onreadystatechange = (e) => { | ||
if (request.readyState !== 4) { | ||
return; | ||
} | ||
if (request.status === 200) { | ||
// get final URL (after any redirects) | ||
const finalUrl = response.url; | ||
const finalUrl = request.responseURL; | ||
// get content type of response | ||
var contentType = findById(response.headers, 'content-type'); | ||
let contentType = findById(request.responseHeaders, 'content-type'); | ||
if (!contentType) { | ||
@@ -52,8 +56,5 @@ return reject({ error: 'React-Native-Link-Preview: Could not extract content type for URL.' }); | ||
resolve(parseVideoResponse(finalUrl, contentType)); | ||
} else if (contentType && CONSTANTS.REGEX_CONTENT_TYPE_TEXT.test(contentType)) { | ||
response.text() | ||
.then(function(text) { | ||
resolve(parseTextResponse(text, finalUrl, options || {}, contentType)); | ||
}); | ||
} else if (contentType && CONSTANTS.REGEX_CONTENT_TYPE_APPLICATION.test(contentType)) { | ||
} else if (contentType && REGEX_CONTENT_TYPE_TEXT.test(contentType)) { | ||
resolve(parseTextResponse(request._response, finalUrl, options || {}, contentType)); | ||
} else if (contentType && REGEX_CONTENT_TYPE_APPLICATION.test(contentType)) { | ||
resolve(parseApplicationResponse(finalUrl, contentType)); | ||
@@ -63,4 +64,11 @@ } else { | ||
} | ||
}) | ||
.catch(function(error) { reject({ error: error }) }); | ||
} else { | ||
reject({ | ||
error: 'React-Native-Link-Preview: Could not fetch provided link' | ||
}) | ||
} | ||
}; | ||
request.open('GET', detectedUrl); | ||
request.send(); | ||
} else { | ||
@@ -67,0 +75,0 @@ reject({ |
{ | ||
"name": "react-native-link-preview", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"keywords": [ | ||
"react-native" | ||
"react-native", "javascript", "link", "url" | ||
], | ||
@@ -19,3 +19,2 @@ "author": "Oscar Franco", | ||
"cheerio-without-node-native": "^0.20.1", | ||
"cross-fetch": "0.0.8", | ||
"es6-promise": "^4.2.4", | ||
@@ -22,0 +21,0 @@ "url": "^0.11.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
144061
3
426
0
- Removedcross-fetch@0.0.8
- Removedcross-fetch@0.0.8(transitive)
- Removedencoding@0.1.13(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedwhatwg-fetch@2.0.3(transitive)