UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

39 lines (38 loc) 1.15 kB
class LstuManager { constructor(serviceUrl) { Object.defineProperty(this, "serviceUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.serviceUrl = serviceUrl; } async shortenUrl(longUrl) { const params = new URLSearchParams(); params.append('lsturl', longUrl); params.append('format', 'json'); const errorResponse = { success: false, shorturl: 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.success) { const data = response_data; return { success: true, shorturl: data.short, qrcode: `data:image/png;base64, ${data.qrcode}` }; } return errorResponse; } } export default LstuManager;