mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 21:59:58 -05:00
Add Docs module for searching and organizing PDFs and EPUBs
Create a new Docs module that consolidates PDF and eBook handling into a unified system with subjects and authors support. This replaces the separate PDF/eBook modelers with a single Doc model backed by an alembic migration (rename ebook to doc). Key changes: - New modules/docs package with models, API, extractors, and lib - Subject and author metadata extraction with case-insensitive normalization for cleaner PDF metadata - Frontend Docs pages with AuthorsPage, SubjectsPage using CollectionTable, and doc card deletion - Global search integration for subjects and authors - Generic collection item count support - Frontend file card metadata adjusted to match collection sort - Bump yt-dlp version
This commit is contained in:
parent
4a21499bdd
commit
aefc7b1def
90 changed files with 4484 additions and 1189 deletions
|
|
@ -346,6 +346,8 @@ function ArchivePage() {
|
|||
|
||||
export function ArchiveCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
const {sort} = useSearchOrder();
|
||||
const sortField = sort ? sort.replace(/^-/, '') : null;
|
||||
const {data, directory} = file;
|
||||
|
||||
// Resolve data paths (filename-only) to full relative paths using directory
|
||||
|
|
@ -386,7 +388,16 @@ export function ArchiveCard({file}) {
|
|||
<span {...s}>{domain}</span>
|
||||
</CardLink>}
|
||||
<CardMeta {...s}>
|
||||
{isoDatetimeToAgoPopup(dt, false)}
|
||||
{sortField === 'published_modified_datetime'
|
||||
? isoDatetimeToAgoPopup(file.published_modified_datetime, false)
|
||||
: sortField === 'download_datetime'
|
||||
? isoDatetimeToAgoPopup(file.download_datetime, false)
|
||||
: sortField === 'size'
|
||||
? humanFileSize(file.size)
|
||||
: sortField === 'viewed'
|
||||
? isoDatetimeToAgoPopup(file.viewed, false)
|
||||
: isoDatetimeToAgoPopup(dt, false)
|
||||
}
|
||||
</CardMeta>
|
||||
<CardDescription>
|
||||
<Link to={`/archive/${data.id}`}>
|
||||
|
|
|
|||
152
app/src/components/CbzViewer.js
Normal file
152
app/src/components/CbzViewer.js
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
import React, {useCallback, useEffect, useRef, useState} from 'react';
|
||||
import {getArchiveContents, getArchiveMemberUrl} from '../api';
|
||||
import {Icon, Label, Loader, Message} from 'semantic-ui-react';
|
||||
import {Button} from './Theme';
|
||||
import {useLocalStorage} from './Common';
|
||||
|
||||
const IMAGE_EXTENSIONS = /\.(jpe?g|png|gif|webp|bmp|tiff?)$/i;
|
||||
|
||||
/**
|
||||
* Recursively flatten archive tree entries into a list of file paths.
|
||||
*/
|
||||
function flattenEntries(entries, prefix = '') {
|
||||
let paths = [];
|
||||
for (const entry of entries) {
|
||||
const fullPath = entry.path || (prefix ? `${prefix}/${entry.name}` : entry.name);
|
||||
if (entry.is_dir && entry.children) {
|
||||
paths = paths.concat(flattenEntries(entry.children, fullPath));
|
||||
} else if (!entry.is_dir) {
|
||||
paths.push(fullPath);
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
export function CbzViewer({path}) {
|
||||
const [pages, setPages] = useState(null);
|
||||
const [currentPage, setCurrentPage] = useState(0);
|
||||
const [rtl, setRtl] = useLocalStorage('cbzViewerRtl', false);
|
||||
const [fullscreen, setFullscreen] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const load = async () => {
|
||||
try {
|
||||
const contents = await getArchiveContents(path);
|
||||
if (!contents) {
|
||||
setError('Could not read archive contents.');
|
||||
return;
|
||||
}
|
||||
const images = flattenEntries(contents.entries)
|
||||
.filter(name => IMAGE_EXTENSIONS.test(name))
|
||||
.sort();
|
||||
const urls = images.map(member => getArchiveMemberUrl(path, member));
|
||||
setPages(urls);
|
||||
setCurrentPage(0);
|
||||
} catch (e) {
|
||||
setError(e.message || 'Could not read archive contents.');
|
||||
}
|
||||
};
|
||||
load();
|
||||
}, [path]);
|
||||
|
||||
const goNext = useCallback(() => {
|
||||
setCurrentPage(p => Math.min(p + 1, (pages?.length || 1) - 1));
|
||||
}, [pages]);
|
||||
|
||||
const goPrev = useCallback(() => {
|
||||
setCurrentPage(p => Math.max(p - 1, 0));
|
||||
}, []);
|
||||
|
||||
const onLeftClick = rtl ? goNext : goPrev;
|
||||
const onRightClick = rtl ? goPrev : goNext;
|
||||
const imageContainerRef = useRef(null);
|
||||
|
||||
const handleFullscreen = useCallback(() => {
|
||||
setFullscreen(f => !f);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKey = (e) => {
|
||||
if (e.key === 'ArrowLeft') onLeftClick();
|
||||
else if (e.key === 'ArrowRight') onRightClick();
|
||||
else if (e.key === 'Escape') setFullscreen(false);
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [onLeftClick, onRightClick]);
|
||||
|
||||
if (error) {
|
||||
return <Message negative>
|
||||
<Message.Header>Cannot load comic</Message.Header>
|
||||
<p>{error}</p>
|
||||
</Message>;
|
||||
}
|
||||
if (!pages) return <Loader active inline='centered'/>;
|
||||
if (pages.length === 0) {
|
||||
return <Message warning>
|
||||
<Message.Header>No images found</Message.Header>
|
||||
<p>This archive does not contain any image files.</p>
|
||||
</Message>;
|
||||
}
|
||||
|
||||
const hasPrev = currentPage > 0;
|
||||
const hasNext = currentPage < pages.length - 1;
|
||||
|
||||
return <div style={{marginBottom: '1em'}}>
|
||||
<div ref={imageContainerRef} style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
background: '#222',
|
||||
borderRadius: fullscreen ? 0 : '4px',
|
||||
padding: '0.5em',
|
||||
minHeight: '300px',
|
||||
position: fullscreen ? 'fixed' : 'relative',
|
||||
...(fullscreen ? {top: 0, left: 0, right: 0, bottom: 0, zIndex: 9999} : {}),
|
||||
}}>
|
||||
<img
|
||||
src={pages[currentPage]}
|
||||
alt={`Page ${currentPage + 1}`}
|
||||
style={{
|
||||
maxHeight: fullscreen ? '100vh' : '75vh',
|
||||
maxWidth: '100%',
|
||||
objectFit: 'contain',
|
||||
}}
|
||||
/>
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
top: 0, left: 0, right: 0, bottom: 0,
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr 1fr',
|
||||
}}>
|
||||
<div style={{cursor: 'pointer'}} onClick={onLeftClick}/>
|
||||
<div style={{cursor: 'pointer'}} onClick={handleFullscreen}/>
|
||||
<div style={{cursor: 'pointer'}} onClick={onRightClick}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
gap: '0.5em',
|
||||
marginTop: '0.5em',
|
||||
}}>
|
||||
<Button icon basic active={rtl} onClick={() => setRtl(r => !r)}
|
||||
aria-label='Reading direction'>
|
||||
<Icon name={rtl ? 'hand point left' : 'hand point right'}/>
|
||||
</Button>
|
||||
<span style={{flex: 1}}/>
|
||||
<Button icon basic disabled={rtl ? !hasNext : !hasPrev}
|
||||
onClick={onLeftClick} aria-label='Previous page'>
|
||||
<Icon name='chevron left'/>
|
||||
</Button>
|
||||
<Label>{currentPage + 1} / {pages.length}</Label>
|
||||
<Button icon basic disabled={rtl ? !hasPrev : !hasNext}
|
||||
onClick={onRightClick} aria-label='Next page'>
|
||||
<Icon name='chevron right'/>
|
||||
</Button>
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ import {
|
|||
Search,
|
||||
Transition
|
||||
} from 'semantic-ui-react';
|
||||
import {Link, NavLink, useNavigate, useSearchParams} from "react-router";
|
||||
import {Link, NavLink, useNavigate} from "react-router";
|
||||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
import {useHotspot, useSearchDirectories, useSearchOrder, useThrottle, useWROLMode} from "../hooks/customHooks";
|
||||
import {Media, SettingsContext, StatusContext, ThemeContext} from "../contexts/contexts";
|
||||
|
|
@ -701,15 +701,9 @@ export function textEllipsis(str, maxLength = 100, {side = "end", ellipsis = "..
|
|||
}
|
||||
|
||||
export function TabLinks({links}) {
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const getTo = (to) => {
|
||||
return `${to}?${searchParams.toString()}`;
|
||||
}
|
||||
|
||||
return <Menu tabular>
|
||||
{links.map((link) => <NavLink
|
||||
to={getTo(link.to)}
|
||||
to={link.to}
|
||||
style={{padding: '1em'}}
|
||||
key={link.to}
|
||||
end={link.end === true ? true : null}
|
||||
|
|
@ -1084,11 +1078,12 @@ export function emptyToNull(obj) {
|
|||
return obj;
|
||||
}
|
||||
|
||||
export function mimetypeColor(mimetype) {
|
||||
export function mimetypeColor(mimetype, path = '') {
|
||||
if (!mimetype) {
|
||||
return 'grey';
|
||||
}
|
||||
try {
|
||||
const lowerPath = path.toLowerCase();
|
||||
if (mimetype === 'application/pdf') {
|
||||
return 'red'
|
||||
} else if (mimetype.startsWith('video/')) {
|
||||
|
|
@ -1099,6 +1094,11 @@ export function mimetypeColor(mimetype) {
|
|||
return 'green'
|
||||
} else if (mimetype.startsWith('application/epub')) {
|
||||
return 'yellow'
|
||||
} else if (mimetype.includes('cbz') || mimetype.includes('cbr')
|
||||
|| mimetype.includes('comicbook')
|
||||
|| lowerPath.endsWith('.cbz') || lowerPath.endsWith('.cbr')
|
||||
|| lowerPath.endsWith('.cbt') || lowerPath.endsWith('.cb7')) {
|
||||
return 'yellow'
|
||||
} else if (mimetype.startsWith('audio/')) {
|
||||
return 'violet'
|
||||
} else if (isZipMimetype(mimetype)) {
|
||||
|
|
@ -1142,7 +1142,8 @@ export function mimetypeIconName(mimetype, lowerPath = '') {
|
|||
return 'file archive';
|
||||
} else if (mimetype.startsWith('application/x-iso9660-image') || mimetype.startsWith('application/x-raw-disk-image') || mimetype.startsWith('application/x-cd-image')) {
|
||||
return 'dot circle';
|
||||
} else if (mimetype.startsWith('application/epub') || mimetype.startsWith('application/x-mobipocket-ebook') || mimetype.startsWith('application/vnd.amazon.mobi8-ebook')) {
|
||||
} else if (mimetype.startsWith('application/epub') || mimetype.startsWith('application/x-mobipocket-ebook') || mimetype.startsWith('application/vnd.amazon.mobi8-ebook')
|
||||
|| mimetype.startsWith('application/vnd.comicbook') || mimetype.startsWith('application/x-cbz') || mimetype.startsWith('application/x-cbr')) {
|
||||
return 'book';
|
||||
} else if (mimetype.startsWith('text/vtt') || mimetype.startsWith('text/srt')) {
|
||||
return 'closed captioning';
|
||||
|
|
@ -1527,6 +1528,10 @@ export const filterToMimetypes = (filter) => {
|
|||
return ['audio'];
|
||||
} else if (filter === 'ebook') {
|
||||
return ['application/epub+zip', 'application/x-mobipocket-ebook'];
|
||||
} else if (filter === 'doc') {
|
||||
return ['application/epub+zip', 'application/x-mobipocket-ebook', 'application/pdf',
|
||||
'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/vnd.oasis.opendocument.text', 'application/x-cbz', 'application/x-cbr'];
|
||||
} else if (filter === 'image') {
|
||||
return ['image'];
|
||||
} else if (filter === 'zip') {
|
||||
|
|
|
|||
532
app/src/components/Docs.js
Normal file
532
app/src/components/Docs.js
Normal file
|
|
@ -0,0 +1,532 @@
|
|||
import React, {useContext, useEffect, useState} from 'react';
|
||||
import {Link, Route, Routes, useLocation, useNavigate, useParams} from "react-router";
|
||||
import {Grid, Icon as SIcon, Label, Loader, StatisticLabel, StatisticValue} from "semantic-ui-react";
|
||||
import {deleteDocs, getDocStatistics, tagFileGroup, untagFileGroup} from "../api";
|
||||
import {Media, ThemeContext} from "../contexts/contexts";
|
||||
import {
|
||||
APIButton,
|
||||
BackButton,
|
||||
encodeMediaPath,
|
||||
ErrorMessage,
|
||||
humanFileSize,
|
||||
isoDatetimeToAgoPopup,
|
||||
PageContainer,
|
||||
PreviewPath,
|
||||
SearchInput,
|
||||
SortButton,
|
||||
TabLinks,
|
||||
toLocaleString,
|
||||
useTitle
|
||||
} from "./Common";
|
||||
import {Button, darkTheme, Header, Icon, Segment, Statistic, Tab} from "./Theme";
|
||||
import {FilesView} from "./Files";
|
||||
import {useAuthors, useDoc, useOneQuery, useSearchDocs, useSubjects} from "../hooks/customHooks";
|
||||
import {TagsSelector} from "../Tags";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import {CollectionTable} from "./collections/CollectionTable";
|
||||
import {CbzViewer} from "./CbzViewer";
|
||||
import _ from "lodash";
|
||||
|
||||
function DocsPage() {
|
||||
useTitle('Documents');
|
||||
const searchInputRef = React.useRef();
|
||||
|
||||
const {
|
||||
docs,
|
||||
totalPages,
|
||||
activePage,
|
||||
setPage,
|
||||
searchStr,
|
||||
setSearchStr,
|
||||
author,
|
||||
subject,
|
||||
fetchDocs,
|
||||
} = useSearchDocs();
|
||||
|
||||
const [selectedDocs, setSelectedDocs] = useState([]);
|
||||
|
||||
const onSelect = (path, checked) => {
|
||||
if (checked && path) {
|
||||
setSelectedDocs([...selectedDocs, path]);
|
||||
} else if (path) {
|
||||
setSelectedDocs(selectedDocs.filter(i => i !== path));
|
||||
}
|
||||
}
|
||||
|
||||
const onDelete = async () => {
|
||||
const docIds = docs.filter(i => selectedDocs.indexOf(i['primary_path']) >= 0).map(i => i['id']);
|
||||
await deleteDocs(docIds);
|
||||
await fetchDocs();
|
||||
setSelectedDocs([]);
|
||||
}
|
||||
|
||||
const invertSelection = () => {
|
||||
const newSelectedDocs = docs.map(doc => doc['key']).filter(i => selectedDocs.indexOf(i) < 0);
|
||||
setSelectedDocs(newSelectedDocs);
|
||||
}
|
||||
|
||||
const clearSelection = (e) => {
|
||||
if (e) e.preventDefault();
|
||||
setSelectedDocs([]);
|
||||
}
|
||||
|
||||
const selectElm = <div style={{marginTop: '0.5em'}}>
|
||||
<APIButton
|
||||
color='red'
|
||||
disabled={_.isEmpty(selectedDocs)}
|
||||
confirmButton='Delete'
|
||||
confirmContent='Are you sure you want to delete these documents? This cannot be undone.'
|
||||
onClick={onDelete}
|
||||
obeyWROLMode={true}
|
||||
>Delete</APIButton>
|
||||
<Button color='grey' onClick={invertSelection} disabled={_.isEmpty(docs)}>Invert</Button>
|
||||
<Button color='yellow' onClick={clearSelection}
|
||||
disabled={_.isEmpty(docs) || _.isEmpty(selectedDocs)}>Clear</Button>
|
||||
</div>;
|
||||
|
||||
let docOrders = [
|
||||
{value: 'published_datetime', text: 'Published Date', short: 'P.Date'},
|
||||
{value: 'size', text: 'Size'},
|
||||
{value: 'title', text: 'Title'},
|
||||
];
|
||||
if (searchStr) {
|
||||
docOrders = [{value: 'rank', text: 'Rank'}, ...docOrders];
|
||||
}
|
||||
|
||||
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
|
||||
{
|
||||
files: docs,
|
||||
activePage: activePage,
|
||||
totalPages: totalPages,
|
||||
selectElem: selectElm,
|
||||
selectedKeys: selectedDocs,
|
||||
onSelect: onSelect,
|
||||
setPage: setPage,
|
||||
},
|
||||
);
|
||||
|
||||
const [localSearchStr, setLocalSearchStr] = React.useState(searchStr || '');
|
||||
const searchInput = <SearchInput
|
||||
onChange={setLocalSearchStr}
|
||||
onClear={() => setLocalSearchStr(null)}
|
||||
searchStr={localSearchStr}
|
||||
onSubmit={setSearchStr}
|
||||
placeholder='Search Documents...'
|
||||
inputRef={searchInputRef}
|
||||
/>;
|
||||
|
||||
return <>
|
||||
{author && <Header as='h1'>Author: {author}</Header>}
|
||||
{subject && <Header as='h1'>Subject: {subject}</Header>}
|
||||
<Media at='mobile'>
|
||||
<Grid>
|
||||
<Grid.Row>
|
||||
<Grid.Column width={2}>{selectButton}</Grid.Column>
|
||||
<Grid.Column width={2}>{viewButton}</Grid.Column>
|
||||
<Grid.Column width={4}>{limitDropdown}</Grid.Column>
|
||||
<Grid.Column width={2}>{tagQuerySelector}</Grid.Column>
|
||||
<Grid.Column width={6}><SortButton sorts={docOrders}/></Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row width={16}>
|
||||
<Grid.Column>{searchInput}</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Media>
|
||||
<Media greaterThanOrEqual='tablet'>
|
||||
<Grid>
|
||||
<Grid.Row>
|
||||
<Grid.Column width={1}>{selectButton}</Grid.Column>
|
||||
<Grid.Column width={1}>{viewButton}</Grid.Column>
|
||||
<Grid.Column width={2}>{limitDropdown}</Grid.Column>
|
||||
<Grid.Column width={1}>{tagQuerySelector}</Grid.Column>
|
||||
<Grid.Column width={3}><SortButton sorts={docOrders}/></Grid.Column>
|
||||
<Grid.Column width={8}>{searchInput}</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Media>
|
||||
{body}
|
||||
{paginator}
|
||||
</>;
|
||||
}
|
||||
|
||||
function DocPage() {
|
||||
const {fileGroupId} = useParams();
|
||||
const navigate = useNavigate();
|
||||
const {docFile, doc, fetchDoc} = useDoc(parseInt(fileGroupId));
|
||||
const {theme} = useContext(ThemeContext);
|
||||
|
||||
const title = docFile ? (docFile.title || docFile.name) : null;
|
||||
useTitle(title);
|
||||
|
||||
if (docFile === null) {
|
||||
return <Segment><Loader active/></Segment>;
|
||||
}
|
||||
if (docFile === undefined) {
|
||||
return <>
|
||||
<Header as='h2'>Unknown document</Header>
|
||||
<Header as='h4'>This document does not exist</Header>
|
||||
</>;
|
||||
}
|
||||
|
||||
const {data, size, directory} = docFile;
|
||||
|
||||
// Cover image.
|
||||
const coverPath = data && data.cover_path ? data.cover_path : null;
|
||||
const coverUrl = coverPath ? `/media/${encodeMediaPath(coverPath)}` : null;
|
||||
|
||||
// Primary file URLs.
|
||||
const primaryPath = docFile.primary_path;
|
||||
const downloadUrl = primaryPath ? `/download/${encodeMediaPath(primaryPath)}` : null;
|
||||
const isEpub = docFile.mimetype && docFile.mimetype.startsWith('application/epub');
|
||||
const mt = docFile.mimetype || '';
|
||||
const primaryExt = (primaryPath || '').toLowerCase().split('.').pop();
|
||||
const isCbz = mt.includes('cbz') || mt.includes('cbr') || mt.includes('comicbook+zip') || mt.includes('comicbook-rar')
|
||||
|| ['cbz', 'cbr', 'cbt', 'cb7'].includes(primaryExt);
|
||||
const viewerUrl = isEpub ? `/epub/epub.html?url=${downloadUrl}` : null;
|
||||
const openUrl = viewerUrl || (primaryPath ? `/media/${encodeMediaPath(primaryPath)}` : null);
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (doc && doc.id) {
|
||||
await deleteDocs([doc.id]);
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Document Deleted',
|
||||
description: 'Document was successfully deleted.',
|
||||
time: 2000,
|
||||
});
|
||||
navigate(-1);
|
||||
}
|
||||
};
|
||||
|
||||
const localAddTag = async (name) => {
|
||||
await tagFileGroup(docFile, name);
|
||||
await fetchDoc();
|
||||
};
|
||||
|
||||
const localRemoveTag = async (name) => {
|
||||
await untagFileGroup(docFile, name);
|
||||
await fetchDoc();
|
||||
};
|
||||
|
||||
const publishedDatetimeString = docFile.published_datetime
|
||||
? isoDatetimeToAgoPopup(docFile.published_datetime, true)
|
||||
: null;
|
||||
|
||||
// Format badge based on mimetype.
|
||||
const formatLabel = () => {
|
||||
const mt = docFile.mimetype || '';
|
||||
if (mt.startsWith('application/epub')) return 'EPUB';
|
||||
if (mt === 'application/x-mobipocket-ebook') return 'MOBI';
|
||||
if (mt === 'application/pdf') return 'PDF';
|
||||
if (mt.includes('wordprocessingml')) return 'DOCX';
|
||||
if (mt === 'application/msword') return 'DOC';
|
||||
if (mt.includes('opendocument.text')) return 'ODT';
|
||||
if (mt.includes('cbz') || mt.includes('comicbook+zip')) return 'CBZ';
|
||||
if (mt.includes('cbr') || mt.includes('comicbook-rar')) return 'CBR';
|
||||
if (mt.includes('cbt')) return 'CBT';
|
||||
if (mt.includes('cb7') || mt.includes('x-7z')) return 'CB7';
|
||||
return mt.split('/').pop().toUpperCase();
|
||||
};
|
||||
|
||||
// About pane.
|
||||
const aboutPane = {
|
||||
menuItem: 'About', render: () => <Tab.Pane>
|
||||
{doc && doc.description && <>
|
||||
<Header as='h3'>Description</Header>
|
||||
<p>{doc.description}</p>
|
||||
</>}
|
||||
|
||||
{doc && doc.publisher && <>
|
||||
<Header as='h3'>Publisher</Header>
|
||||
<p>{doc.publisher}</p>
|
||||
</>}
|
||||
|
||||
{doc && doc.language && <>
|
||||
<Header as='h3'>Language</Header>
|
||||
<p>{doc.language}</p>
|
||||
</>}
|
||||
|
||||
{doc && doc.subject && <>
|
||||
<Header as='h3'>Subject</Header>
|
||||
<p><Link to={`/docs?subject=${encodeURIComponent(doc.subject)}`}>{doc.subject}</Link></p>
|
||||
</>}
|
||||
|
||||
{doc && doc.page_count && <>
|
||||
<Header as='h3'>Page Count</Header>
|
||||
<p>{doc.page_count}</p>
|
||||
</>}
|
||||
|
||||
<Header as='h3'>Size</Header>
|
||||
<p>{humanFileSize(size)}</p>
|
||||
</Tab.Pane>
|
||||
};
|
||||
|
||||
// Files pane.
|
||||
const filesPane = {
|
||||
menuItem: 'Files', render: () => <Tab.Pane>
|
||||
{docFile.files && docFile.files.map((file, idx) =>
|
||||
<div key={idx} style={{marginBottom: '0.5em'}}>
|
||||
<PreviewPath path={file.path} mimetype={file.mimetype} taggable={false}>
|
||||
{file.path}
|
||||
</PreviewPath>
|
||||
{file.size && <span style={{marginLeft: '1em', color: 'grey'}}>
|
||||
({humanFileSize(file.size)})
|
||||
</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Header as='h3'>Directory</Header>
|
||||
<p>{directory || 'Unknown'}</p>
|
||||
</Tab.Pane>
|
||||
};
|
||||
|
||||
const tabPanes = [aboutPane, filesPane];
|
||||
const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true};
|
||||
|
||||
// Inline reader: epub viewer iframe or PDF iframe.
|
||||
const isPdf = docFile.mimetype === 'application/pdf';
|
||||
const canEmbed = isEpub || isPdf;
|
||||
const embedUrl = isEpub ? viewerUrl : (isPdf && primaryPath ? `/media/${encodeMediaPath(primaryPath)}` : null);
|
||||
|
||||
return <>
|
||||
<BackButton/>
|
||||
|
||||
{isCbz && primaryPath && <CbzViewer path={primaryPath}/>}
|
||||
|
||||
{canEmbed && embedUrl && !isCbz && <div style={{marginBottom: '1em'}}>
|
||||
<iframe
|
||||
src={embedUrl}
|
||||
title={docFile.title || docFile.name}
|
||||
style={{width: '100%', height: '80vh', border: '1px solid #ccc', borderRadius: '4px'}}
|
||||
/>
|
||||
</div>}
|
||||
|
||||
<Segment>
|
||||
<Header as='h2'>{docFile.title || docFile.name}</Header>
|
||||
|
||||
{docFile.author && <Header as='h3'>
|
||||
Author: <Link to={`/docs?author=${encodeURIComponent(docFile.author)}`}>{docFile.author}</Link>
|
||||
</Header>}
|
||||
|
||||
<Grid columns={2} stackable>
|
||||
<Grid.Row>
|
||||
{publishedDatetimeString && <Grid.Column>
|
||||
<Header as='h4'>Published: {publishedDatetimeString}</Header>
|
||||
</Grid.Column>}
|
||||
<Grid.Column>
|
||||
<Label>{formatLabel()}</Label>
|
||||
{doc && doc.page_count && <Label>{doc.page_count} pages</Label>}
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
||||
<div style={{marginTop: '1em'}}>
|
||||
{openUrl && <Button as='a' href={openUrl} target='_blank' rel='noreferrer' color='violet'>
|
||||
<SIcon name='expand arrows alternate'/> Open
|
||||
</Button>}
|
||||
{downloadUrl && <Button as='a' href={downloadUrl}>
|
||||
<SIcon name='download'/> Download
|
||||
</Button>}
|
||||
<APIButton
|
||||
color='red'
|
||||
confirmContent='Are you sure you want to delete this document? All files will be deleted.'
|
||||
confirmButton='Delete'
|
||||
onClick={handleDelete}
|
||||
obeyWROLMode={true}
|
||||
>Delete</APIButton>
|
||||
</div>
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<TagsSelector selectedTagNames={docFile.tags} onAdd={localAddTag} onRemove={localRemoveTag}/>
|
||||
</Segment>
|
||||
|
||||
<Tab menu={tabMenu} panes={tabPanes}/>
|
||||
</>;
|
||||
}
|
||||
|
||||
const AUTHOR_COLUMNS = [
|
||||
{key: 'name', label: 'Author', sortable: true, width: 10},
|
||||
{key: 'item_count', label: 'Documents', sortable: true, align: 'right', width: 6},
|
||||
];
|
||||
|
||||
const AUTHOR_ROUTES = {
|
||||
search: '/docs',
|
||||
searchParam: 'author',
|
||||
};
|
||||
|
||||
const SUBJECT_COLUMNS = [
|
||||
{key: 'name', label: 'Subject', sortable: true, width: 10},
|
||||
{key: 'item_count', label: 'Documents', sortable: true, align: 'right', width: 6},
|
||||
];
|
||||
|
||||
const SUBJECT_ROUTES = {
|
||||
search: '/docs',
|
||||
searchParam: 'subject',
|
||||
};
|
||||
|
||||
function AuthorsPage() {
|
||||
useTitle('Doc Authors');
|
||||
|
||||
const [authors] = useAuthors();
|
||||
const [searchStr, setSearchStr] = useOneQuery('author');
|
||||
const searchInputRef = React.useRef();
|
||||
|
||||
const header = <div style={{marginBottom: '1em'}}>
|
||||
<Grid stackable columns={2}>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<SearchInput
|
||||
placeholder='Author filter...'
|
||||
size='large'
|
||||
searchStr={searchStr}
|
||||
disabled={!Array.isArray(authors) || authors.length === 0}
|
||||
onClear={() => setSearchStr('')}
|
||||
onChange={setSearchStr}
|
||||
onSubmit={null}
|
||||
inputRef={searchInputRef}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</div>;
|
||||
|
||||
return <>
|
||||
{header}
|
||||
<CollectionTable
|
||||
collections={authors}
|
||||
columns={AUTHOR_COLUMNS}
|
||||
routes={AUTHOR_ROUTES}
|
||||
searchStr={searchStr}
|
||||
emptyMessage='No authors found. Index some documents with author metadata!'
|
||||
/>
|
||||
</>;
|
||||
}
|
||||
|
||||
function SubjectsPage() {
|
||||
useTitle('Doc Subjects');
|
||||
|
||||
const [subjects] = useSubjects();
|
||||
const [searchStr, setSearchStr] = useOneQuery('subject');
|
||||
const searchInputRef = React.useRef();
|
||||
|
||||
const header = <div style={{marginBottom: '1em'}}>
|
||||
<Grid stackable columns={2}>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<SearchInput
|
||||
placeholder='Subject filter...'
|
||||
size='large'
|
||||
searchStr={searchStr}
|
||||
disabled={!Array.isArray(subjects) || subjects.length === 0}
|
||||
onClear={() => setSearchStr('')}
|
||||
onChange={setSearchStr}
|
||||
onSubmit={null}
|
||||
inputRef={searchInputRef}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</div>;
|
||||
|
||||
return <>
|
||||
{header}
|
||||
<CollectionTable
|
||||
collections={subjects}
|
||||
columns={SUBJECT_COLUMNS}
|
||||
routes={SUBJECT_ROUTES}
|
||||
searchStr={searchStr}
|
||||
emptyMessage='No subjects found. Index some documents with subject metadata!'
|
||||
/>
|
||||
</>;
|
||||
}
|
||||
|
||||
function DocsStatisticsPage() {
|
||||
useTitle('Doc Statistics');
|
||||
|
||||
const [statistics, setStatistics] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
const response = await getDocStatistics();
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setStatistics(data.statistics);
|
||||
}
|
||||
} catch (e) {
|
||||
setStatistics(undefined);
|
||||
}
|
||||
};
|
||||
fetchStats();
|
||||
}, []);
|
||||
|
||||
if (statistics === null) {
|
||||
return <Loader active inline='centered'/>;
|
||||
}
|
||||
if (statistics === undefined) {
|
||||
return <ErrorMessage>Unable to fetch Doc Statistics</ErrorMessage>;
|
||||
}
|
||||
|
||||
return <Segment>
|
||||
<Header as='h1' textAlign='center'>Documents</Header>
|
||||
<Statistic.Group>
|
||||
<Statistic style={{margin: '2em'}}>
|
||||
<StatisticValue>{toLocaleString(statistics.doc_count)}</StatisticValue>
|
||||
<StatisticLabel>Documents</StatisticLabel>
|
||||
</Statistic>
|
||||
<Statistic style={{margin: '2em'}}>
|
||||
<StatisticValue>{toLocaleString(statistics.epub_count)}</StatisticValue>
|
||||
<StatisticLabel>eBooks</StatisticLabel>
|
||||
</Statistic>
|
||||
<Statistic style={{margin: '2em'}}>
|
||||
<StatisticValue>{toLocaleString(statistics.pdf_count)}</StatisticValue>
|
||||
<StatisticLabel>PDFs</StatisticLabel>
|
||||
</Statistic>
|
||||
<Statistic style={{margin: '2em'}}>
|
||||
<StatisticValue>{toLocaleString(statistics.other_count)}</StatisticValue>
|
||||
<StatisticLabel>Other</StatisticLabel>
|
||||
</Statistic>
|
||||
<Statistic style={{margin: '2em'}}>
|
||||
<StatisticValue>{humanFileSize(statistics.total_size)}</StatisticValue>
|
||||
<StatisticLabel>Total Size</StatisticLabel>
|
||||
</Statistic>
|
||||
<Statistic style={{margin: '2em'}}>
|
||||
<StatisticValue>{toLocaleString(statistics.author_count)}</StatisticValue>
|
||||
<StatisticLabel>Authors</StatisticLabel>
|
||||
</Statistic>
|
||||
<Statistic style={{margin: '2em'}}>
|
||||
<StatisticValue>{toLocaleString(statistics.subject_count)}</StatisticValue>
|
||||
<StatisticLabel>Subjects</StatisticLabel>
|
||||
</Statistic>
|
||||
</Statistic.Group>
|
||||
</Segment>;
|
||||
}
|
||||
|
||||
export function DocsRoute() {
|
||||
const location = useLocation();
|
||||
const path = location.pathname;
|
||||
|
||||
const links = [
|
||||
{
|
||||
text: 'Docs',
|
||||
to: '/docs',
|
||||
end: true,
|
||||
isActive: () => path === '/docs' || /^\/docs\/view\/\d+$/.test(path)
|
||||
},
|
||||
{text: 'Subjects', to: '/docs/subjects', isActive: () => path.startsWith('/docs/subjects')},
|
||||
{text: 'Authors', to: '/docs/authors', isActive: () => path.startsWith('/docs/authors')},
|
||||
{text: 'Statistics', to: '/docs/statistics'},
|
||||
];
|
||||
|
||||
return <PageContainer>
|
||||
<TabLinks links={links}/>
|
||||
<Routes>
|
||||
<Route path='/' element={<DocsPage/>}/>
|
||||
<Route path='view/:fileGroupId' element={<DocPage/>}/>
|
||||
<Route path='subjects' element={<SubjectsPage/>}/>
|
||||
<Route path='authors' element={<AuthorsPage/>}/>
|
||||
<Route path='statistics' element={<DocsStatisticsPage/>}/>
|
||||
</Routes>
|
||||
</PageContainer>;
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import {Media} from "../contexts/contexts";
|
|||
import {encodeMediaPath, isSupportedArchive} from "./Common";
|
||||
import {getFile, tagFileGroup, untagFileGroup} from "../api";
|
||||
import {ArchivePreviewContent} from "./ArchivePreview";
|
||||
import {CbzViewer} from "./CbzViewer";
|
||||
import {StlViewer} from "react-stl-viewer";
|
||||
import {Button, Modal} from "./Theme";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
|
|
@ -361,6 +362,9 @@ export function FilePreviewProvider({children}) {
|
|||
setModalContent(getAudioPreviewModal(previewFile), url, downloadURL, path, taggable);
|
||||
} else if (mimetype.startsWith('application/octet-stream') && lowerPath.endsWith('.stl')) {
|
||||
setModalContent(getSTLPreviewModal(previewFile), null, downloadURL, path, taggable);
|
||||
} else if (mimetype.includes('cbz') || mimetype.includes('cbr') || mimetype.includes('comicbook+zip') || mimetype.includes('comicbook-rar')
|
||||
|| lowerPath.endsWith('.cbz') || lowerPath.endsWith('.cbr') || lowerPath.endsWith('.cbt') || lowerPath.endsWith('.cb7')) {
|
||||
setModalContent(<Modal.Content><CbzViewer path={path}/></Modal.Content>, null, downloadURL, path, taggable);
|
||||
} else if (isSupportedArchive(mimetype, lowerPath)) {
|
||||
setModalContent(<ArchivePreviewContent previewFile={previewFile}/>, null, downloadURL, path, taggable);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -37,12 +37,13 @@ import {
|
|||
usePages,
|
||||
useSearchFiles,
|
||||
useSearchFilter,
|
||||
useSearchOrder,
|
||||
useSearchView,
|
||||
useStatusFlag,
|
||||
useWROLMode
|
||||
} from "../hooks/customHooks";
|
||||
import {useFileWorkerStatus} from "../contexts/FileWorkerStatusContext";
|
||||
import {Route, Routes} from "react-router";
|
||||
import {Link, Route, Routes} from "react-router";
|
||||
import {CardPlaceholder} from "./Placeholder";
|
||||
import {ArchiveCard, ArchiveRowCells} from "./Archive";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
|
|
@ -66,20 +67,23 @@ import {Headlines} from "./Headline";
|
|||
import {useSearch} from "./Search";
|
||||
import {FILES_MEDIA_URI} from "./Vars";
|
||||
|
||||
function EbookCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
function EbookCard({file, sortField}) {
|
||||
const {s, t} = useContext(ThemeContext);
|
||||
|
||||
const downloadUrl = `/download/${encodeMediaPath(file.primary_path)}`;
|
||||
const isEpub = file['mimetype'].startsWith('application/epub');
|
||||
const isEpub = file['mimetype'] && file['mimetype'].startsWith('application/epub');
|
||||
const viewerUrl = isEpub ? `/epub/epub.html?url=${downloadUrl}` : null;
|
||||
|
||||
const color = mimetypeColor(file.mimetype);
|
||||
// Link to doc detail page if this is a modeled doc.
|
||||
const detailUrl = file.model === 'doc' ? `/docs/view/${file.id}` : null;
|
||||
|
||||
const color = mimetypeColor(file.mimetype, file.primary_path);
|
||||
const title = file.title || file.stem || file.name;
|
||||
const header = <ExternalCardLink to={viewerUrl || downloadUrl} className='card-title-ellipsis'>
|
||||
{title}
|
||||
</ExternalCardLink>;
|
||||
const header = detailUrl
|
||||
? <Link to={detailUrl} className='no-link-underscore card-link card-title-ellipsis' {...t}>{title}</Link>
|
||||
: <ExternalCardLink to={viewerUrl || downloadUrl} className='card-title-ellipsis'>{title}</ExternalCardLink>;
|
||||
return <Card color={color}>
|
||||
<CardPoster file={file} preview={true}/>
|
||||
<CardPoster file={file} to={detailUrl}/>
|
||||
<CardContent {...s}>
|
||||
<CardHeader>
|
||||
<Container textAlign='left'>
|
||||
|
|
@ -90,7 +94,10 @@ function EbookCard({file}) {
|
|||
</CardHeader>
|
||||
<CardMeta>
|
||||
{file.author ? <b {...s}>{file.author}</b> : null}
|
||||
{file.size && <p {...s}>{humanFileSize(file.size)}</p>}
|
||||
{sortField === 'published_datetime'
|
||||
? <p {...s}>{file.published_datetime ? isoDatetimeToAgoPopup(file.published_datetime, false) : null}</p>
|
||||
: file.size && <p {...s}>{humanFileSize(file.size)}</p>
|
||||
}
|
||||
</CardMeta>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
|
@ -128,10 +135,14 @@ function ImageCard({file}) {
|
|||
|
||||
function FileCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
const {sort} = useSearchOrder();
|
||||
const sortField = sort ? sort.replace(/^-/, '') : null;
|
||||
|
||||
const isEbookType = file.mimetype && (
|
||||
const isDocType = file.model === 'doc' || (file.mimetype && (
|
||||
file.mimetype.startsWith('application/epub') || file.mimetype.startsWith('application/x-mobipocket-ebook')
|
||||
);
|
||||
));
|
||||
// Default doc sort is published_datetime when no order query param is set.
|
||||
const docSortField = sortField || 'published_datetime';
|
||||
|
||||
if (file.model === 'video' && 'video' in file) {
|
||||
return <VideoCard key={file['primary_path']} file={file}/>;
|
||||
|
|
@ -139,12 +150,12 @@ function FileCard({file}) {
|
|||
return <ArchiveCard key={file['primary_path']} file={file}/>;
|
||||
} else if (file.mimetype && file.mimetype.startsWith('image/')) {
|
||||
return <ImageCard key={file['primary_path']} file={file}/>;
|
||||
} else if (isEbookType) {
|
||||
return <EbookCard key={file['primary_path']} file={file}/>;
|
||||
} else if (isDocType) {
|
||||
return <EbookCard key={file['primary_path']} file={file} sortField={docSortField}/>;
|
||||
}
|
||||
|
||||
const author = file.author;
|
||||
const color = mimetypeColor(file.mimetype);
|
||||
const color = mimetypeColor(file.mimetype, file.primary_path);
|
||||
const size = file.size !== null && file.size !== undefined ? humanFileSize(file.size) : null;
|
||||
|
||||
const title = file.title || file.name || file.primary_path;
|
||||
|
|
@ -160,8 +171,13 @@ function FileCard({file}) {
|
|||
</PreviewLink>
|
||||
</CardHeader>
|
||||
{author && <b {...s}>{author}</b>}
|
||||
<p>{isoDatetimeToAgoPopup(dt, false)}</p>
|
||||
<p>{size}</p>
|
||||
{sortField === 'published_datetime'
|
||||
? <p>{file.published_datetime ? isoDatetimeToAgoPopup(file.published_datetime, false) : null}</p>
|
||||
: <>
|
||||
<p>{isoDatetimeToAgoPopup(dt, false)}</p>
|
||||
<p>{size}</p>
|
||||
</>
|
||||
}
|
||||
</CardContent>
|
||||
</Card>
|
||||
}
|
||||
|
|
@ -206,7 +222,7 @@ function ImageRowCells({file}) {
|
|||
}
|
||||
|
||||
export function EbookRowCells({file}) {
|
||||
let cover = <Card.Icon><FileIcon file={file}/></Card.Icon>;
|
||||
let cover = <FileIcon file={file} size='large'/>;
|
||||
const posterPath = findPosterPath(file);
|
||||
if (posterPath) {
|
||||
const coverSrc = `/media/${encodeMediaPath(posterPath)}`;
|
||||
|
|
@ -229,9 +245,9 @@ export function EbookRowCells({file}) {
|
|||
}
|
||||
|
||||
function FileRow({file}) {
|
||||
const isEbookType = file.mimetype && (
|
||||
const isDocType = file.model === 'doc' || (file.mimetype && (
|
||||
file.mimetype.startsWith('application/epub') || file.mimetype.startsWith('application/x-mobipocket-ebook')
|
||||
);
|
||||
));
|
||||
|
||||
if (file.model === 'video' && 'video' in file) {
|
||||
return <VideoRowCells file={file}/>;
|
||||
|
|
@ -239,7 +255,7 @@ function FileRow({file}) {
|
|||
return <ArchiveRowCells file={file}/>;
|
||||
} else if (file.mimetype && file.mimetype.startsWith('image/')) {
|
||||
return <ImageRowCells file={file}/>;
|
||||
} else if (isEbookType) {
|
||||
} else if (isDocType) {
|
||||
return <EbookRowCells key={file['primary_path']} file={file}/>;
|
||||
}
|
||||
|
||||
|
|
@ -480,6 +496,7 @@ export function FileSearchFilterButton({size = 'medium'}) {
|
|||
{key: 'archive', text: 'Archive', value: 'archive'},
|
||||
{key: 'pdf', text: 'PDF', value: 'pdf'},
|
||||
{key: 'ebook', text: 'eBook', value: 'ebook'},
|
||||
{key: 'doc', text: 'Document', value: 'doc'},
|
||||
{key: 'audio', text: 'Audio', value: 'audio'},
|
||||
{key: 'image', text: 'Image', value: 'image'},
|
||||
{key: 'zip', text: 'ZIP', value: 'zip'},
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ function updateFavicon(colorName) {
|
|||
const links = [
|
||||
{text: 'Videos', to: '/videos', key: 'videos'},
|
||||
{text: 'Archive', to: '/archive', key: 'archive'},
|
||||
{text: 'Docs', to: '/docs', key: 'docs'},
|
||||
{text: 'Map', to: '/map', key: 'map'},
|
||||
{text: 'Zim', to: '/zim', key: 'zim'},
|
||||
{text: 'Files', to: '/files', key: 'files'},
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
|
|||
const pages = usePages(defaultLimit, totalPages);
|
||||
// text/html, video*, image*, etc.
|
||||
const filter = searchParams.get('filter');
|
||||
// archive/video/ebook/etc.
|
||||
// archive/video/doc/etc.
|
||||
const model_ = searchParams.get('model') || model;
|
||||
|
||||
const anySearch = (!datesIsEmpty) || searchStr || (activeTags && activeTags.length > 0) || filter || model;
|
||||
|
|
@ -121,6 +121,8 @@ export function useSuggestions(searchStr, tagNames, filter, anyTag) {
|
|||
fileGroups: [],
|
||||
channels: [],
|
||||
domains: [],
|
||||
authors: [],
|
||||
subjects: [],
|
||||
zimsEstimates: [],
|
||||
}
|
||||
const [suggestions, setSuggestions] = React.useState(defaultSuggestions);
|
||||
|
|
@ -162,6 +164,8 @@ export function useSuggestions(searchStr, tagNames, filter, anyTag) {
|
|||
...prevState,
|
||||
channels: generalData.channels,
|
||||
domains: generalData.domains,
|
||||
authors: generalData.authors,
|
||||
subjects: generalData.subjects,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -274,6 +278,30 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag)
|
|||
})
|
||||
}
|
||||
}
|
||||
if (newSuggestions.authors && newSuggestions.authors.length > 0) {
|
||||
results.authors = {
|
||||
name: 'Authors', results: newSuggestions.authors.map(i => {
|
||||
return {
|
||||
type: 'author',
|
||||
title: i.name,
|
||||
id: i.id,
|
||||
location: `/docs?author=${encodeURIComponent(i.name)}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
if (newSuggestions.subjects && newSuggestions.subjects.length > 0) {
|
||||
results.subjects = {
|
||||
name: 'Subjects', results: newSuggestions.subjects.map(i => {
|
||||
return {
|
||||
type: 'subject',
|
||||
title: i.name,
|
||||
id: i.id,
|
||||
location: `/docs?subject=${encodeURIComponent(i.name)}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Match at most 5 Tags.
|
||||
const matchingTags = searchStr ? fuzzyMatchTagsByName(searchStr).slice(0, 5) : null;
|
||||
|
|
@ -304,6 +332,8 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag)
|
|||
otherSum: otherSum,
|
||||
channels: newSuggestions.channels.length,
|
||||
domains: newSuggestions.domains.length,
|
||||
authors: newSuggestions.authors?.length,
|
||||
subjects: newSuggestions.subjects?.length,
|
||||
tags: matchingTags?.length,
|
||||
apps: matchingApps?.length,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -854,6 +854,8 @@ export function VideosRoute(props) {
|
|||
export function VideoCard({file}) {
|
||||
const {video} = file;
|
||||
const {s} = useContext(ThemeContext);
|
||||
const {sort} = useSearchOrder();
|
||||
const sortField = sort ? sort.replace(/^-/, '') : null;
|
||||
|
||||
// Default to video FilePreview for lone video files.
|
||||
let video_url;
|
||||
|
|
@ -904,7 +906,18 @@ export function VideoCard({file}) {
|
|||
{channel && <Link to={channel_url} className="no-link-underscore card-link">
|
||||
<b {...s}>{channel.name}</b>
|
||||
</Link>}
|
||||
<p {...s}>{isoDatetimeToAgoPopup(file.published_datetime, false)}</p>
|
||||
{sortField === 'length'
|
||||
? <p {...s}>{secondsToFullDuration(file.length || 0)}</p>
|
||||
: sortField === 'size'
|
||||
? <p {...s}>{humanFileSize(file.size)}</p>
|
||||
: sortField === 'view_count'
|
||||
? <p {...s}>{humanNumber(video.view_count || 0)} views</p>
|
||||
: sortField === 'viewed'
|
||||
? <p {...s}>{isoDatetimeToAgoPopup(file.viewed, false)}</p>
|
||||
: sortField === 'download_datetime'
|
||||
? <p {...s}>{isoDatetimeToAgoPopup(file.download_datetime, false)}</p>
|
||||
: <p {...s}>{isoDatetimeToAgoPopup(file.published_datetime, false)}</p>
|
||||
}
|
||||
</Container>
|
||||
</CardDescription>
|
||||
</CardContent>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue