mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 23:40:13 +01:00
removed createInterceptDownload file and use existing code for http download
This commit is contained in:
parent
72b8672e62
commit
cfb88baa7f
3 changed files with 49 additions and 51 deletions
29
models/lib/httpStream.js
Normal file
29
models/lib/httpStream.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
export const httpStreamOutput = function(readStream, name, http, downloadFlag, cacheControl) {
|
||||
readStream.on('data', data => {
|
||||
http.response.write(data);
|
||||
});
|
||||
|
||||
readStream.on('end', () => {
|
||||
// don't pass parameters to end() or it will be attached to the file's binary stream
|
||||
http.response.end();
|
||||
});
|
||||
|
||||
readStream.on('error', () => {
|
||||
http.response.statusCode = 404;
|
||||
http.response.end('not found');
|
||||
});
|
||||
|
||||
http.response.setHeader('Cache-Control', cacheControl);
|
||||
http.response.setHeader('Content-Disposition', getContentDisposition(name, http?.params?.query?.download));
|
||||
};
|
||||
|
||||
/** will initiate download, if links are called with ?download="true" queryparam */
|
||||
const getContentDisposition = (name, downloadFlag) => {
|
||||
const dispositionType = downloadFlag === 'true' ? 'attachment;' : 'inline;';
|
||||
|
||||
const encodedName = encodeURIComponent(name);
|
||||
const dispositionName = `filename="${encodedName}"; filename=*UTF-8"${encodedName}";`;
|
||||
const dispositionEncoding = 'charset=utf-8';
|
||||
|
||||
return `${dispositionType} ${dispositionName} ${dispositionEncoding}`;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue