mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 07:05:35 +00:00
20 lines
478 B
JavaScript
20 lines
478 B
JavaScript
import request from 'superagent';
|
|
|
|
const SHORTEN_API = 'https://www.googleapis.com/urlshortener/v1/url?key=';
|
|
|
|
export default function shortenUrl(url, success, error) {
|
|
if (window.navigator.onLine) {
|
|
request.post(SHORTEN_API + GAPI_KEY)
|
|
.send({ longUrl: url })
|
|
.end(function(err, response) {
|
|
if (err) {
|
|
error('Error');
|
|
} else {
|
|
success(response.data.id);
|
|
}
|
|
});
|
|
} else {
|
|
return error('Not Online');
|
|
}
|
|
}
|