-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc5e963
commit 621b97f
Showing
17 changed files
with
479 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { FastifyInstance } from 'fastify' | ||
import { Static, Type } from '@sinclair/typebox' | ||
import { EventDao } from '../../dao/eventDao' | ||
import { getStorageBucketName } from '../../dao/firebasePlugin' | ||
|
||
const GetReply = Type.Union([ | ||
Type.Object({ | ||
eventName: Type.String(), | ||
gladiaAPIKey: Type.String(), | ||
dataUrl: Type.String(), | ||
}), | ||
Type.String(), | ||
]) | ||
type GetReplyType = Static<typeof GetReply> | ||
|
||
export const transcriptionRoutes = (fastify: FastifyInstance, options: any, done: () => any) => { | ||
fastify.get<{ Reply: GetReplyType }>( | ||
'/v1/:eventId/transcription', | ||
{ | ||
schema: { | ||
tags: ['transcription'], | ||
summary: 'Public route to access the Gladia API Key along with some more data', | ||
response: { | ||
200: GetReply, | ||
400: Type.String(), | ||
401: Type.String(), | ||
}, | ||
security: [ | ||
{ | ||
password: [], | ||
}, | ||
], | ||
}, | ||
}, | ||
async (request, reply) => { | ||
const { eventId } = request.params as { eventId: string } | ||
|
||
const password = request.headers['password'] as string | ||
|
||
const event = await EventDao.getEvent(fastify.firebase, eventId) | ||
|
||
const bucket = getStorageBucketName() | ||
|
||
if (!event.gladiaAPIKey || !event.transcriptionPassword) { | ||
reply.status(401).send( | ||
JSON.stringify({ | ||
error: 'Missing Gladia API Key or password', | ||
}) | ||
) | ||
return | ||
} | ||
if (event.transcriptionPassword !== password) { | ||
reply.status(401).send( | ||
JSON.stringify({ | ||
error: 'Passwords does not match', | ||
}) | ||
) | ||
return | ||
} | ||
if (!event.files?.public) { | ||
reply.status(401).send( | ||
JSON.stringify({ | ||
error: 'Missing public file, did you forgot to "Update website" once?', | ||
}) | ||
) | ||
return | ||
} | ||
|
||
reply.status(200).send({ | ||
eventName: event.name, | ||
gladiaAPIKey: event.gladiaAPIKey, | ||
dataUrl: `https://storage.googleapis.com/${bucket}/${event.files.public}`, | ||
}) | ||
} | ||
) | ||
done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const BaseAPIUrl = import.meta.env.VITE_FIREBASE_OPEN_PLANNER_API_URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { PublicJSON, TranscriptionReply } from '../publicTypes' | ||
import { BaseAPIUrl } from './constants' | ||
import { useEffect, useState } from 'react' | ||
import { DateTime } from 'luxon' | ||
|
||
export const useTranscription = ( | ||
eventId: string, | ||
password: string | ||
): [string | undefined | null, null | PublicJSON, boolean, string | null] => { | ||
const [state, setState] = useState<{ | ||
isLoading: boolean | ||
error: string | null | ||
data: TranscriptionReply | null | ||
eventData: null | PublicJSON | ||
}>({ | ||
isLoading: false, | ||
error: null, | ||
data: null, | ||
eventData: null, | ||
}) | ||
|
||
// const dateNow = DateTime.fromISO('2023-07-05T016:00:00.000Z') | ||
|
||
useEffect(() => { | ||
const load = async () => { | ||
try { | ||
setState((newState) => { | ||
return { | ||
...newState, | ||
error: null, | ||
isLoading: true, | ||
} | ||
}) | ||
|
||
if (!password || password.length === 0) { | ||
setState((newState) => { | ||
return { | ||
...newState, | ||
isLoading: false, | ||
error: 'Missing password', | ||
} | ||
}) | ||
return | ||
} | ||
|
||
const url = new URL(BaseAPIUrl as string) | ||
url.pathname += `v1/${eventId}/transcription` | ||
|
||
const apiResult = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
password: password, | ||
}, | ||
}) | ||
|
||
if (!apiResult.ok) { | ||
setState((newState) => { | ||
return { | ||
...newState, | ||
isLoading: false, | ||
error: `HTTP error! status: ${apiResult.status}`, | ||
} | ||
}) | ||
return | ||
} | ||
|
||
const apiData = await apiResult.json() | ||
|
||
setState((newState) => { | ||
return { | ||
...newState, | ||
data: apiData, | ||
} | ||
}) | ||
const urlEventData = new URL(`${apiData.dataUrl}?t=${Date.now()}`) | ||
|
||
const eventDataResult = await fetch(urlEventData) | ||
|
||
if (!eventDataResult.ok) { | ||
setState((newState) => { | ||
return { | ||
...newState, | ||
isLoading: false, | ||
error: `HTTP error! status: ${eventDataResult.status}`, | ||
} | ||
}) | ||
return | ||
} | ||
|
||
const eventData = await eventDataResult.json() | ||
|
||
setState((newState) => { | ||
return { | ||
...newState, | ||
isLoading: false, | ||
eventData: eventData, | ||
} | ||
}) | ||
} catch (error) { | ||
setState((newState) => { | ||
return { | ||
...newState, | ||
isLoading: false, | ||
error: `Error! status: ${error}`, | ||
} | ||
}) | ||
} | ||
} | ||
|
||
load() | ||
}, [password]) | ||
|
||
return [state.data?.gladiaAPIKey, state.eventData, state.isLoading, state.error] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.