mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add RLS to speech table
This commit is contained in:
parent
b2d49d1fbf
commit
5201f5d360
3 changed files with 37 additions and 11 deletions
|
|
@ -4,13 +4,14 @@
|
|||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import { corsConfig } from '../../utils/corsConfig'
|
||||
import { getRepository } from '../../entity/utils'
|
||||
import { getRepository, setClaims } from '../../entity/utils'
|
||||
import { getPageById } from '../../elastic/pages'
|
||||
import { Speech, SpeechState } from '../../entity/speech'
|
||||
import { buildLogger } from '../../utils/logger'
|
||||
import { getClaimsByToken } from '../../utils/auth'
|
||||
import { shouldSynthesize, synthesize } from '../../services/speech'
|
||||
import { readPushSubscription } from '../../datalayer/pubsub'
|
||||
import { AppDataSource } from '../../server'
|
||||
|
||||
const logger = buildLogger('app.dispatch')
|
||||
|
||||
|
|
@ -93,20 +94,25 @@ export function speechServiceRouter() {
|
|||
return res.status(401).send('UNAUTHORIZED')
|
||||
}
|
||||
|
||||
const { speechId, audioFileName, speechMarksFileName } = req.body as {
|
||||
speechId: string
|
||||
audioFileName: string
|
||||
speechMarksFileName: string
|
||||
}
|
||||
if (!speechId || !audioFileName || !speechMarksFileName) {
|
||||
const { speechId, audioFileName, speechMarksFileName, state } =
|
||||
req.body as {
|
||||
speechId: string
|
||||
audioFileName: string
|
||||
speechMarksFileName: string
|
||||
state: SpeechState
|
||||
}
|
||||
if (!speechId) {
|
||||
return res.status(400).send('Invalid data')
|
||||
}
|
||||
|
||||
// set state to completed
|
||||
await getRepository(Speech).update(speechId, {
|
||||
audioFileName: audioFileName,
|
||||
speechMarksFileName: speechMarksFileName,
|
||||
state: SpeechState.COMPLETED,
|
||||
await AppDataSource.transaction(async (t) => {
|
||||
await setClaims(t, userId)
|
||||
await t.getRepository(Speech).update(speechId, {
|
||||
audioFileName: audioFileName,
|
||||
speechMarksFileName: speechMarksFileName,
|
||||
state,
|
||||
})
|
||||
})
|
||||
|
||||
res.send('OK')
|
||||
|
|
|
|||
11
packages/db/migrations/0095.do.add_rls_to_speech.sql
Executable file
11
packages/db/migrations/0095.do.add_rls_to_speech.sql
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
-- Type: DO
|
||||
-- Name: add_rls_to_speech
|
||||
-- Description: Add Row level security to speech table
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE POLICY update_speech on omnivore.speech
|
||||
FOR UPDATE TO omnivore_user
|
||||
USING (user_id = omnivore.get_current_user_id());
|
||||
|
||||
COMMIT;
|
||||
9
packages/db/migrations/0095.undo.add_rls_to_speech.sql
Executable file
9
packages/db/migrations/0095.undo.add_rls_to_speech.sql
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
-- Type: UNDO
|
||||
-- Name: add_rls_to_speech
|
||||
-- Description: Add Row level security to speech table
|
||||
|
||||
BEGIN;
|
||||
|
||||
DROP POLICY IF EXISTS update_speech ON omnivore.speech;
|
||||
|
||||
COMMIT;
|
||||
Loading…
Reference in a new issue