mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Allow saving epub from email attachments
This commit is contained in:
parent
e943f91acf
commit
62b772eeca
2 changed files with 27 additions and 24 deletions
|
|
@ -1,34 +1,35 @@
|
|||
import express from 'express'
|
||||
import { setClaims } from '../../datalayer/helpers'
|
||||
import { kx } from '../../datalayer/knex_config'
|
||||
import { createPubSubClient } from '../../datalayer/pubsub'
|
||||
import { createPage } from '../../elastic/pages'
|
||||
import { ArticleSavingRequestStatus, Page } from '../../elastic/types'
|
||||
import { env } from '../../env'
|
||||
import { PageType, UploadFileStatus } from '../../generated/graphql'
|
||||
import { initModels } from '../../server'
|
||||
import { getNewsletterEmail } from '../../services/newsletters'
|
||||
import { updateReceivedEmail } from '../../services/received_emails'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
import { getClaimsByToken } from '../../utils/auth'
|
||||
import { generateSlug } from '../../utils/helpers'
|
||||
import {
|
||||
generateUploadFilePathName,
|
||||
generateUploadSignedUrl,
|
||||
getStorageFileDetails,
|
||||
makeStorageFilePublic,
|
||||
} from '../../utils/uploads'
|
||||
import { initModels } from '../../server'
|
||||
import { kx } from '../../datalayer/knex_config'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
import { getNewsletterEmail } from '../../services/newsletters'
|
||||
import { setClaims } from '../../datalayer/helpers'
|
||||
import { generateSlug } from '../../utils/helpers'
|
||||
import { createPubSubClient } from '../../datalayer/pubsub'
|
||||
import { ArticleSavingRequestStatus, Page } from '../../elastic/types'
|
||||
import { createPage } from '../../elastic/pages'
|
||||
import { getClaimsByToken } from '../../utils/auth'
|
||||
import { updateReceivedEmail } from '../../services/received_emails'
|
||||
|
||||
export function pdfAttachmentsRouter() {
|
||||
export function emailAttachmentRouter() {
|
||||
const router = express.Router()
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
router.post('/upload', async (req, res) => {
|
||||
console.log('pdf-attachments/upload')
|
||||
console.log('email-attachment/upload')
|
||||
|
||||
const { email, fileName } = req.body as {
|
||||
const { email, fileName, contentType } = req.body as {
|
||||
email: string
|
||||
fileName: string
|
||||
contentType: string
|
||||
}
|
||||
|
||||
const token = req?.headers?.authorization
|
||||
|
|
@ -45,14 +46,13 @@ export function pdfAttachmentsRouter() {
|
|||
|
||||
analytics.track({
|
||||
userId: user.id,
|
||||
event: 'pdf_attachment_upload',
|
||||
event: 'email_attachment_upload',
|
||||
properties: {
|
||||
env: env.server.apiEnv,
|
||||
},
|
||||
})
|
||||
|
||||
try {
|
||||
const contentType = 'application/pdf'
|
||||
const models = initModels(kx, false)
|
||||
const uploadFileData = await models.uploadFile.create({
|
||||
url: '',
|
||||
|
|
@ -86,7 +86,7 @@ export function pdfAttachmentsRouter() {
|
|||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
router.post('/create-article', async (req, res) => {
|
||||
console.log('pdf-attachments/create-article')
|
||||
console.log('email-attachment/create-article')
|
||||
|
||||
const { email, uploadFileId, subject, receivedEmailId } = req.body as {
|
||||
email: string
|
||||
|
|
@ -109,7 +109,7 @@ export function pdfAttachmentsRouter() {
|
|||
|
||||
analytics.track({
|
||||
userId: user.id,
|
||||
event: 'pdf_attachment_create_article',
|
||||
event: 'email_attachment_create_article',
|
||||
properties: {
|
||||
env: env.server.apiEnv,
|
||||
},
|
||||
|
|
@ -144,18 +144,21 @@ export function pdfAttachmentsRouter() {
|
|||
)
|
||||
|
||||
const uploadFileHash = uploadFileDetails.md5Hash
|
||||
const pageType = PageType.File
|
||||
const pageType =
|
||||
uploadFile.contentType === 'application/pdf'
|
||||
? PageType.File
|
||||
: PageType.Book
|
||||
const title = subject || uploadFileData.fileName
|
||||
const articleToSave: Page = {
|
||||
id: '',
|
||||
url: uploadFileUrlOverride,
|
||||
pageType: pageType,
|
||||
pageType,
|
||||
hash: uploadFileHash,
|
||||
uploadFileId: uploadFileId,
|
||||
uploadFileId,
|
||||
title,
|
||||
content: '',
|
||||
userId: user.id,
|
||||
slug: generateSlug(title),
|
||||
id: '',
|
||||
createdAt: new Date(),
|
||||
savedAt: new Date(),
|
||||
readingProgressPercent: 0,
|
||||
|
|
@ -38,10 +38,10 @@ import { notificationRouter } from './routers/notification_router'
|
|||
import { pageRouter } from './routers/page_router'
|
||||
import { contentServiceRouter } from './routers/svc/content'
|
||||
import { emailsServiceRouter } from './routers/svc/emails'
|
||||
import { emailAttachmentRouter } from './routers/svc/email_attachment'
|
||||
import { integrationsServiceRouter } from './routers/svc/integrations'
|
||||
import { linkServiceRouter } from './routers/svc/links'
|
||||
import { newsletterServiceRouter } from './routers/svc/newsletters'
|
||||
import { pdfAttachmentsRouter } from './routers/svc/pdf_attachments'
|
||||
import { remindersServiceRouter } from './routers/svc/reminders'
|
||||
import { uploadServiceRouter } from './routers/svc/upload'
|
||||
import { webhooksServiceRouter } from './routers/svc/webhooks'
|
||||
|
|
@ -145,7 +145,7 @@ export const createApp = (): {
|
|||
app.use('/svc/pubsub/webhooks', webhooksServiceRouter())
|
||||
app.use('/svc/pubsub/integrations', integrationsServiceRouter())
|
||||
app.use('/svc/reminders', remindersServiceRouter())
|
||||
app.use('/svc/pdf-attachments', pdfAttachmentsRouter())
|
||||
app.use('/svc/email-attachment', emailAttachmentRouter())
|
||||
|
||||
if (env.dev.isLocal) {
|
||||
app.use('/local/debug', localDebugRouter())
|
||||
|
|
|
|||
Loading…
Reference in a new issue