UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

41 lines (40 loc) 1.17 kB
class GmfManager { constructor(serviceUrl) { Object.defineProperty(this, "serviceUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.serviceUrl = serviceUrl; } async shortenUrl(longUrl) { const errorResponse = { success: false, shorturl: longUrl }; try { const params = new URLSearchParams(); params.append('url', longUrl); const response = await fetch(this.serviceUrl, { method: 'POST', headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }), body: params }); const response_data = (await response.json()); if (response_data) { return { success: true, shorturl: response_data.short_url }; } return errorResponse; } catch (error) { return errorResponse; } } } export default GmfManager;