deshortify
Advanced tools
Comparing version 0.1.0 to 0.1.1
# v0.1.1 (2017-05-12) | ||
* Bugfix for race conditions: Cache the unresolved promises too | ||
* Bugfix for infinite loops: Actually carry breadcrumbs around | ||
* Bugfix for weird URLs: Assume duplicated URL query params are invalid and are to be removed | ||
# v0.1.0 (2017-05-12) | ||
@@ -3,0 +9,0 @@ |
{ | ||
"name": "deshortify", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Turns short URLs into long, meaningful, crap-less URLs.", | ||
@@ -8,3 +8,9 @@ "main": "src/deshortify.js", | ||
"license": "Beerware", | ||
"repository": "https://IvanSanchez@gitlab.com/IvanSanchez/deshortify.git" | ||
"repository": "https://IvanSanchez@gitlab.com/IvanSanchez/deshortify.git", | ||
"keywords": [ | ||
"shorturl", | ||
"url", | ||
"unshort", | ||
"shortlink" | ||
] | ||
} |
@@ -12,3 +12,3 @@ # Deshortify | ||
Because the existing de-shortening libraries for NodeJS are lacking. | ||
Because I feel that the existing de-shortening libraries for NodeJS (like [unshort](https://www.npmjs.com/package/unshort), or [url-unshort](https://www.npmjs.com/package/url-unshort)) are lacking. | ||
@@ -19,3 +19,3 @@ | ||
For example, it will turn `http://bit.ly/2qzPrcN` into `http://www.liberation.fr/direct/element/une-elue-du-personnel-de-whirlpool-candidate-suppleante-pour-en-marche_63786/?utm_campaign=Echobox&utm_medium=Social&utm_source=Twitter#link_time=1494593774`, and then into `http://www.liberation.fr/direct/element/une-elue-du-personnel-de-whirlpool-candidate-suppleante-pour-en-marche_63786/#link_time=1494593774`. | ||
For example, it will turn `http://bit.ly/2qzPrcN` into `http://www.liberation.fr/direct/element/une-elue-du-personnel-de-whirlpool-candidate-suppleante-pour-en-marche_63786/?utm_campaign=Echobox&utm_medium=Social&utm_source=Twitter#link_time=1494593774`, **and then** into `http://www.liberation.fr/direct/element/une-elue-du-personnel-de-whirlpool-candidate-suppleante-pour-en-marche_63786/#link_time=1494593774`. | ||
@@ -22,0 +22,0 @@ Deshortify will keep a cache of resolved URLs, so that known ones are not re-requested on the network. |
@@ -47,3 +47,11 @@ | ||
if (url in this._cache) { | ||
if (this._cache['url'] === url) { | ||
let cachedUrl = this._cache[url]; | ||
// Several requests for the same URL might happen before any of them resolves. If that's the case, just | ||
// return the promise already created. | ||
if (cachedUrl instanceof Promise) { return cachedUrl; } | ||
if (cachedUrl === url) { | ||
return Promise.resolve(this._cleanUp(url)); | ||
@@ -53,5 +61,5 @@ } | ||
if (this._verbose) { | ||
console.log('cached follow: ', url, ' → ', this._cache[url]); | ||
console.log('cached follow: ', url, ' → ', cachedUrl, ' (breadcrumbs lenght is ', breadcrumbs.length, ')'); | ||
} | ||
return this._deshortify(this._cache[url]); | ||
return this._deshortify(cachedUrl, breadcrumbs); | ||
} | ||
@@ -74,3 +82,3 @@ | ||
// Handle header-based redirects | ||
return new Promise((resolve, reject)=>{ | ||
return this._cache[url] = new Promise((resolve, reject)=>{ | ||
@@ -100,3 +108,3 @@ let backend = | ||
this._cache[url] = newUrl; | ||
return resolve(this.deshortify(newUrl)); | ||
return resolve(this._deshortify(newUrl, breadcrumbs)); | ||
} | ||
@@ -132,2 +140,3 @@ | ||
if (params) { | ||
// console.log(url); | ||
params.forEach((name)=>{ | ||
@@ -141,2 +150,3 @@ let val = parsedUrl.query[name]; | ||
if ( | ||
(typeof val !== 'string') || // e.g. http://www.businessinsider.com/...&r=US&IR=T&IR=T | ||
(name.match(/_source$/)) || | ||
@@ -216,2 +226,3 @@ (name.match(/_medium$/)) || | ||
let parsedUrl = parseUrl(url, true); | ||
let host = parsedUrl.host; | ||
@@ -218,0 +229,0 @@ |
@@ -10,4 +10,10 @@ | ||
// deshortifier.deshortify('http://di.gg/1Xp1Sx6').then(u=>console.log('Final URL is ' + u)); | ||
deshortifier.deshortify('https://t.co/p0N0Zl8rx6').then(u=>console.log('Final URL is ' + u)); | ||
// deshortifier.deshortify('https://t.co/p0N0Zl8rx6').then(u=>console.log('Final URL is ' + u)); | ||
// deshortifier.deshortify('https://t.co/uLcQFpE45F').then(u=>console.log('Final URL is ' + u)); | ||
deshortifier.deshortify('http://yfrog.com/od667vyj').then(u=>console.log('Final URL is ' + u)); | ||
11302
205