From 67dc9c546d0cb4ba2a7fef33512335aae133c015 Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Mon, 29 Jul 2024 18:41:05 +0200 Subject: [PATCH] Use mime object import See https://github.com/broofa/mime/issues/295 --- lib/index.ts | 6 +++--- lib/util/html.ts | 6 +++--- lib/util/index.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 7378777..e0e1ed8 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,6 +1,6 @@ import { render as renderTemplate } from 'ejs'; import jszip, { generateAsync, JSZipGeneratorOptions } from 'jszip'; -import { getExtension, getType } from 'mime/lite'; +import mime from 'mime/lite'; import { Chapter, chapterDefaults, Content, Font, Image, isString, NormChapter, NormOptions, Options, optionsDefaults, retryFetch, type, uuid, validateAndNormalizeChapters, validateAndNormalizeOptions, validateIsOptionsOrTitle, validateIsVarargArray } from './util'; @@ -39,8 +39,8 @@ export class EPub { if (this.options.cover) { const fname = isString(this.options.cover) ? this.options.cover : this.options.cover.name; - const mediaType = getType(fname); - const extension = getExtension(mediaType || ''); + const mediaType = mime.getType(fname); + const extension = mime.getExtension(mediaType || ''); if (mediaType && extension) this.cover = { mediaType, extension }; else this.warn('Could not detect cover image type from file', fname); diff --git a/lib/util/html.ts b/lib/util/html.ts index 01681e5..99a75cd 100644 --- a/lib/util/html.ts +++ b/lib/util/html.ts @@ -1,4 +1,4 @@ -import { getExtension, getType } from 'mime/lite'; +import mime from 'mime/lite'; import type { EPub } from '..'; import { fixHTML } from './html-parse'; import { uuid } from './other'; @@ -15,12 +15,12 @@ export type Image = { function imgSrc(this: EPub, url: string) { let image = this.images.find(i => i.url === url); if (!image) { - const mediaType = getType(url.replace(/\?.*/, "")) || ''; + const mediaType = mime.getType(url.replace(/\?.*/, "")) || ''; image = { url, mediaType, id: uuid(), - extension: getExtension(mediaType) || '', + extension: mime.getExtension(mediaType) || '', }; this.images.push(image); } diff --git a/lib/util/index.ts b/lib/util/index.ts index 70705b8..2223494 100644 --- a/lib/util/index.ts +++ b/lib/util/index.ts @@ -1,5 +1,5 @@ import { remove as removeDiacritics } from 'diacritics'; -import { getType } from 'mime/lite'; +import mime from 'mime/lite'; import slugify from 'slugify'; import chapterXHTML2 from 'templates/epub2/chapter.xhtml.ejs'; import contentOPF2 from 'templates/epub2/content.opf.ejs'; @@ -63,7 +63,7 @@ export const validateAndNormalizeOptions = (options: Options) => { ...options, } as NormOptions; opt.author = normName(opt.author); - opt.fonts = opt.fonts.map(font => ({ ...font, filename: font.filename.replace(/\s/g, '_').replace(/[^-._A-Za-z0-9]/g, ''), mediaType: getType(font.filename)! })); + opt.fonts = opt.fonts.map(font => ({ ...font, filename: font.filename.replace(/\s/g, '_').replace(/[^-._A-Za-z0-9]/g, ''), mediaType: mime.getType(font.filename)! })); opt.date = new Date(opt.date).toISOString(); opt.lang = removeDiacritics(opt.lang); return opt;