mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
www: fix mp3 download while authenticated
This commit is contained in:
@@ -4,6 +4,7 @@ import getApi from "../../../lib/getApi";
|
|||||||
import useTranscript from "../useTranscript";
|
import useTranscript from "../useTranscript";
|
||||||
import useTopics from "../useTopics";
|
import useTopics from "../useTopics";
|
||||||
import useWaveform from "../useWaveform";
|
import useWaveform from "../useWaveform";
|
||||||
|
import useMp3 from "../useMp3";
|
||||||
import { TopicList } from "../topicList";
|
import { TopicList } from "../topicList";
|
||||||
import Recorder from "../recorder";
|
import Recorder from "../recorder";
|
||||||
import { Topic } from "../webSocketTypes";
|
import { Topic } from "../webSocketTypes";
|
||||||
@@ -31,6 +32,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
const waveform = useWaveform(api, transcriptId);
|
const waveform = useWaveform(api, transcriptId);
|
||||||
const useActiveTopic = useState<Topic | null>(null);
|
const useActiveTopic = useState<Topic | null>(null);
|
||||||
const requireLogin = featureEnabled("requireLogin");
|
const requireLogin = featureEnabled("requireLogin");
|
||||||
|
const mp3 = useMp3(api, transcriptId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (requireLogin && !isAuthenticated) return;
|
if (requireLogin && !isAuthenticated) return;
|
||||||
@@ -70,6 +72,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
waveform={waveform?.waveform}
|
waveform={waveform?.waveform}
|
||||||
isPastMeeting={true}
|
isPastMeeting={true}
|
||||||
transcriptId={transcript?.response?.id}
|
transcriptId={transcript?.response?.id}
|
||||||
|
mp3Blob={mp3.blob}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ type RecorderProps = {
|
|||||||
waveform?: AudioWaveform | null;
|
waveform?: AudioWaveform | null;
|
||||||
isPastMeeting: boolean;
|
isPastMeeting: boolean;
|
||||||
transcriptId?: string | null;
|
transcriptId?: string | null;
|
||||||
|
mp3Blob?: Blob | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Recorder(props: RecorderProps) {
|
export default function Recorder(props: RecorderProps) {
|
||||||
@@ -107,11 +108,7 @@ export default function Recorder(props: RecorderProps) {
|
|||||||
if (waveformRef.current) {
|
if (waveformRef.current) {
|
||||||
const _wavesurfer = WaveSurfer.create({
|
const _wavesurfer = WaveSurfer.create({
|
||||||
container: waveformRef.current,
|
container: waveformRef.current,
|
||||||
url: props.transcriptId
|
|
||||||
? `${process.env.NEXT_PUBLIC_API_URL}/v1/transcripts/${props.transcriptId}/audio/mp3`
|
|
||||||
: undefined,
|
|
||||||
peaks: props.waveform?.data,
|
peaks: props.waveform?.data,
|
||||||
|
|
||||||
hideScrollbar: true,
|
hideScrollbar: true,
|
||||||
autoCenter: true,
|
autoCenter: true,
|
||||||
barWidth: 2,
|
barWidth: 2,
|
||||||
@@ -145,6 +142,10 @@ export default function Recorder(props: RecorderProps) {
|
|||||||
|
|
||||||
if (props.isPastMeeting) _wavesurfer.toggleInteraction(true);
|
if (props.isPastMeeting) _wavesurfer.toggleInteraction(true);
|
||||||
|
|
||||||
|
if (props.mp3Blob) {
|
||||||
|
_wavesurfer.loadBlob(props.mp3Blob);
|
||||||
|
}
|
||||||
|
|
||||||
setWavesurfer(_wavesurfer);
|
setWavesurfer(_wavesurfer);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@@ -156,6 +157,12 @@ export default function Recorder(props: RecorderProps) {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!wavesurfer) return;
|
||||||
|
if (!props.mp3Blob) return;
|
||||||
|
wavesurfer.loadBlob(props.mp3Blob);
|
||||||
|
}, [props.mp3Blob]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
topicsRef.current = props.topics;
|
topicsRef.current = props.topics;
|
||||||
if (!isRecording) renderMarkers();
|
if (!isRecording) renderMarkers();
|
||||||
|
|||||||
@@ -1,36 +1,64 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
DefaultApi,
|
DefaultApi,
|
||||||
V1TranscriptGetAudioMp3Request,
|
// V1TranscriptGetAudioMp3Request,
|
||||||
} from "../../api/apis/DefaultApi";
|
} from "../../api/apis/DefaultApi";
|
||||||
import {} from "../../api";
|
import {} from "../../api";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
|
import { DomainContext } from "../domainContext";
|
||||||
|
|
||||||
type Mp3Response = {
|
type Mp3Response = {
|
||||||
url: string | null;
|
url: string | null;
|
||||||
|
blob: Blob | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: Error | null;
|
error: Error | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useMp3 = (api: DefaultApi, id: string): Mp3Response => {
|
const useMp3 = (api: DefaultApi, id: string): Mp3Response => {
|
||||||
const [url, setUrl] = useState<string | null>(null);
|
const [url, setUrl] = useState<string | null>(null);
|
||||||
|
const [blob, setBlob] = useState<Blob | null>(null);
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
|
const { api_url } = useContext(DomainContext);
|
||||||
|
|
||||||
const getMp3 = (id: string) => {
|
const getMp3 = (id: string) => {
|
||||||
if (!id) throw new Error("Transcript ID is required to get transcript Mp3");
|
if (!id) return;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const requestParameters: V1TranscriptGetAudioMp3Request = {
|
// XXX Current API interface does not output a blob, we need to to is manually
|
||||||
transcriptId: id,
|
// const requestParameters: V1TranscriptGetAudioMp3Request = {
|
||||||
};
|
// transcriptId: id,
|
||||||
api
|
// };
|
||||||
.v1TranscriptGetAudioMp3(requestParameters)
|
// api
|
||||||
.then((result) => {
|
// .v1TranscriptGetAudioMp3(requestParameters)
|
||||||
setUrl(result);
|
// .then((result) => {
|
||||||
setLoading(false);
|
// setUrl(result);
|
||||||
console.debug("Transcript Mp3 loaded:", result);
|
// setLoading(false);
|
||||||
|
// console.debug("Transcript Mp3 loaded:", result);
|
||||||
|
// })
|
||||||
|
// .catch((err) => {
|
||||||
|
// setError(err);
|
||||||
|
// setErrorState(err);
|
||||||
|
// });
|
||||||
|
const localUrl = `${api_url}/v1/transcripts/${id}/audio/mp3`;
|
||||||
|
if (localUrl == url) return;
|
||||||
|
const headers = new Headers();
|
||||||
|
|
||||||
|
if (api.configuration.configuration.accessToken) {
|
||||||
|
headers.set("Authorization", api.configuration.configuration.accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(localUrl, {
|
||||||
|
method: "GET",
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
setUrl(localUrl);
|
||||||
|
response.blob().then((blob) => {
|
||||||
|
setBlob(blob);
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setError(err);
|
setError(err);
|
||||||
@@ -42,7 +70,7 @@ const useMp3 = (api: DefaultApi, id: string): Mp3Response => {
|
|||||||
getMp3(id);
|
getMp3(id);
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
return { url, loading, error };
|
return { url, blob, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useMp3;
|
export default useMp3;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
"supports-color": "^9.4.0",
|
"supports-color": "^9.4.0",
|
||||||
"tailwindcss": "^3.3.2",
|
"tailwindcss": "^3.3.2",
|
||||||
"typescript": "^5.1.6",
|
"typescript": "^5.1.6",
|
||||||
"wavesurfer.js": "^7.0.3"
|
"wavesurfer.js": "^7.4.2"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": "https://github.com/Monadical-SAS/reflector-ui.git",
|
"repository": "https://github.com/Monadical-SAS/reflector-ui.git",
|
||||||
|
|||||||
@@ -2638,10 +2638,10 @@ watchpack@2.4.0:
|
|||||||
glob-to-regexp "^0.4.1"
|
glob-to-regexp "^0.4.1"
|
||||||
graceful-fs "^4.1.2"
|
graceful-fs "^4.1.2"
|
||||||
|
|
||||||
wavesurfer.js@^7.0.3:
|
wavesurfer.js@^7.4.2:
|
||||||
version "7.0.3"
|
version "7.4.2"
|
||||||
resolved "https://registry.npmjs.org/wavesurfer.js/-/wavesurfer.js-7.0.3.tgz"
|
resolved "https://registry.yarnpkg.com/wavesurfer.js/-/wavesurfer.js-7.4.2.tgz#59f5c87193d4eeeb199858688ddac1ad7ba86b3a"
|
||||||
integrity sha512-gJ3P+Bd3Q4E8qETjjg0pneaVqm2J7jegG2Cc6vqEF5YDDKQ3m8sKsvVfgVhJkacKkO9jFAGDu58Hw4zLr7xD0A==
|
integrity sha512-4pNQ1porOCUBYBmd2F1TqVuBnB2wBPipaw2qI920zYLuPnada0Rd1CURgh8HRuPGKxijj2iyZDFN2UZwsaEuhA==
|
||||||
|
|
||||||
wcwidth@>=1.0.1, wcwidth@^1.0.1:
|
wcwidth@>=1.0.1, wcwidth@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user