Coder Social home page Coder Social logo

lmammino / tall Goto Github PK

View Code? Open in Web Editor NEW
69.0 4.0 7.0 611 KB

Promise-based, No-dependency URL unshortner (expander) module for Node.js

Home Page: https://lmammino.github.io/tall/

License: MIT License

JavaScript 41.92% TypeScript 58.08%
url url-shortener url-parsing url-unshorten url-expand nodejs node library module no-dependencies

tall's People

Contributors

aheissenberger avatar cawa-93 avatar fiveboroughs avatar gusruss89 avatar karlhorky avatar leftshift avatar lmammino avatar polilluminato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tall's Issues

Array of urls not able to resolved

Hi,

As investigating while trying to get this work with array of urls => does not work?
If there is a away to do it, write it down?

Simple as but not able to get it work.

Youtube links not resolved in v3.0.0

Hey there,

I tried upgrading from v2 to v3 and youtube links are not resolved anymore. You may try this example I took from the README:

import { tall } from 'tall';

async function someFunction() {
  try {
    const LINK = 'https://youtu.be/TCB_RSlgTqY';
    const unshortenedUrl = await tall(LINK, {
      maxRedirect: 10
    });
    console.log('Tall url', unshortenedUrl);
  } catch (error) {
    console.error('AAAW ๐Ÿ‘ป', error);
  }
}

someFunction();

Am I doing something wrong?

Thanks in advance,

Not throwing exception on "Error: getaddrinfo ENOTFOUND"

When using tall() inside a try/catch block, the following kind of error isn't thrown and catchable, but instead, the node process exits with:

Error: getaddrinfo ENOTFOUND XXXXXX XXXXXX
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)

Improve compatibility with more default headers?

Hey @lmammino ๐Ÿ‘‹ hope things are going well!

In our experience with using tall against a large number of domains, some domains will refuse to send back a response without a certain set of headers.

Some of these headers could be set automatically by tall as default options to improve out-of-the-box compatibility (there are libraries to keep up to date with latest Accepts and User-Agents values):

const accepts = [
  // Chrome 112
  'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
  // Firefox 113
  'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
];

const userAgents = [
  // Chrome 112
  'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36',
  // Firefox 113
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0'
]

tall(url, {
  headers: {
    'Accept-Encoding': 'gzip, deflate, br',
    Connection: 'keep-alive',
    Accept: accepts[Math.floor(Math.random() * (accepts.length - 1))],
    'User-Agent':
      userAgents[Math.floor(Math.random() * (userAgents.length - 1))],
  },
});

What do you think about setting these as default headers options?

TypeError: The "listener" argument must be of type Function. Received type object

I can't seem to get this to work. I have installed the package, and I am running nextjs.

Here is my code:

import { tall } from 'tall';
var airbnblink = 'https://abnb.me/YEO24YyMisb';
tall(airbnblink).then(function(response) {
console.log(response);
})
.catch(function(err) {
console.log(err);
})

But I can't get this to run - console keeps saying:
TypeError: The "listener" argument must be of type Function. Received type object

Any ideas why?

TypeError: tall is not a function

When using tall, I get the error mentioned in the title. I'm using Firebase to run my code.

Here's my package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^9.2.0",
    "firebase-functions": "^3.11.0",
    "needle": "^2.6.0",
    "tall": "^4.0.1",
    "twilio": "^3.62.0"
  },
  "devDependencies": {
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

Here's my code:

const tall = require("tall");

...

async function unshortenLink(link) {
  var fullLink = null;
  try {
    fullLink = await tall(link);
  } catch (err) {
    console.log("Error: tall did not unshorten link. Link: ", link);
    console.log("Error: tall did not unshorten link: ", err);
  }
  return fullLink;
}

Any help would be appreciated.

Certificate verification error

Hi @lmammino ! ๐Ÿ‘‹

It seems like running tall on the https://eyeondesign.aiga.org/the-era-of-nonchalant-web-design-is-here/ website on a deployed Ubuntu environment fails with a certificate validation error.

const {tall} = require('tall')
tall('https://eyeondesign.aiga.org/the-era-of-nonchalant-web-design-is-here/')

> Uncaught Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
    at TLSSocket.emit (node:events:390:28)
    at TLSSocket.emit (node:domain:537:15)
    at TLSSocket._finishInit (node:_tls_wrap:944:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12)
    at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'

The certificate for the website is valid in the browser:

Screen Shot 2022-05-30 at 12 32 52

Following the advice from Stack Overflow I tried installing [email protected] to install the root CAs, but this did not change anything for tall... ๐Ÿค”

Similar to #5

Tiktok links not resolving?

Hey, just using this package to resolve TikTok links and it appears that tall is not working for those links

Handling ENOTFOUND

Hello,

I know this was supposedly handled in #12 but I have2.2.0 installed (the one with this PR) and it seems to still fail when fed a shortened URL pointing to an invalid URL. I'd like to know if it's me handling this poorly somehow or if the bug is still present.

How to reproduce:

  • Get on twitter or bit.ly, and ask to shorten to an invalid URL like z.chat
  • Feed the shortened url to tall: tall("https://t.co/FqLTQ7TRYS")
  • The promise doesn't reject anything, instead the node process stops with error:
Error: getaddrinfo ENOTFOUND z.chat z.chat:80
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:58:26)
Emitted 'error' event at:
    at Socket.socketErrorListener (_http_client.js:397:9)
    at Socket.emit (events.js:193:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:17)

Am I missing something, am I handling the promise rejection wrong?

  const promises = urls.map((shortUrl, idx) =>
    tall(shortUrl).then(longUrl => ({
      shortUrl,
      longUrl,
      idx
    }))
  );

  Promise.all(promises)
    .then(results => {
        // Handle success
    })
    .catch(e => {
      // THIS NEVER GETS CALLED
      log("The elusive buggerino!");
      log(`Total message: ${text}`);
      log(`URL we tried shortening: ${shortUrl}`);
      log(e);
    });

Thanks for your time

Support following <meta http-equiv="refresh" /> ?

Hi @lmammino ๐Ÿ‘‹

First of all, thanks so much for creating and maintaining this module, super simple and works!

What are your thoughts on supporting unshortening the <meta http-equiv="refresh" /> redirects that pages can return in the response body?

For example, the html below would instantly redirect to https://example.com/abc/:

<html>
  <head>
    <meta http-equiv="refresh" content="0;url=https://example.com/abc/">
  </head>
  <body></body>
</html>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.