Skip to content

Commit

Permalink
fix(OPDS): filter rel='alternate', improved contentType parsing (PR #…
Browse files Browse the repository at this point in the history
…1275 Fixes #1148)
  • Loading branch information
panaC committed Dec 4, 2020
1 parent 57b8183 commit c5c019b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/converter/opds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export class OpdsFeedViewConverter {
const entrylinkView = fallback(
this.convertFilterLinkToView(baseUrl, r2OpdsPublication.Links, {
type: "type=entry;profile=opds-catalog",
rel: "alternate",
}),
this.convertFilterLinkToView(baseUrl, r2OpdsPublication.Links, {
type: ContentType.Opds2Pub,
Expand Down
11 changes: 6 additions & 5 deletions src/renderer/library/opds/handleLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IOpdsLinkView } from "readium-desktop/common/views/opds";
import { decodeB64 } from "readium-desktop/renderer/common/logics/base64";
import { buildOpdsBrowserRoute } from "readium-desktop/renderer/library/opds/route";
import { TDispatch } from "readium-desktop/typings/redux";
import { ContentType } from "readium-desktop/utils/content-type";
import { ContentType, parseContentType } from "readium-desktop/utils/content-type";

import { dispatchHistoryPush, TLocation } from "../routing";
import { extractParamFromOpdsRoutePathname } from "./route";
Expand All @@ -22,10 +22,11 @@ export const dispatchOpdsLink =

dispatch(dialogActions.closeRequest.build());

if (ln.type === ContentType.Opds2 ||
ln.type === ContentType.Opds2Auth ||
ln.type === ContentType.Opds2Pub ||
ln.type === ContentType.AtomXml) {
const contentType = parseContentType(ln.type);
if (contentType === ContentType.Opds2 ||
contentType === ContentType.Opds2Auth ||
contentType === ContentType.Opds2Pub ||
contentType === ContentType.AtomXml) {

const param = extractParamFromOpdsRoutePathname(location.pathname);

Expand Down
13 changes: 13 additions & 0 deletions src/utils/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ export enum ContentType {
lcppdf = "application/pdf+lcp",
pdf = "application/pdf",
}

export const parseContentType = (RawContentType: string): ContentType | undefined => {

if (!RawContentType) {
return undefined;
}

const contentTypeArray = RawContentType.replace(/\s/g, "").split(";");

const contentType = contentTypeArray.reduce<ContentType | undefined>(
(pv, cv) => pv || Object.values(ContentType).find((v) => v === cv), undefined);
return contentType;
};

0 comments on commit c5c019b

Please sign in to comment.