add a "read in omnivore" button to the digest email

This commit is contained in:
Hongbo Wu
2024-05-08 16:49:12 +08:00
parent 5f4ed6ad11
commit ee2ca1ec97
2 changed files with 24 additions and 7 deletions

View File

@ -599,6 +599,17 @@ const sendEmail = async (user: User, digest: Digest) => {
</div>`
)
.join('')}
<button style="background-color: #FFEAA0;
border: 0px solid transparent;
color: rgb(42, 42, 42);
padding:15px 32px;
font-size: 14px;
margin: 20px 0;
font-family: Inter, sans-serif;
border-radius: 5px;">
<a href="${env.client.url}/digest/${digest.id}">Read in Omnivore</a>
</button>
</div>`
await enqueueSendEmail({
@ -609,17 +620,23 @@ const sendEmail = async (user: User, digest: Digest) => {
})
}
const findThumbnail = async (chapters: Chapter[]) => {
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))
)
return _findThumbnail(images)
try {
return _findThumbnail(images)
} catch {
return undefined
}
}
export const saveInLibrary = async (user: User, digest: Digest) => {
export const moveToLibrary = async (user: User, digest: Digest) => {
const subTitle = digest.title?.slice(AUTHOR.length + 1) ?? ''
const title = `${AUTHOR}: ${subTitle}`
@ -644,7 +661,7 @@ export const saveInLibrary = async (user: User, digest: Digest) => {
await savePage(
{
url: `${env.client.url}/digest/${digest.id}`,
url: `${env.client.url}/omnivore-digest/${digest.id}`,
title,
originalContent: html,
clientRequestId: digest.id,
@ -672,7 +689,7 @@ const sendToChannels = async (
case 'email':
return sendEmail(user, digest)
case 'library':
return saveInLibrary(user, digest)
return moveToLibrary(user, digest)
default:
logger.error('Unknown channel', { channel })
return

View File

@ -4,7 +4,7 @@ import { env } from '../env'
import { TaskState } from '../generated/graphql'
import {
CreateDigestJobSchedule,
saveInLibrary,
moveToLibrary,
} from '../jobs/ai/create_digest'
import { getDigest } from '../services/digest'
import { FeatureName, findGrantedFeatureByName } from '../services/features'
@ -301,7 +301,7 @@ export function digestRouter() {
}
// move digest to library
await saveInLibrary(feature.user, digest)
await moveToLibrary(feature.user, digest)
res.send({
success: true,