app/core/services/mediaKit-service/media-kit.service.ts
Methods |
constructor(util: UtilService, linkService: ComponentLinkService, idService: IdGeneratorService, publicationService: PublicationService, constants: ConstantsService)
|
||||||||||||||||||
Parameters :
|
buildQueryString | ||||||
buildQueryString(mediaKit: MediaKit)
|
||||||
Parameters :
Returns :
string
|
nbrOfDownloadableItems | ||||||
nbrOfDownloadableItems(mediaKit: MediaKit)
|
||||||
Parameters :
Returns :
number
|
Private parseMediaItem | ||||
parseMediaItem(mediaItemJson)
|
||||
Parameters :
Returns :
MediaItem
|
parseMediaKit | ||||||
parseMediaKit(json: any)
|
||||||
Parameters :
Returns :
MediaKit
|
import { MediaKit, MediaItem } from '../../interfaces/interfaces.component';
import { UtilService } from '../util-service/util.service';
import { ComponentLinkService } from '../component-link-service/component-link.service';
import { IdGeneratorService } from '../id-generator.service';
import { PublicationService } from '../publication-service/publication.service';
import { Injectable } from '@angular/core';
import { ConstantsService } from 'src/app/shared/constants/constants.service';
@Injectable()
export class MediaKitService {
constructor(private util: UtilService,
private linkService: ComponentLinkService,
private idService: IdGeneratorService,
private publicationService: PublicationService,
private constants: ConstantsService) { }
buildQueryString(mediaKit: MediaKit): string {
const pubPath = this.publicationService.getPublicationPath();
const handlerUrl = `${this.constants.CONTENT_URL_PREFIX}${pubPath}/${this.constants.DOWNLOAD_ZIPFILE_HANDLER}`;
let queryString = `${handlerUrl}?zipFilename=${mediaKit.zipFileName}.zip`;
mediaKit.mediaItems.forEach(mediaItem => {
if (!mediaItem.isVideo) {
queryString += `&item=${mediaItem.componentId}-${mediaItem.fileName}`;
}
});
return queryString.includes('item') ? queryString : '#';
}
nbrOfDownloadableItems(mediaKit: MediaKit): number {
return mediaKit.mediaItems.filter(mk => !mk.isVideo).length;
}
parseMediaKit(json: any): MediaKit {
const title = this.util.extract(json, 'Title');
const buttonTitle = this.util.extract(json, 'ButtonTitle');
const mediaItems = (this.util.extract(json, 'ImagesVideosDocuments') || []).map(e => this.parseMediaItem(e));
const zipFileName = this.util.extract(json, 'DownloadedMediaKitTitlebuttonTitle');
return {
title: title,
buttonTitle: buttonTitle,
mediaItems: mediaItems,
zipFileName: zipFileName
};
}
private parseMediaItem(mediaItemJson): MediaItem {
const url = this.linkService.getUrl(this.util.extract(mediaItemJson, 'MediaItem'));
const title = this.util.extract(mediaItemJson, 'PresentationTitleForMediaItem') || '';
const mediaItem = this.util.partiallyApplyExtract(mediaItemJson, 'MediaItem');
const altText = mediaItem('Assetmetadata', 'Titlemm');
const mimeType = mediaItem('MimeType') || mediaItem('Type') || '';
const fileName = mediaItem('FileName');
const componentId = mediaItem('Id');
const filesize = this.util.formatFilesize(Number(mediaItem('FileSize')));
const item = this.util.extract(mediaItemJson, 'MediaItem');
// VidDisplay is a field from the youtube video, mimetype is set for MM videos and the akamai player has the type flag
const isVideo = mediaItem('VidDisplay') || mimeType.startsWith('video') || mediaItem('Type') === 'akamaiplayer';
return {
title: title,
size: filesize,
url: url,
altText: altText,
mimeType: mimeType,
id: this.idService.getId(),
fileName: fileName,
componentId: componentId,
mediaItem: item,
isVideo: isVideo
};
}
}