mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
use embed size in alternative link
This commit is contained in:
@@ -15,7 +15,8 @@ import { Injectable } from '@angular/core';
|
|||||||
import { ResponseParsingService } from './parsing.service';
|
import { ResponseParsingService } from './parsing.service';
|
||||||
import { ParsedResponse } from '../cache/response.models';
|
import { ParsedResponse } from '../cache/response.models';
|
||||||
import { RestRequestMethod } from './rest-request-method';
|
import { RestRequestMethod } from './rest-request-method';
|
||||||
import { getUrlWithoutEmbedParams } from '../index/index.selectors';
|
import { getUrlWithoutEmbedParams, getEmbedSizeParams } from '../index/index.selectors';
|
||||||
|
import { URLCombiner } from '../url-combiner/url-combiner';
|
||||||
|
|
||||||
/* tslint:disable:max-classes-per-file */
|
/* tslint:disable:max-classes-per-file */
|
||||||
|
|
||||||
@@ -86,6 +87,8 @@ export class DspaceRestResponseParsingService implements ResponseParsingService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public process<ObjectDomain>(data: any, request: RestRequest, alternativeURL?: string): any {
|
public process<ObjectDomain>(data: any, request: RestRequest, alternativeURL?: string): any {
|
||||||
|
const embedSizeParams = getEmbedSizeParams(request.href);
|
||||||
|
|
||||||
if (isNotEmpty(data)) {
|
if (isNotEmpty(data)) {
|
||||||
if (hasNoValue(data) || (typeof data !== 'object')) {
|
if (hasNoValue(data) || (typeof data !== 'object')) {
|
||||||
return data;
|
return data;
|
||||||
@@ -100,7 +103,13 @@ export class DspaceRestResponseParsingService implements ResponseParsingService
|
|||||||
.keys(data._embedded)
|
.keys(data._embedded)
|
||||||
.filter((property) => data._embedded.hasOwnProperty(property))
|
.filter((property) => data._embedded.hasOwnProperty(property))
|
||||||
.forEach((property) => {
|
.forEach((property) => {
|
||||||
this.process<ObjectDomain>(data._embedded[property], request, data._links[property].href);
|
let embedAltUrl = data._links[property].href;
|
||||||
|
const match = embedSizeParams
|
||||||
|
.find((param: { name: string, size: number }) => param.name === property);
|
||||||
|
if (hasValue(match)) {
|
||||||
|
embedAltUrl = new URLCombiner(embedAltUrl, `?size=${match.size}`).toString();
|
||||||
|
}
|
||||||
|
this.process<ObjectDomain>(data._embedded[property], request, embedAltUrl);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@ export const getUrlWithoutEmbedParams = (url: string): string => {
|
|||||||
if (isNotEmpty(parsed.query)) {
|
if (isNotEmpty(parsed.query)) {
|
||||||
const parts = parsed.query.split(/[?|&]/)
|
const parts = parsed.query.split(/[?|&]/)
|
||||||
.filter((part: string) => isNotEmpty(part))
|
.filter((part: string) => isNotEmpty(part))
|
||||||
.filter((part: string) => !part.startsWith('embed='));
|
.filter((part: string) => !(part.startsWith('embed=') || part.startsWith('embed.size=')));
|
||||||
let args = '';
|
let args = '';
|
||||||
if (isNotEmpty(parts)) {
|
if (isNotEmpty(parts)) {
|
||||||
args = `?${parts.join('&')}`;
|
args = `?${parts.join('&')}`;
|
||||||
@@ -37,6 +37,27 @@ export const getUrlWithoutEmbedParams = (url: string): string => {
|
|||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the embed size params from a url
|
||||||
|
* @param url The url to parse
|
||||||
|
*/
|
||||||
|
export const getEmbedSizeParams = (url: string): { name: string, size: number }[] => {
|
||||||
|
if (isNotEmpty(url)) {
|
||||||
|
const parsed = parse(url);
|
||||||
|
if (isNotEmpty(parsed.query)) {
|
||||||
|
return parsed.query.split(/[?|&]/)
|
||||||
|
.filter((part: string) => isNotEmpty(part))
|
||||||
|
.map((part: string) => part.match(/^embed.size=([^=]+)=(\d+)$/))
|
||||||
|
.filter((matches: RegExpMatchArray) => hasValue(matches) && hasValue(matches[1]) && hasValue(matches[2]))
|
||||||
|
.map((matches: RegExpMatchArray) => {
|
||||||
|
return { name: matches[1], size: Number(matches[2]) };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the MetaIndexState based on the CoreSate
|
* Return the MetaIndexState based on the CoreSate
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user