Commits

Yura Bondarenko authored 1caba78b4df
79768: Check against list of allowed mimetypes
No tags

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

Modified
33 33
34 34 @Injectable()
35 35 export class MetadataService {
36 36
37 37 private initialized: boolean;
38 38
39 39 private tagStore: Map<string, MetaDefinition[]>;
40 40
41 41 private currentObject: BehaviorSubject<DSpaceObject>;
42 42
43 + private readonly ALLOWED_MIMETYPES = [
44 + 'application/pdf', // .pdf
45 + 'application/postscript', // .ps
46 + 'application/msword', // .doc
47 + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document ', // .docx
48 + 'application/rtf', // .rtf
49 + 'application/epub+zip', // .epub
50 + ];
51 +
43 52 constructor(
44 53 private router: Router,
45 54 private translate: TranslateService,
46 55 private meta: Meta,
47 56 private title: Title,
48 57 private dsoNameService: DSONameService,
49 58 private bundleDataService: BundleDataService,
50 59 private bitstreamDataService: BitstreamDataService,
51 60 private bitstreamFormatDataService: BitstreamFormatDataService,
52 61 private rootService: RootDataService
376 385 switchMap((bitstreams: Bitstream[]) => bitstreams),
377 386 // Retrieve the format for each bitstream
378 387 switchMap((bitstream: Bitstream) => bitstream.format.pipe(
379 388 getFirstSucceededRemoteDataPayload(),
380 389 // Keep the original bitstream, because it, not the format, is what we'll need
381 390 // for the link at the end
382 391 map((format: BitstreamFormat) => [bitstream, format])
383 392 )),
384 393 // Filter out only pairs with whitelisted formats
385 394 filter(([, format]: [Bitstream, BitstreamFormat]) =>
386 - hasValue(format) && format.mimetype === 'application/pdf'), // TODO change to check map of mimetypes
395 + hasValue(format) && this.ALLOWED_MIMETYPES.includes(format.mimetype)),
387 396 // We only need 1
388 397 take(1),
389 398 // Emit the link of the match
390 399 map(([bitstream, ]: [Bitstream, BitstreamFormat]) => getBitstreamDownloadRoute(bitstream))
391 400 );
392 401 }
393 402
394 403 /**
395 404 * Add <meta name="Generator" ... > to the <head> containing the current DSpace version
396 405 */

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut