[IMP] web: export download file function

Currently, there is a download function exported that expects data and a url.
You would provide a controller url and some data to send, and the result would be downloaded.

However, it may be useful to sometimes trigger a download on the spot if there is no need to reach for a controller. Like having some json data and download it.

The code already existed, so this function is now exported as `downloadFile`.

closes odoo/odoo#118227

X-original-commit: cd9a5d491715247636d95c9f768ffc42616f4b47
Related: odoo/enterprise#39564
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
This commit is contained in:
Simon Genin (ges)
2023-04-13 15:26:52 +02:00
parent 33466c6ecd
commit 8835b3fe7a
+21 -2
View File
@@ -446,11 +446,30 @@ function _download(data, filename, mimetype) {
/* eslint-enable */
// -----------------------------------------------------------------------------
// Exported download function
// Exported download functions
// -----------------------------------------------------------------------------
/**
* Download a file
* Download data as a file
*
* @param {Object} data
* @param {String} filename
* @param {String} mimetype
* @returns {Boolean}
*
* Note: the actual implementation is certainly unconventional, but sadly
* necessary to be able to test code using the download function
*/
export function downloadFile(data, filename, mimetype) {
return downloadFile._download(data, filename, mimetype)
}
downloadFile._download = _download;
/**
* Download a file from form or server url
*
* This function is meant to call a controller with some data
* and download the response.
*
* Note: the actual implementation is certainly unconventional, but sadly
* necessary to be able to test code using the download function