Skip to content

Commit

Permalink
Add fileDownlod.js and htmlescape.js file function
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Oct 23, 2023
1 parent 42b1559 commit 531feeb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/utils/fileDownload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TIMEOUT } from 'app/constant';

export function fileDownload({url, data, httpMethod="POST"} = {}) {
let timeoutId;
return new Promise((resolve, reject) => {
const downloadPromise = $.fileDownload(url, {
httpMethod,
data
});
timeoutId = setTimeout(()=>{
reject('Timeout');
downloadPromise.abort();
}, TIMEOUT);
downloadPromise
.done(()=>resolve())
.fail(()=> reject())
.always(()=>{
clearTimeout(timeoutId)
});
})
}
7 changes: 7 additions & 0 deletions src/utils/htmlescape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function htmlescape(string) {
string = string.replace("&", "&");
string = string.replace("<", "&lt;");
string = string.replace(">", "&gt;");
string = string.replace('"', "&quot;");
return string;
};
4 changes: 4 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { downloadCSVLayerFeatures } from './downloadCSVLayerFeatures';
import { downloadCSV } from './downloadCSV';
import { getTimeoutPromise } from './getTimeoutPromise';
import { XHR } from './XHR';
import { htmlescape } from "./htmlescape";
import { fileDownload } from "./fileDownload";
import { createSingleFieldParameter } from './createSingleFieldParameter';
import { createFilterFormInputs } from './createFilterFormInputs';
import { createFilterFromString } from './createFilterFromString';
Expand Down Expand Up @@ -141,6 +143,8 @@ const utils = {
downloadCSV,
getTimeoutPromise,
XHR,
htmlescape,
fileDownload,
/** @since 3.8.7 */
createSingleFieldParameter,
createFilterFromString,
Expand Down

0 comments on commit 531feeb

Please sign in to comment.