Skip to content

Commit

Permalink
Refactor to remove bucket from env
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcretu committed Sep 9, 2024
1 parent c2e9445 commit aa017a7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ui/src/hooks/useTimestampFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -45,21 +43,19 @@ export function useTimestampFetcher(
const [timestamp, setTimestamp] = useState<number>();

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;

useEffect(() => {
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);
Expand All @@ -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;
};

Expand Down

0 comments on commit aa017a7

Please sign in to comment.