From aa017a70bbb2274be5127313112e54450e4dc92c Mon Sep 17 00:00:00 2001 From: Paul Cretu Date: Mon, 9 Sep 2024 23:53:45 +0000 Subject: [PATCH] Refactor to remove bucket from env --- ui/src/hooks/useTimestampFetcher.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ui/src/hooks/useTimestampFetcher.ts b/ui/src/hooks/useTimestampFetcher.ts index 0f9df248..d4e54c92 100644 --- a/ui/src/hooks/useTimestampFetcher.ts +++ b/ui/src/hooks/useTimestampFetcher.ts @@ -4,8 +4,6 @@ if (!process.env.NEXT_PUBLIC_S3_BUCKET) { throw new Error("NEXT_PUBLIC_S3_BUCKET is not set"); } -const S3_BUCKET = process.env.NEXT_PUBLIC_S3_BUCKET; - const getBucketBase = (bucket: string) => `https://${bucket}.s3.amazonaws.com`; const getTimestampURI = (bucket: string, nodeName: string) => @@ -45,11 +43,11 @@ export function useTimestampFetcher( const [timestamp, setTimestamp] = useState(); const hlsURI = - nodeName && timestamp - ? getHlsURI(bucket ?? S3_BUCKET, nodeName, timestamp) + nodeName && bucket && timestamp + ? getHlsURI(bucket, nodeName, timestamp) : undefined; const awsConsoleUri = - nodeName && timestamp + nodeName && bucket && timestamp ? `https://s3.console.aws.amazon.com/s3/buckets/${bucket}/${nodeName}/hls/${timestamp}/` : undefined; @@ -57,9 +55,7 @@ export function useTimestampFetcher( let currentXhr: XMLHttpRequest | undefined; let intervalId: NodeJS.Timeout | undefined; - const fetchTimestamp = (feed: string) => { - const timestampURI = getTimestampURI(bucket ?? S3_BUCKET, feed); - + const fetchTimestamp = (timestampURI: string) => { const xhr = new XMLHttpRequest(); currentXhr = xhr; xhr.open("GET", timestampURI); @@ -75,11 +71,15 @@ export function useTimestampFetcher( }; const startFetcher = () => { - if (!nodeName) return; + if (!nodeName || !bucket) return; + const timestampURI = getTimestampURI(bucket, nodeName); onStart?.(); - fetchTimestamp(nodeName); - const newIntervalId = setInterval(() => fetchTimestamp(nodeName), 10000); + fetchTimestamp(timestampURI); + const newIntervalId = setInterval( + () => fetchTimestamp(timestampURI), + 10000, + ); intervalId = newIntervalId; };