Storing example ebooks for testing.

Special handling of json mimetype for json files.

Moving types up to avoid overwriting mime.types.

Adding custom types to nginx to server ebooks better.

Displaying EBookCard correctly when ebook was not indexed correctly.

Global search can search for all ebooks (mobi/epub).

Testing when mimetype suffix is searched.

Adding eBook to global search filter list.  Opening mimetype search to match mimetypes that may not end with expected suffix.

Adding log warning to explain refresh speed.

Generating ebook covers after refresh.

Testing that another nearby book removes the cover.

Calibre covers can be discovered and associated with an ebook.

Handling if ebooklib is not yet installed.

Adding ebook table and modeler to allow searching the contents of epub files.

Marking all PDFs as un-indexed, so they will be indexed.

Replacing null characters in PDF text.

Testing PDFIndexer against example PDF file.

Installing PyPDF2 to extract text for PDFIndexer.
This commit is contained in:
Roland 2022-12-09 11:22:20 -07:00
parent d77e69f54e
commit 6fcb992540
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
21 changed files with 769 additions and 52 deletions

View file

@ -423,16 +423,24 @@ export function CardGroupCentered(props) {
</div>)
}
export function CardPosterLink({to, poster_url, imageLabel}) {
export function CardPosterLink({to, poster_url, imageLabel, external = false}) {
const {s} = useContext(ThemeContext);
const style = {display: 'flex', justifyContent: 'center', ...s['style']};
return <Link to={to} style={style}>
<Image fluid
src={poster_url}
label={imageLabel}
style={{maxHeight: '163px', width: 'auto'}}
/>
</Link>
const image = <Image fluid
src={poster_url}
label={imageLabel}
style={{maxHeight: '163px', width: 'auto'}}
/>;
if (external === true) {
return <a href={to} target='_blank' style={style}>
{image}
</a>
} else {
// Link using React Router.
return <Link to={to} style={style}>
{image}
</Link>
}
}
export function HelpPopup({icon, size, content, position}) {
@ -567,6 +575,9 @@ export function mimetypeColor(mimetype) {
return 'green'
} else if (mimetype && mimetype.startsWith('application/zip')) {
return 'purple'
} else if (mimetype && (
mimetype.startsWith('application/epub') || mimetype.startsWith('application/x-mobipocket-ebook'))) {
return 'yellow'
}
} catch (e) {
console.error(e);
@ -595,6 +606,8 @@ export function FileIcon({file, disabled = true, size = 'huge', ...props}) {
props['name'] = 'file archive';
} else if (mimetype.startsWith('application/x-iso9660-image')) {
props['name'] = 'dot circle';
} else if (mimetype.startsWith('application/epub') || mimetype.startsWith('application/x-mobipocket-ebook')) {
props['name'] = 'book';
}
}
return <Icon disabled={disabled} size={size} {...props}/>
@ -763,3 +776,19 @@ export const ColorToSemanticHexColor = (color) => {
}
return colorMap[color] || null;
}
export const filterToMimetypes = (filter) => {
if (filter === 'video') {
return ['video'];
} else if (filter === 'archive') {
return ['text/html'];
} else if (filter === 'pdf') {
return ['application/pdf'];
} else if (filter === 'ebook') {
return ['application/epub+zip', 'application/x-mobipocket-ebook'];
} else if (filter === 'image') {
return ['image'];
} else if (filter === 'zip') {
return ['application/zip'];
}
}

View file

@ -6,6 +6,7 @@ import {
CardHeader,
CardMeta,
Confirm,
Container,
Divider,
Dropdown,
Image,
@ -17,6 +18,8 @@ import 'react-keyed-file-browser/dist/react-keyed-file-browser.css';
import {deleteFile, refreshDirectoryFiles, refreshFiles} from "../api";
import {
CardGroupCentered,
CardPosterLink,
epochToDateString,
ExternalCardLink,
FileIcon,
humanFileSize,
@ -25,7 +28,6 @@ import {
PageContainer,
Paginator,
textEllipsis,
epochToDateString,
useTitle
} from "./Common";
import {useBrowseFiles, useQuery, useSearchFiles} from "../hooks/customHooks";
@ -37,6 +39,7 @@ import {ThemeContext} from "../contexts/contexts";
import {Button, Card, CardIcon, Header, Icon, Placeholder, Segment} from "./Theme";
import {SelectableTable} from "./Tables";
import {VideoCard, VideoRowCells} from "./Videos";
import _ from 'lodash';
const icons = {
File: <Icon name='file'/>,
@ -142,6 +145,42 @@ export function Files() {
</>
}
function EbookCard({file}) {
const {s} = useContext(ThemeContext);
const url = `/media/${encodeURIComponent(file.path)}`;
let {ebook, suffix} = file;
const coverSrc = ebook && ebook.cover_path ? `/media/${encodeURIComponent(ebook.cover_path)}` : null;
let cover = <CardIcon><FileIcon file={file}/></CardIcon>;
if (coverSrc) {
cover = <CardPosterLink to={url} poster_url={coverSrc} external={true}/>;
}
suffix = suffix ? _.trimStart(suffix, '.').toUpperCase() : null;
const color = mimetypeColor(file.mimetype);
return <Card color={color}>
{cover}
<CardContent {...s}>
<CardHeader>
<Container textAlign='left'>
<ExternalCardLink to={url}>{ebook ? ebook.title : file.title}</ExternalCardLink>
</Container>
</CardHeader>
<CardDescription>
<Container textAlign='left'>
<b {...s}>{ebook ? ebook.creator : null}</b>
</Container>
</CardDescription>
<CardMeta>
<p {...s}>{ebook ? humanFileSize(ebook.size) : null}</p>
<pre {...s}>{suffix}</pre>
</CardMeta>
</CardContent>
</Card>
}
function ImageCard({file}) {
const {s} = useContext(ThemeContext);
const url = `/media/${encodeURIComponent(file.path)}`;
@ -184,6 +223,10 @@ function FileCard({file}) {
return <ArchiveCard key={file['path']} file={file}/>;
} else if (file.mimetype && file.mimetype.startsWith('image/')) {
return <ImageCard key={file['path']} file={file}/>;
} else if (file.mimetype && (
file.mimetype.startsWith('application/epub') || file.mimetype.startsWith('application/x-mobipocket-ebook')
)) {
return <EbookCard key={file['path']} file={file}/>;
}
const url = `/media/${encodeURIComponent(file.path)}`;
@ -399,26 +442,27 @@ export function FilesSearchView({
showSelect = false,
emptySearch = false,
filterOptions,
mimetype,
model,
onSelect,
setFilters,
}) {
const {searchFiles, limit, setLimit, totalPages, activePage, setPage} =
useSearchFiles(24, emptySearch, mimetype, model);
filterOptions = filterOptions || [
{key: 'video', text: 'Video', value: 'video'},
{key: 'archive', text: 'Archive', value: 'archive'},
{key: 'pdf', text: 'PDF', value: 'pdf'},
{key: 'ebook', text: 'eBook', value: 'ebook'},
{key: 'image', text: 'Image', value: 'image'},
{key: 'zip', text: 'ZIP', value: 'zip'},
];
const {searchFiles, limit, setLimit, totalPages, activePage, setPage, filter} =
useSearchFiles(24, emptySearch, model);
const {searchParams, updateQuery} = useQuery();
const setView = (value) => updateQuery({view: value});
const view = searchParams.get('view');
const setMimetype = (value) => updateQuery({'mimetype': value});
filterOptions = filterOptions || [
{key: 'video', text: 'Video', value: 'video'},
{key: 'archive', text: 'Archive', value: 'text/html'},
{key: 'pdf', text: 'PDF', value: 'application/pdf'},
{key: 'zip', text: 'ZIP', value: 'application/zip'},
{key: 'image', text: 'Image', value: 'image'},
];
const setFilter = (value) => updateQuery({'filter': value});
return <FilesView
files={searchFiles}
@ -434,7 +478,7 @@ export function FilesSearchView({
onSelect={onSelect}
setPage={setPage}
filterOptions={filterOptions}
setFilters={setFilters || setMimetype}
setFilters={setFilters || setFilter}
/>
}