Skip to content

Commit 6685184

Browse files
Updated addAcquisition to allow for any acquisition relation
1 parent 811d39d commit 6685184

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/model/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ export type FeedKind = 'navigation' | 'acquisition';
22

33
export type NavigationRel = 'start' | 'previous' | 'next' | 'last' | 'first';
44

5+
export type AcquisitionRel =
6+
| 'open-access'
7+
| 'borrow'
8+
| 'buy'
9+
| 'sample'
10+
| 'preview'
11+
| 'subscribe';
12+
513
export interface Link {
614
rel: string;
715
href: string;

src/versions/v1_2/entry.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { EntryOptions, FeedKind, Link } from '../../model/types';
1+
import {
2+
AcquisitionRel,
3+
EntryOptions,
4+
FeedKind,
5+
Link,
6+
} from '../../model/types';
27
import { EntryXmlSerializer } from '../../utils/xml/EntryXmlSerializer';
38

49
/**
@@ -99,17 +104,21 @@ export class Entry {
99104
/**
100105
* Adds an acquisition link to the entry. This is a convenience method for adding an acquisition link with the appropriate rel. If openAccess is true, the rel will be set to open-access.
101106
* @param href - The URL of the acquisition link.
102-
* @param type - The type of the acquisition link (e.g., application/epub+zip or application/x-cbz).
103-
* @param openAccess - Whether the acquisition is open access.
107+
* @param type - The content type of the acquisition link (e.g., application/epub+zip or application/x-cbz).
108+
* @param aquisitionRel - The specific acquisition relation (e.g., buy, borrow, sample). OPDS acquisition relations: https://specs.opds.io/opds-1.2#521-acquisition-relations
104109
* @returns The Entry instance (for chaining).
105110
*/
106-
addAcquisition(href: string, type: string, openAccess = false) {
111+
addAcquisition(
112+
href: string,
113+
contentTtype: string,
114+
aquisitionRel?: AcquisitionRel
115+
) {
107116
return this.addLink({
108-
rel: openAccess
109-
? 'http://opds-spec.org/acquisition/open-access'
117+
rel: aquisitionRel
118+
? `http://opds-spec.org/acquisition/${aquisitionRel}`
110119
: 'http://opds-spec.org/acquisition',
111120
href,
112-
type,
121+
type: contentTtype,
113122
});
114123
}
115124

0 commit comments

Comments
 (0)