Skip to content

Commit 5670e26

Browse files
committed
Moved book format identifier assignment to makeBook.
1 parent 0d13f9d commit 5670e26

File tree

6 files changed

+7
-5
lines changed

6 files changed

+7
-5
lines changed

comic-book.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export const makeComicBook = ({ entries, loadBlob, getSize }, file) => {
2424
if (!files.length) throw new Error('No supported image files in archive')
2525

2626
const book = {}
27-
Object.defineProperty(book, "type", {get: () => 'comic-book'})
2827
book.getCover = () => loadBlob(files[0])
2928
book.metadata = { title: file.name }
3029
book.sections = files.map(name => ({

epub.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ export class EPUB {
930930
this.getSize = getSize
931931
this.#encryption = new Encryption(deobfuscators(sha1))
932932
}
933-
get type() { return 'epub'; }
934933
async #loadXML(uri) {
935934
const str = await this.loadText(uri)
936935
if (!str) return null

fb2.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ const dataID = 'data-foliate-id'
231231

232232
export const makeFB2 = async blob => {
233233
const book = {}
234-
Object.defineProperty(book, "type", {get: () => 'fb2'})
235234

236235
const doc = await parseXML(blob)
237236
const converter = new FB2Converter(doc)

mobi.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ class MOBI6 {
670670
constructor(mobi) {
671671
this.mobi = mobi
672672
}
673-
get type() { return 'mobi'; }
674673
async init() {
675674
// load all text records in an array
676675
let array = new Uint8Array()

pdf.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export const makePDF = async file => {
119119
}).promise
120120

121121
const book = { rendition: { layout: 'pre-paginated' } }
122-
Object.defineProperty(book, "type", {get: () => 'pdf'})
123122

124123
const { metadata, info } = await pdf.getMetadata() ?? {}
125124
// TODO: for better results, parse `metadata.getRaw()`

view.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,39 +83,46 @@ export const makeBook = async file => {
8383
const loader = await makeDirectoryLoader(file)
8484
const { EPUB } = await import('./epub.js')
8585
book = await new EPUB(loader).init()
86+
book.type = 'epub';
8687
}
8788
else if (!file.size) throw new NotFoundError('File not found')
8889
else if (await isZip(file)) {
8990
const loader = await makeZipLoader(file)
9091
if (isCBZ(file)) {
9192
const { makeComicBook } = await import('./comic-book.js')
9293
book = makeComicBook(loader, file)
94+
book.type = 'comic-book';
9395
}
9496
else if (isFBZ(file)) {
9597
const { makeFB2 } = await import('./fb2.js')
9698
const { entries } = loader
9799
const entry = entries.find(entry => entry.filename.endsWith('.fb2'))
98100
const blob = await loader.loadBlob((entry ?? entries[0]).filename)
99101
book = await makeFB2(blob)
102+
book.type = 'fb2';
100103
}
101104
else {
102105
const { EPUB } = await import('./epub.js')
103106
book = await new EPUB(loader).init()
107+
book.type = 'epub';
104108
}
105109
}
106110
else if (await isPDF(file)) {
107111
const { makePDF } = await import('./pdf.js')
108112
book = await makePDF(file)
113+
book.type = 'pdf'
109114
}
110115
else {
111116
const { isMOBI, MOBI } = await import('./mobi.js')
112117
if (await isMOBI(file)) {
113118
const fflate = await import('./vendor/fflate.js')
114119
book = await new MOBI({ unzlib: fflate.unzlibSync }).open(file)
120+
book.type = 'mobi';
115121
}
116122
else if (isFB2(file)) {
117123
const { makeFB2 } = await import('./fb2.js')
118124
book = await makeFB2(file)
125+
book.type = 'fb2';
119126
}
120127
}
121128
if (!book) throw new UnsupportedTypeError('File type not supported')

0 commit comments

Comments
 (0)