2021-10-05 16:21:07 +03:00
|
|
|
import Service from '@ember/service';
|
|
|
|
|
|
|
|
export default class UtilsService extends Service {
|
|
|
|
downloadFile(url) {
|
|
|
|
let iframe = document.getElementById('iframeDownload');
|
|
|
|
|
|
|
|
if (!iframe) {
|
|
|
|
iframe = document.createElement('iframe');
|
|
|
|
iframe.id = 'iframeDownload';
|
|
|
|
iframe.style.display = 'none';
|
|
|
|
document.body.append(iframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
iframe.setAttribute('src', url);
|
|
|
|
}
|
2022-09-23 18:41:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove tracking parameters from a URL
|
|
|
|
* @param {string} url
|
|
|
|
* @param {boolean} [display] Set to true to remove protocol and hash from the URL
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
cleanTrackedUrl(url, display = false) {
|
|
|
|
// Remove our own querystring parameters and protocol
|
2022-09-28 12:03:00 +03:00
|
|
|
const removeParams = ['ref', 'attribution_id', 'attribution_type'];
|
2022-09-23 18:41:46 +03:00
|
|
|
const urlObj = new URL(url);
|
|
|
|
for (const param of removeParams) {
|
|
|
|
urlObj.searchParams.delete(param);
|
|
|
|
}
|
|
|
|
if (!display) {
|
|
|
|
return urlObj.toString();
|
|
|
|
}
|
|
|
|
// Return URL without protocol
|
2022-09-28 11:31:18 +03:00
|
|
|
return urlObj.host + (urlObj.pathname === '/' && !urlObj.search ? '' : urlObj.pathname) + (urlObj.search ? urlObj.search : '') + (urlObj.hash ? urlObj.hash : '');
|
2022-09-23 18:41:46 +03:00
|
|
|
}
|
2021-10-05 16:21:07 +03:00
|
|
|
}
|