mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
fix mp3 auth
This commit is contained in:
@@ -29,7 +29,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
const topics = useTopics(protectedPath, transcriptId);
|
const topics = useTopics(protectedPath, transcriptId);
|
||||||
const waveform = useWaveform(protectedPath, transcriptId);
|
const waveform = useWaveform(protectedPath, transcriptId);
|
||||||
const useActiveTopic = useState<Topic | null>(null);
|
const useActiveTopic = useState<Topic | null>(null);
|
||||||
const mp3 = useMp3(api, transcriptId);
|
const mp3 = useMp3(protectedPath, transcriptId);
|
||||||
|
|
||||||
if (transcript?.error /** || topics?.error || waveform?.error **/) {
|
if (transcript?.error /** || topics?.error || waveform?.error **/) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
import {} from "../../api";
|
import {} from "../../api";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import { DomainContext } from "../domainContext";
|
import { DomainContext } from "../domainContext";
|
||||||
|
import getApi from "../../lib/getApi";
|
||||||
|
import { useFiefAccessTokenInfo } from "@fief/fief/build/esm/nextjs/react";
|
||||||
|
|
||||||
type Mp3Response = {
|
type Mp3Response = {
|
||||||
url: string | null;
|
url: string | null;
|
||||||
@@ -14,16 +16,18 @@ type Mp3Response = {
|
|||||||
error: Error | null;
|
error: Error | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useMp3 = (api: DefaultApi, id: string): Mp3Response => {
|
const useMp3 = (protectedPath: boolean, 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 [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 = getApi(protectedPath);
|
||||||
const { api_url } = useContext(DomainContext);
|
const { api_url } = useContext(DomainContext);
|
||||||
|
const accessTokenInfo = useFiefAccessTokenInfo();
|
||||||
|
|
||||||
const getMp3 = (id: string) => {
|
const getMp3 = (id: string) => {
|
||||||
if (!id) return;
|
if (!id || !api) return;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
// XXX Current API interface does not output a blob, we need to to is manually
|
// XXX Current API interface does not output a blob, we need to to is manually
|
||||||
@@ -45,8 +49,8 @@ const useMp3 = (api: DefaultApi, id: string): Mp3Response => {
|
|||||||
if (localUrl == url) return;
|
if (localUrl == url) return;
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
|
|
||||||
if (api.configuration.configuration.accessToken) {
|
if (accessTokenInfo) {
|
||||||
headers.set("Authorization", api.configuration.configuration.accessToken);
|
headers.set("Authorization", "Bearer " + accessTokenInfo.access_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(localUrl, {
|
fetch(localUrl, {
|
||||||
@@ -68,7 +72,7 @@ const useMp3 = (api: DefaultApi, id: string): Mp3Response => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getMp3(id);
|
getMp3(id);
|
||||||
}, [id]);
|
}, [id, api]);
|
||||||
|
|
||||||
return { url, blob, loading, error };
|
return { url, blob, loading, error };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user