Skip to content

Commit 86655fd

Browse files
Merge pull request #307 from NYPL-Simplified/SIMPLY-3869/opds-parsing-bug-fix
Simply 3869/opds parsing bug fix - TEST
2 parents bca6d8a + 715a4bd commit 86655fd

File tree

5 files changed

+73
-17
lines changed

5 files changed

+73
-17
lines changed

packages/opds-web-client/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Changelog
22

3+
### v0.6.3-test
4+
5+
- The resolve function in OPDSDataAdapter is causing bugs in the List Manager of CM Admin. This version removes the function in order to test it.
36
### v0.6.2
47

58
- Updated class `.collection .collection-container` to give more space to the bottom.

packages/opds-web-client/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opds-web-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opds-web-client",
3-
"version": "0.6.2",
3+
"version": "0.6.3-test",
44
"description": "OPDS web client",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

packages/opds-web-client/src/DataFetcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default class DataFetcher {
4040

4141
fetchOPDSData(url: string) {
4242
let parser = new OPDSParser();
43+
console.log('in fetchOPDSData')
4344

4445
if (!this.adapter) {
4546
return Promise.reject({

packages/opds-web-client/src/OPDSDataAdapter.ts

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import {
2121
SearchData,
2222
FulfillmentLink
2323
} from "./interfaces";
24+
// import { resolve } from "url";
2425

25-
const resolve = (base, relative) => new URL(relative, base).toString();
26+
// const resolve = (base, relative) => new URL(relative, base).toString();
2627

2728
let sanitizeHtml;
2829
const createDOMPurify = require("dompurify");
@@ -49,9 +50,14 @@ export function adapter(
4950
url: string
5051
): CollectionData | BookData {
5152
if (data instanceof OPDSFeed) {
53+
console.log('in adapter - OPDSFeed')
54+
console.log('url -->', url)
55+
console.log('data -->', data)
5256
let collectionData = feedToCollection(data, url);
57+
console.log('collectionData -->', collectionData)
5358
return collectionData;
5459
} else if (data instanceof OPDSEntry) {
60+
console.log('in adapter - OPDSEntry')
5561
let bookData = entryToBook(data, url);
5662
return bookData;
5763
} else {
@@ -60,34 +66,47 @@ export function adapter(
6066
}
6167

6268
export function entryToBook(entry: OPDSEntry, feedUrl: string): BookData {
69+
console.log('in entryToBook function')
6370
let authors = entry.authors.map(author => {
71+
console.log('in authors loop')
6472
return author.name;
6573
});
6674

6775
let contributors = entry.contributors.map(contributor => {
76+
console.log('in contributors loop')
6877
return contributor.name;
6978
});
7079

7180
let imageUrl, imageThumbLink;
7281
let artworkLinks = entry.links.filter(link => {
82+
console.log('in artworkLinks loop')
7383
return link instanceof OPDSArtworkLink;
7484
});
7585
if (artworkLinks.length > 0) {
7686
imageThumbLink = artworkLinks.find(
7787
link => link.rel === "http://opds-spec.org/image/thumbnail"
7888
);
7989
if (imageThumbLink) {
80-
imageUrl = resolve(feedUrl, imageThumbLink.href);
90+
console.log('in if statement before first resolve in entryToBook')
91+
console.log('feedUrl -->', feedUrl)
92+
console.log('imageThumLink.href -->', imageThumbLink.href)
93+
// imageUrl = resolve(feedUrl, imageThumbLink.href); // feedUrl = /OWL..., imageThumb = https:// --> new URL(https://, /OWL)
94+
imageUrl = imageThumbLink.href
8195
} else {
8296
console.log("WARNING: using possibly large image for " + entry.title);
83-
imageUrl = resolve(feedUrl, artworkLinks[0].href);
97+
// imageUrl = resolve(feedUrl, artworkLinks[0].href);
98+
imageUrl = artworkLinks[0].href
8499
}
85100
}
86101

87102
let detailUrl;
88103
let detailLink = entry.links.find(link => link instanceof CompleteEntryLink);
89104
if (detailLink) {
90-
detailUrl = resolve(feedUrl, detailLink.href);
105+
console.log('in if detailLink statement')
106+
console.log('detailLink.href -->', detailLink.href)
107+
console.log('feedUrl --->', feedUrl)
108+
// detailUrl = resolve(feedUrl, detailLink.href);
109+
detailUrl = detailLink.href
91110
}
92111

93112
let categories = entry.categories
@@ -96,14 +115,18 @@ export function entryToBook(entry: OPDSEntry, feedUrl: string): BookData {
96115

97116
let openAccessLinks = entry.links
98117
.filter(link => {
118+
console.log('in openAccessLinks')
99119
return (
100120
link instanceof OPDSAcquisitionLink &&
101121
link.rel === OPDSAcquisitionLink.OPEN_ACCESS_REL
102122
);
103123
})
104124
.map(link => {
125+
console.log('link.href -->', link.href)
126+
console.log('feedUrl -->', feedUrl)
105127
return {
106-
url: resolve(feedUrl, link.href),
128+
// url: resolve(feedUrl, link.href),
129+
url: link.href,
107130
type: link.type
108131
};
109132
});
@@ -116,7 +139,10 @@ export function entryToBook(entry: OPDSEntry, feedUrl: string): BookData {
116139
);
117140
});
118141
if (borrowLink) {
119-
borrowUrl = resolve(feedUrl, borrowLink.href);
142+
console.log('in borrowLink if statement')
143+
console.log('borrowLink.href -->', borrowLink.href)
144+
// borrowUrl = resolve(feedUrl, borrowLink.href);
145+
borrowUrl = borrowLink.href
120146
}
121147

122148
let allBorrowLinks: FulfillmentLink[] = entry.links
@@ -134,7 +160,8 @@ export function entryToBook(entry: OPDSEntry, feedUrl: string): BookData {
134160
indirectType = indirects[0].type;
135161
}
136162
return {
137-
url: resolve(feedUrl, link.href),
163+
// url: resolve(feedUrl, link.href),
164+
url: link.href,
138165
type: link.type,
139166
indirectType
140167
};
@@ -156,7 +183,8 @@ export function entryToBook(entry: OPDSEntry, feedUrl: string): BookData {
156183
indirectType = indirects[0].type;
157184
}
158185
return {
159-
url: resolve(feedUrl, link.href),
186+
url: link.href,
187+
// url: resolve(feedUrl, link.href),
160188
type: link.type,
161189
indirectType
162190
};
@@ -200,7 +228,8 @@ export function entryToBook(entry: OPDSEntry, feedUrl: string): BookData {
200228
function entryToLink(entry: OPDSEntry, feedUrl: string): LinkData | null {
201229
let links = entry.links;
202230
if (links.length > 0) {
203-
const href = resolve(feedUrl, links[0].href);
231+
// const href = resolve(feedUrl, links[0].href);
232+
const href = links[0].href
204233
return {
205234
id: entry.id,
206235
text: entry.title,
@@ -253,9 +282,10 @@ function OPDSLinkToLinkData(feedUrl, link: OPDSLink = null): LinkData | null {
253282
if (!link || !link.href) {
254283
return null;
255284
}
256-
285+
console.log('in OPDSLinkToLinkData')
257286
return {
258-
url: resolve(feedUrl, link.href),
287+
// url: resolve(feedUrl, link.href),
288+
url: link.href,
259289
text: link.title,
260290
type: link.rel
261291
};
@@ -265,6 +295,7 @@ export function feedToCollection(
265295
feed: OPDSFeed,
266296
feedUrl: string
267297
): CollectionData {
298+
console.log('in feedToCollection function!')
268299
let collection = <CollectionData>{
269300
id: feed.id,
270301
title: feed.title,
@@ -288,20 +319,29 @@ export function feedToCollection(
288319
let links: OPDSLink[] = [];
289320

290321
feed.entries.forEach(entry => {
322+
console.log('in feed.entries loop')
291323
if (feed instanceof AcquisitionFeed) {
324+
console.log('in first if statement')
292325
let book = entryToBook(entry, feedUrl);
293326
const collectionLink: OPDSCollectionLink = entry.links.find(
294327
link => link instanceof OPDSCollectionLink
295328
);
296329
if (collectionLink) {
330+
console.log('in second if statement')
297331
let { title, href } = collectionLink;
332+
console.log('collectionLink -->', collectionLink)
333+
console.log('href from collectionLink --->', href)
298334

299335
if (laneIndex[title]) {
336+
console.log('in third if statement')
300337
laneIndex[title].books.push(book);
301338
} else {
339+
console.log('in else statement')
340+
console.log('feedUrl --->', feedUrl)
302341
laneIndex[title] = {
303342
title,
304-
url: resolve(feedUrl, href),
343+
// url: resolve(feedUrl, href),
344+
url: href,
305345
books: [book]
306346
};
307347
// use array of titles to preserve lane order
@@ -316,7 +356,10 @@ export function feedToCollection(
316356
}
317357
});
318358

359+
console.log('finished feed.entries loop')
360+
319361
lanes = laneTitles.reduce((result, title) => {
362+
console.log('in laneTitles loop')
320363
let lane = laneIndex[title];
321364
lane.books = dedupeBooks(lane.books);
322365
result.push(lane);
@@ -325,6 +368,7 @@ export function feedToCollection(
325368

326369
let facetLinks: OPDSFacetLink[] = [];
327370
if (feed.links) {
371+
console.log('in feed.links if statement')
328372
facetLinks = feed.links.filter(link => {
329373
return link instanceof OPDSFacetLink;
330374
});
@@ -333,14 +377,21 @@ export function feedToCollection(
333377
return link instanceof SearchLink;
334378
});
335379
if (searchLink) {
336-
search = { url: resolve(feedUrl, searchLink.href) };
380+
console.log('searchLink is true!')
381+
console.log('feedUrl -->', feedUrl)
382+
console.log('searchLink.href -->', searchLink.href)
383+
// search = { url: resolve(feedUrl, searchLink.href) };
384+
search = {url: searchLink.href}
337385
}
338386

339387
let nextPageLink = feed.links.find(link => {
340388
return link.rel === "next";
341389
});
342390
if (nextPageLink) {
343-
nextPageUrl = resolve(feedUrl, nextPageLink.href);
391+
console.log('in nextPageLink')
392+
// nextPageUrl = resolve(feedUrl, nextPageLink.href);
393+
nextPageUrl = nextPageLink.href
394+
console.log(nextPageUrl)
344395
}
345396

346397
catalogRootLink = feed.links.find(link => {
@@ -360,7 +411,8 @@ export function feedToCollection(
360411
facetGroups = facetLinks.reduce((result, link) => {
361412
let groupLabel = link.facetGroup;
362413
let label = link.title;
363-
let href = resolve(feedUrl, link.href);
414+
let href = link.href
415+
// let href = resolve(feedUrl, link.href);
364416
let active = link.activeFacet;
365417
let facet = { label, href, active };
366418
let newResult: any[] = [];

0 commit comments

Comments
 (0)