mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Using image next to a PDF with the same stem as the PDF's poster.
This commit is contained in:
parent
8cffea6e1f
commit
3f4d5798e2
4 changed files with 34 additions and 8 deletions
|
|
@ -674,6 +674,10 @@ export function findPosterPath(file) {
|
|||
// Ebook.
|
||||
return file['data']['cover_path'];
|
||||
}
|
||||
if (file['data'] && file['data']['poster_path']) {
|
||||
// PDF.
|
||||
return file['data']['poster_path'];
|
||||
}
|
||||
if (video && video['poster_path']) {
|
||||
// file is a video model.
|
||||
return video['poster_path'];
|
||||
|
|
|
|||
|
|
@ -144,22 +144,20 @@ function FileCard({file}) {
|
|||
}
|
||||
|
||||
const author = file.author;
|
||||
const downloadUrl = `/download/${encodeMediaPath(file.primary_path)}`;
|
||||
const color = mimetypeColor(file.mimetype);
|
||||
const size = file.size !== null && file.size !== undefined ? humanFileSize(file.size) : null;
|
||||
|
||||
const title = file.title || file.name || file.primary_path;
|
||||
const header = <ExternalCardLink to={downloadUrl} className='card-title-ellipsis'>
|
||||
{title}
|
||||
</ExternalCardLink>;
|
||||
const dt = file.published_datetime || file.published_modified_datetime || file.modified;
|
||||
return <Card color={color}>
|
||||
<CardPoster to={downloadUrl} file={file}/>
|
||||
<CardPoster file={file}/>
|
||||
<CardContent {...s}>
|
||||
<CardHeader>
|
||||
<Popup on='hover'
|
||||
trigger={header}
|
||||
content={title}/>
|
||||
<PreviewLink file={file}>
|
||||
<Popup on='hover'
|
||||
trigger={<span className='card-title-ellipsis'>{title}</span>}
|
||||
content={title}/>
|
||||
</PreviewLink>
|
||||
</CardHeader>
|
||||
{author && <b {...s}>{author}</b>}
|
||||
<p>{isoDatetimeToAgoPopup(dt, false)}</p>
|
||||
|
|
|
|||
|
|
@ -150,6 +150,12 @@ async def pdf_modeler():
|
|||
file_group.published_datetime = metadata.published_datetime
|
||||
file_group.published_modified_datetime = metadata.modification_datetime
|
||||
file_group.model = 'pdf'
|
||||
|
||||
# Find an image with the same stem to use as the poster.
|
||||
poster_files = file_group.my_poster_files()
|
||||
if poster_files:
|
||||
file_group.data = file_group.data or {}
|
||||
file_group.data['poster_path'] = str(poster_files[0]['path'])
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to index PDF {pdf_file}', exc_info=e)
|
||||
if PYTEST:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from wrolpi.dates import now
|
||||
from wrolpi.files import lib as files_lib
|
||||
|
|
@ -74,3 +75,20 @@ async def test_pdf_indexer_max_size(test_session, example_pdf):
|
|||
await pdfs.pdf_modeler()
|
||||
file_group = test_session.query(FileGroup).one()
|
||||
assert file_group.d_text is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pdf_poster(test_session, example_pdf):
|
||||
"""PDF modeler finds an image with the same stem and uses it as the poster."""
|
||||
# Create an image with the same stem as the PDF.
|
||||
poster_path = example_pdf.with_suffix('.jpg')
|
||||
Image.new('RGB', (25, 25), color='grey').save(poster_path)
|
||||
|
||||
files_lib._upsert_files([example_pdf, poster_path], now())
|
||||
|
||||
await pdfs.pdf_modeler()
|
||||
file_group = test_session.query(FileGroup).one()
|
||||
assert file_group.indexed is True
|
||||
assert file_group.data is not None
|
||||
# FancyJSON converts paths back to pathlib.Path when reading from DB.
|
||||
assert file_group.data.get('poster_path') == poster_path
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue