diff --git a/goofy-client/libs/ozg-file/src/lib/ozg-file-container/ozg-file/ozg-file.component.ts b/goofy-client/libs/ozg-file/src/lib/ozg-file-container/ozg-file/ozg-file.component.ts index a33a903ed798abe776018ec30893587dfcb0a3fa..fd4897bb6f9ae0516e8a8d4e46c155dfcb78667b 100644 --- a/goofy-client/libs/ozg-file/src/lib/ozg-file-container/ozg-file/ozg-file.component.ts +++ b/goofy-client/libs/ozg-file/src/lib/ozg-file-container/ozg-file/ozg-file.component.ts @@ -1,4 +1,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { HttpParams } from '@angular/common/http'; +import { OAuthService } from 'angular-oauth2-oidc'; import { OzgFileLinkRel, OzgFileResource } from '@goofy-client/ozg-file-shared'; import { createEmptyStateResource, StateResource } from '@goofy-client/tech-shared'; import { getUrl, hasLink } from '@ngxp/rest'; @@ -20,6 +22,8 @@ export class OzgFileComponent { @Output() public startDownload: EventEmitter<OzgFileResource> = new EventEmitter<OzgFileResource>(); @Output() public startDelete: EventEmitter<OzgFileResource> = new EventEmitter<OzgFileResource>(); + constructor(private authService: OAuthService) {} + get isDisabled(): boolean { return this.getStateResource().loading; } @@ -37,13 +41,16 @@ export class OzgFileComponent { } dragStart(event) { - if (!!this.file.contentType || this.file.contentType === '') this.file.contentType = 'application/octet-stream'; - const downloadUrl = `${ this.file.contentType }:${ this.file.name }:${ getUrl(this.file, OzgFileLinkRel.DOWNLOAD)}` - //const downloadUrl = `${ this.file.contentType }:${ this.file.name }:${ getUrl(this.file, OzgFileLinkRel.DOWNLOAD)}` - //const downloadUrl = 'image/jpeg:Helge1.jpg:http://localhost:4300/api/ozgfiledata/13f009e2-8c81-4d69-9502-b99af959b14f' - //const downloadUrl = 'application/pdf:test-dnd.pdf:http://localhost:4300/assets/test-dnd.pdf' - //const downloadUrl = 'image/jpeg:Helge1.jpg:http://localhost:4300/assets/Helge1.jpg' - console.log(downloadUrl); + if (!!this.file.contentType || this.file.contentType === '') { + this.file.contentType = 'application/octet-stream'; + } + + let getParam = new HttpParams(); + getParam = getParam.set('downloadToken', this.authService.getAccessToken()); + + const remoteUrl = getUrl(this.file, OzgFileLinkRel.DOWNLOAD) + '?' + getParam.toString(); + const downloadUrl = `${ this.file.contentType }:${ this.file.name }:${ remoteUrl }` + event.dataTransfer.setData("DownloadURL", downloadUrl); } }