Skip to content

Commit 2188dd7

Browse files
[DSC-1529] retrieve bitstream link from thumbnail link in item
1 parent 361f6ef commit 2188dd7

1 file changed

Lines changed: 31 additions & 54 deletions

File tree

src/app/core/metadata/metadata.service.ts

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export class MetadataService {
407407
* Add <meta name="citation_pdf_url" ... > to the <head>
408408
*/
409409
private setCitationPdfUrlTag(): void {
410-
this.setPrimaryBitstreamInBundleTag('ORIGINAL', 'citation_pdf_url');
410+
this.setPrimaryBitstreamInBundleTag('citation_pdf_url');
411411
}
412412

413413
/**
@@ -431,7 +431,7 @@ export class MetadataService {
431431
* Add <meta name="og:image" ... > to the <head>
432432
*/
433433
private setOpenGraphImageTag(): void {
434-
this.setPrimaryBitstreamInBundleTag('THUMBNAIL', 'og:image');
434+
this.setPrimaryBitstreamInBundleTag('og:image');
435435
}
436436

437437

@@ -456,65 +456,42 @@ export class MetadataService {
456456
* Add <meta name="twitter:image" ... > to the <head>
457457
*/
458458
private setTwitterImageTag(): void {
459-
this.setPrimaryBitstreamInBundleTag('THUMBNAIL', 'twitter:image');
459+
this.setPrimaryBitstreamInBundleTag('twitter:image');
460460
}
461461

462-
private setPrimaryBitstreamInBundleTag(bundleName: string, tag: string): void {
462+
/**
463+
* Get bitstream from item thumbnail link
464+
*
465+
* @param item
466+
* @private
467+
*/
468+
private getBitstreamFromThumbnail(item: Item) : Observable<Bitstream> {
469+
return item.thumbnail.pipe(
470+
getFirstCompletedRemoteData(),
471+
map((thumbnailRD) => {
472+
if (thumbnailRD.hasSucceeded && isNotEmpty(thumbnailRD.payload)) {
473+
return thumbnailRD.payload;
474+
} else {
475+
return null;
476+
}
477+
}),
478+
filter(data => !!data),
479+
getDownloadableBitstream(this.authorizationService),
480+
)
481+
}
482+
483+
private setPrimaryBitstreamInBundleTag(tag: string): void {
463484
if (this.currentObject.value instanceof Item) {
464485
const item = this.currentObject.value as Item;
465-
466-
// Retrieve the bundle for the item
467-
this.bundleDataService.findByItemAndName(
468-
item,
469-
bundleName,
470-
true,
471-
true,
472-
followLink('primaryBitstream'),
473-
followLink('bitstreams', {
474-
findListOptions: {
475-
// limit the number of bitstreams used to find the citation pdf url to the number
476-
// shown by default on an item page
477-
elementsPerPage: this.appConfig.item.bitstream.pageSize
478-
}
479-
}, followLink('format')),
480-
).pipe(
481-
getFirstSucceededRemoteDataPayload(),
482-
switchMap((bundle: Bundle) =>
483-
// First try the primary bitstream
484-
bundle.primaryBitstream.pipe(
485-
getFirstCompletedRemoteData(),
486-
map((rd: RemoteData<Bitstream>) => {
487-
if (hasValue(rd.payload)) {
488-
return rd.payload;
489-
} else {
490-
return null;
491-
}
492-
}),
493-
getDownloadableBitstream(this.authorizationService),
494-
// return the bundle as well so we can use it again if there's no primary bitstream
495-
map((bitstream: Bitstream) => [bundle, bitstream])
496-
)
497-
),
498-
switchMap(([bundle, primaryBitstream]: [Bundle, Bitstream]) => {
499-
if (hasValue(primaryBitstream)) {
500-
// If there was a downloadable primary bitstream, emit its link
501-
return [getBitstreamDownloadRoute(primaryBitstream)];
486+
this.getBitstreamFromThumbnail(item).pipe(
487+
switchMap((bitstream) => {
488+
if (hasValue(bitstream)) {
489+
return [getBitstreamDownloadRoute(bitstream)]
502490
} else {
503-
// Otherwise consider the regular bitstreams in the bundle
504-
return bundle.bitstreams.pipe(
505-
getFirstCompletedRemoteData(),
506-
switchMap((bitstreamRd: RemoteData<PaginatedList<Bitstream>>) => {
507-
if (hasValue(bitstreamRd.payload) && bitstreamRd.payload.totalElements === 1) {
508-
// If there's only one bitstream in the bundle, emit its link if its downloadable
509-
return this.getBitLinkIfDownloadable(bitstreamRd.payload.page[0], bitstreamRd);
510-
} else {
511-
// Otherwise check all bitstreams to see if one matches the format whitelist
512-
return this.getFirstAllowedFormatBitstreamLink(bitstreamRd);
513-
}
514-
})
515-
);
491+
return null
516492
}
517493
}),
494+
filter(data => !!data),
518495
take(1)
519496
).subscribe((link: string) => {
520497
// Use the found link to set the <meta> tag

0 commit comments

Comments
 (0)