Skip to content

Commit

Permalink
fix contentType parsing in dispatchOpdsLink
Browse files Browse the repository at this point in the history
- should fixes the second part of the issue #1148
  • Loading branch information
panaC committed Dec 3, 2020
1 parent 76b725a commit 81a52fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
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 81a52fe

Please sign in to comment.