RED-6162 - tenant context
This commit is contained in:
parent
37524e1543
commit
f9308f0e13
@ -1,15 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { DownloadStatus, IDownloadStatus, IDownloadStatusResponse, IPrepareDownloadRequest, IRemoveDownloadRequest } from '@red/domain';
|
||||
import { firstValueFrom, Observable } from 'rxjs';
|
||||
import { ConfigService } from '@services/config.service';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { EntitiesService, mapEach, RequiredParam, Validate } from '@iqser/common-ui';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
import { TenantContext } from '@utils/tenant-context';
|
||||
|
||||
@Injectable()
|
||||
export class FileDownloadService extends EntitiesService<IDownloadStatus, DownloadStatus> {
|
||||
protected readonly _defaultModelPath = 'async/download';
|
||||
protected readonly _entityClass = DownloadStatus;
|
||||
protected readonly _tenantContext = inject(TenantContext);
|
||||
|
||||
constructor(private readonly _configService: ConfigService, private readonly _logger: NGXLogger) {
|
||||
super();
|
||||
@ -34,7 +36,9 @@ export class FileDownloadService extends EntitiesService<IDownloadStatus, Downlo
|
||||
async performDownload(status: DownloadStatus) {
|
||||
const token = await this.generateToken(status.storageId);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = `${this._configService.values.API_URL}/async/download/with-ott/${token.value}`;
|
||||
anchor.href = `${this._configService.values.API_URL}/async/download/with-ott/${token.value}?tenantId?=${encodeURIComponent(
|
||||
this._tenantContext.getTenant(),
|
||||
)}`;
|
||||
anchor.download = status.filename;
|
||||
anchor.target = '_blank';
|
||||
this._logger.info('[DOWNLOAD] Downloading with link: ', anchor.href);
|
||||
|
||||
8
apps/red-ui/src/app/utils/tenant-context.ts
Normal file
8
apps/red-ui/src/app/utils/tenant-context.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class TenantContext {
|
||||
getTenant(): string {
|
||||
return 'redaction';
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,15 @@
|
||||
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { TenantContext } from '@utils/tenant-context';
|
||||
|
||||
@Injectable()
|
||||
export class TenantIdInterceptor implements HttpInterceptor {
|
||||
protected readonly _tenantContext = inject(TenantContext);
|
||||
|
||||
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
const updatedRequest = req.clone({
|
||||
setHeaders: { 'X-TENANT-ID': 'redaction' },
|
||||
setHeaders: { 'X-TENANT-ID': this._tenantContext.getTenant() },
|
||||
});
|
||||
return next.handle(updatedRequest);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user