@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
36 lines (35 loc) • 1.09 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import { generateQrCode } from '../../../tools/utils/qrcode.js';
class GmfShareManager {
serviceUrl;
constructor(serviceUrl) {
this.serviceUrl = serviceUrl;
}
async shortenUrl(longUrl) {
const errorResponse = {
success: false,
shorturl: longUrl
};
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());
const shortUrl = response_data.short_url;
const qrcode = await generateQrCode(shortUrl);
if (response_data) {
return {
success: true,
shorturl: response_data.short_url,
qrcode: qrcode
};
}
return errorResponse;
}
}
export default GmfShareManager;