mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
randomly pick the qualified thumbnail
This commit is contained in:
parent
ee2ca1ec97
commit
42b8aede0e
1 changed files with 19 additions and 7 deletions
|
|
@ -623,17 +623,29 @@ const sendEmail = async (user: User, digest: Digest) => {
|
|||
const findThumbnail = async (
|
||||
chapters: Chapter[]
|
||||
): Promise<string | undefined> => {
|
||||
const images = await Promise.all(
|
||||
chapters
|
||||
.filter((chapter) => chapter.thumbnail)
|
||||
.map((chapter) => getImageSize(chapter.thumbnail as string))
|
||||
)
|
||||
const thumbnails = chapters
|
||||
.filter((chapter) => !!chapter.thumbnail)
|
||||
.map((chapter) => chapter.thumbnail as string)
|
||||
// randomly sort the thumbnails
|
||||
.sort(() => 0.5 - Math.random())
|
||||
|
||||
try {
|
||||
return _findThumbnail(images)
|
||||
for (const thumbnail of thumbnails) {
|
||||
const size = await getImageSize(thumbnail)
|
||||
if (!size) {
|
||||
continue
|
||||
}
|
||||
|
||||
const selectedThumbnail = _findThumbnail([size])
|
||||
if (selectedThumbnail) {
|
||||
return selectedThumbnail
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
return undefined
|
||||
logger.error('findThumbnail error')
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
export const moveToLibrary = async (user: User, digest: Digest) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue