From 6d3062539961c881858d10d29acaf16788c0c068 Mon Sep 17 00:00:00 2001 From: Saelmala Date: Mon, 26 Aug 2024 10:40:02 +0200 Subject: [PATCH] fix: add ingest type to database --- src/api/manager/job/syncInventory.ts | 7 ++- .../manager/sources/resources/[id]/route.ts | 24 ---------- .../api/manager/sources/resources/route.ts | 17 ------- src/components/filter/FilterOptions.tsx | 30 +++++------- src/hooks/sources/useResources.tsx | 48 ------------------- src/interfaces/Source.ts | 1 + 6 files changed, 17 insertions(+), 110 deletions(-) delete mode 100644 src/app/api/manager/sources/resources/[id]/route.ts delete mode 100644 src/app/api/manager/sources/resources/route.ts delete mode 100644 src/hooks/sources/useResources.tsx diff --git a/src/api/manager/job/syncInventory.ts b/src/api/manager/job/syncInventory.ts index e5635670..1e225469 100644 --- a/src/api/manager/job/syncInventory.ts +++ b/src/api/manager/job/syncInventory.ts @@ -27,6 +27,7 @@ async function getSourcesFromAPI() { }, ingest_name: ingest.name, ingest_source_name: source.name, + ingest_type: source.type, video_stream: { width: source?.video_stream?.width, height: source?.video_stream?.height, @@ -60,7 +61,8 @@ export async function runSyncInventory() { const apiSource = apiSources.find((source) => { return ( source.ingest_name === inventorySource.ingest_name && - source.ingest_source_name === inventorySource.ingest_source_name + source.ingest_source_name === inventorySource.ingest_source_name && + source.ingest_type === inventorySource.type ); }); if (!apiSource) { @@ -81,7 +83,8 @@ export async function runSyncInventory() { (inventorySource) => { return ( source.ingest_name === inventorySource.ingest_name && - source.ingest_source_name === inventorySource.ingest_source_name + source.ingest_source_name === inventorySource.ingest_source_name && + source.ingest_type === inventorySource.ingest_type ); } ); diff --git a/src/app/api/manager/sources/resources/[id]/route.ts b/src/app/api/manager/sources/resources/[id]/route.ts deleted file mode 100644 index e1b68b78..00000000 --- a/src/app/api/manager/sources/resources/[id]/route.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { NextResponse, NextRequest } from 'next/server'; -import { getIngestSources } from '../../../../../../api/agileLive/ingest'; -import { isAuthenticated } from '../../../../../../api/manager/auth'; - -type Params = { - id: string; -}; - -export async function GET( - request: NextRequest, - { params }: { params: Params } -): Promise { - if (!(await isAuthenticated())) { - return new NextResponse(`Not Authorized!`, { - status: 403 - }); - } - - try { - return NextResponse.json(await getIngestSources(params.id)); - } catch (e) { - return new NextResponse(e?.toString(), { status: 404 }); - } -} diff --git a/src/app/api/manager/sources/resources/route.ts b/src/app/api/manager/sources/resources/route.ts deleted file mode 100644 index 64200693..00000000 --- a/src/app/api/manager/sources/resources/route.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { NextResponse } from 'next/server'; -import { isAuthenticated } from '../../../../../api/manager/auth'; -import { getIngests } from '../../../../../api/agileLive/ingest'; - -export async function GET(): Promise { - if (!(await isAuthenticated())) { - return new NextResponse(`Not Authorized!`, { - status: 403 - }); - } - - try { - return NextResponse.json(await getIngests()); - } catch (e) { - return new NextResponse(e?.toString(), { status: 404 }); - } -} diff --git a/src/components/filter/FilterOptions.tsx b/src/components/filter/FilterOptions.tsx index 5eaeb81c..af8aa674 100644 --- a/src/components/filter/FilterOptions.tsx +++ b/src/components/filter/FilterOptions.tsx @@ -5,7 +5,6 @@ import FilterDropdown from './FilterDropdown'; import { ClickAwayListener } from '@mui/base'; import { SourceWithId } from '../../interfaces/Source'; import { FilterContext } from '../inventory/FilterContext'; -import { useResources } from '../../hooks/sources/useResources'; type FilterOptionsProps = { onFilteredSources: (sources: Map) => void; @@ -13,7 +12,6 @@ type FilterOptionsProps = { function FilterOptions({ onFilteredSources }: FilterOptionsProps) { const { locations, types, sources } = useContext(FilterContext); - const [resources] = useResources(); const [onlyShowActiveSources, setOnlyShowActiveSources] = useState(false); const [onlyShowNdiSources, setOnlyShowNdiSources] = useState(false); @@ -107,21 +105,15 @@ function FilterOptions({ onFilteredSources }: FilterOptionsProps) { const filterSources = async () => { for (const source of tempSet.values()) { - const correspondingResource = resources.find( - (resource) => resource.name === source.ingest_source_name - ); + let shouldDelete = false; - if (correspondingResource) { - let shouldDelete = false; + if (source.ingest_type) { const isNdiSelected = - onlyShowNdiSources && - correspondingResource.type.toUpperCase() === 'NDI'; + onlyShowNdiSources && source.ingest_type.toUpperCase() === 'NDI'; const isBmdSelected = - onlyShowBmdSources && - correspondingResource.type.toUpperCase() === 'BMD'; + onlyShowBmdSources && source.ingest_type.toUpperCase() === 'BMD'; const isSrtSelected = - onlyShowSrtSources && - correspondingResource.type.toUpperCase() === 'SRT'; + onlyShowSrtSources && source.ingest_type.toUpperCase() === 'SRT'; if ( (onlyShowNdiSources || onlyShowBmdSources || onlyShowSrtSources) && @@ -131,14 +123,14 @@ function FilterOptions({ onFilteredSources }: FilterOptionsProps) { ) { shouldDelete = true; } + } - if (onlyShowActiveSources && source.status === 'gone') { - shouldDelete = true; - } + if (onlyShowActiveSources && source.status === 'gone') { + shouldDelete = true; + } - if (shouldDelete) { - tempSet.delete(source._id.toString()); - } + if (shouldDelete) { + tempSet.delete(source._id.toString()); } } }; diff --git a/src/hooks/sources/useResources.tsx b/src/hooks/sources/useResources.tsx deleted file mode 100644 index 607c34a4..00000000 --- a/src/hooks/sources/useResources.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { - ResourcesSourceResponse, - ResourcesCompactIngestResponse -} from '../../../types/agile-live'; -import { useState, useEffect } from 'react'; - -export function useResources() { - const [ingests, setIngests] = useState([]); - const [resources, setResources] = useState([]); - - useEffect(() => { - let isMounted = true; - - const getIngests = async () => - await fetch(`/api/manager/sources/resources`, { - method: 'GET', - headers: [['x-api-key', `Bearer apisecretkey`]] - }).then(async (response) => { - const ing = await response.json(); - if (isMounted) { - setIngests(ing); - } - }); - getIngests(); - return () => { - isMounted = false; - }; - }, []); - - useEffect(() => { - if (ingests) { - for (let i = 0; i < ingests.length; i++) { - const id = ingests[i].uuid; - if (id) { - fetch(`/api/manager/sources/resources/${id}`, { - method: 'GET', - headers: [['x-api-key', `Bearer apisecretkey`]] - }).then(async (response) => { - const sources = await response.json(); - setResources(sources); - }); - } - } - } - }, [ingests]); - - return [resources]; -} diff --git a/src/interfaces/Source.ts b/src/interfaces/Source.ts index 99e57042..abf5c995 100644 --- a/src/interfaces/Source.ts +++ b/src/interfaces/Source.ts @@ -26,6 +26,7 @@ export interface Source { }; ingest_name: string; ingest_source_name: string; + ingest_type: string; video_stream: VideoStream; audio_stream: AudioStream; }