Add features entity

This commit is contained in:
Hongbo Wu 2022-11-08 18:14:23 +08:00
parent 398e242131
commit c2f4ba4a57
2 changed files with 46 additions and 5 deletions

View file

@ -0,0 +1,35 @@
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm'
import { User } from './user'
@Entity({ name: 'features' })
export class Feature {
@PrimaryGeneratedColumn('uuid')
id!: string
@ManyToOne(() => User, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
user!: User
@Column('text')
name!: string
@Column('text')
token!: string
@Column('timestamp', { nullable: true })
grantedAt?: Date | null
@CreateDateColumn({ default: () => 'CURRENT_TIMESTAMP' })
createdAt!: Date
@UpdateDateColumn({ default: () => 'CURRENT_TIMESTAMP' })
updatedAt!: Date
}

View file

@ -15,6 +15,7 @@ import { AppDataSource } from '../server'
import { enqueueTextToSpeech } from '../utils/createTask'
import { htmlToSpeechFile } from '@omnivore/text-to-speech-handler'
import { UserPersonalization } from '../entity/user_personalization'
import { ArticleSavingRequestStatus } from '../elastic/types'
const logger = buildLogger('app.dispatch')
@ -36,17 +37,17 @@ export function textToSpeechRouter() {
}
try {
const data: { userId: string; type: string; id: string; state: string } =
const data: { userId: string; type: string; id: string } =
JSON.parse(msgStr)
const { userId, type, id, state } = data
const { userId, type, id } = data
if (!userId || !type || !id) {
logger.info('Invalid data')
return res.status(400).send('Bad Request')
}
if (type.toUpperCase() !== 'PAGE' || state !== 'SUCCEEDED') {
logger.info('Not a page or not succeeded')
return res.status(200).send('Not a page or not succeeded')
if (type.toUpperCase() !== 'PAGE') {
logger.info('Not a page')
return res.status(200).send('Not a page')
}
const page = await getPageById(id)
@ -55,6 +56,11 @@ export function textToSpeechRouter() {
return res.status(200).send('No page found')
}
if (page.state === ArticleSavingRequestStatus.Processing) {
logger.info('Page is still processing, try again later', { id })
return res.status(400).send('Page is still processing')
}
// checks if this page needs to be synthesized automatically
if (await shouldSynthesize(userId, page)) {
logger.info('page needs to be synthesized')