Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output fails if payload doesn't already exist... #1

Open
Swiftnesses opened this issue Apr 29, 2019 · 5 comments
Open

Output fails if payload doesn't already exist... #1

Swiftnesses opened this issue Apr 29, 2019 · 5 comments

Comments

@Swiftnesses
Copy link

Swiftnesses commented Apr 29, 2019

Hi,

I have a few cases whereby there is no payload when I send the shorturl to the node, in this case it fails... I workaround it by creating a fake payload before, but it's not ideal :)

I believe this issues is because you try to send the payload using "msg.payload.shorturl", which will not work if no payload exists (annoying, I know). Instead I guess we need:

msg.payload = '{"shorturl:" "url"}'

Edit: It would be really nice if we could configure the input msg name and the output, would help avoid conflicts in more complicated flows.

@balsimpson
Copy link
Owner

                        if (msg.longurl) {
				longurl = msg.longurl;
			} else if (msg.payload && msg.payload.longurl) {
				longurl = msg.payload.longurl;
			} else {
				longurl = config.longurl;
			}
			// SHORT URL
			if (msg.shorturl) {
				shorturl = msg.shorturl;
			} else if (msg.payload && msg.payload.shorturl) {
				shorturl = msg.payload.shorturl;
			} else {
				shorturl = config.shorturl;
			}

This is my code. I am checking if there is msg.payload before I assign it to a variable. If there is no payload, you should get the shorturl in msg.shorturl. Does that answer your problem? Do let me know.

@Swiftnesses
Copy link
Author

Hi @balsimpson it does.

I also noticed that urls such as "https://qft.hodloo.com/#/binance:eth-usdt" do not shortnen correctly and return only "https://qft.hodloo.com", it works fine via is.gd direct...

@Swiftnesses
Copy link
Author

Swiftnesses commented May 20, 2019

Seems to be an API issue, works direct, but not via the API GET, hmmm.

is.gd documentation states: The url parameter is the address that you want to shorten. You must URL encode this parameter before submitting it otherwise your application will not properly support URLs containing symbols such as hash, semicolon, plus and ampersand (among others).

A lot of languages have a built in function for URL encoding such as encodeURIComponent() in Javascript, urllib.quote() in Python and urlencode() in PHP.

@Swiftnesses
Copy link
Author

			// LONG URL
			if (msg.longurl) {
				longurl = encodeURIComponent(msg.longurl);
			} else if (msg.payload && msg.payload.longurl) {
				longurl = encodeURIComponent(msg.payload.longurl);
			} else {
				longurl = config.longurl;
			}

@balsimpson
Copy link
Owner

Have updated the code. Do check if it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants