36 lines
892 B
JavaScript
36 lines
892 B
JavaScript
import ngModule from '../module';
|
|
|
|
class File {
|
|
constructor($httpParamSerializer, vnToken) {
|
|
this.$httpParamSerializer = $httpParamSerializer;
|
|
this.vnToken = vnToken;
|
|
}
|
|
|
|
/**
|
|
* Returns the full download path
|
|
*
|
|
* @param {String} dmsUrl The file download path
|
|
* @return {String} The full download path
|
|
*/
|
|
getPath(dmsUrl) {
|
|
const serializedParams = this.$httpParamSerializer({
|
|
access_token: this.vnToken.token
|
|
});
|
|
|
|
return `${dmsUrl}?${serializedParams}`;
|
|
}
|
|
|
|
/**
|
|
* Downloads a file in another window, automatically adds the authorization
|
|
* token to params.
|
|
*
|
|
* @param {String} dmsUrl The file download path
|
|
*/
|
|
download(dmsUrl) {
|
|
window.open(this.getPath(dmsUrl));
|
|
}
|
|
}
|
|
File.$inject = ['$httpParamSerializer', 'vnToken'];
|
|
|
|
ngModule.service('vnFile', File);
|