-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extend node.js http.ServerResponse class, add a download method…
… that sends file attachments to
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {ServerResponse} from 'http'; | ||
|
||
export default { | ||
/** | ||
* returns an RServerResponse class | ||
*@param {StaticFileServer} staticFileServer - static file server instance | ||
*@returns {RServerResponse} | ||
*/ | ||
getClass(staticFileServer) { | ||
|
||
return class extends ServerResponse { | ||
/** | ||
* call the super class. | ||
*/ | ||
constructor(...args) { | ||
super(...args); | ||
} | ||
|
||
/** | ||
* return the instance identifier | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return 'RServerResponse'; | ||
} | ||
|
||
/** | ||
* sends file intended for download to the client | ||
*@param {string} filePath - file relative path | ||
*@param {string} [filename] - suggested file download name that the browser uses while | ||
* saving the file. defaults to the files base name. | ||
*@param {Function} callback - the callback function to execute once the operation | ||
* completes or fails | ||
*/ | ||
download(filePath, filename, callback) { | ||
staticFileServer.serveDownload(this, filePath, filename, callback); | ||
} | ||
}; | ||
} | ||
}; |