forked from OwnZones/orchestration-gui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle missing srt-source in api on delete (#89)
* fix: handle missing srt-source in api on delete * fix: updated delete-fetch to return before fetch if source-id is not in api * fix: removed commented out code
- Loading branch information
Showing
2 changed files
with
30 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
import { useState } from 'react'; | ||
import { CallbackHook } from '../types'; | ||
import { API_SECRET_KEY } from '../../utils/constants'; | ||
import { useIngests, useIngestSources } from '../ingests'; | ||
|
||
export function useDeleteSrtSource(): CallbackHook< | ||
(ingest_name: string, ingest_source_name: string) => void | ||
> { | ||
const [deleteSrtLoading, setDeleteSrtLoading] = useState<boolean>(false); | ||
const ingests = useIngests(); | ||
const [getSources] = useIngestSources(); | ||
|
||
const deleteSrtSource = async ( | ||
ingest_name: string, | ||
ingest_source_name: string | ||
) => { | ||
setDeleteSrtLoading(true); | ||
return fetch(`/api/manager/srt/${ingest_name}/${ingest_source_name}/`, { | ||
method: 'DELETE', | ||
headers: [['x-api-key', `Bearer ${API_SECRET_KEY}`]] | ||
}) | ||
.then(async (response) => { | ||
if (response.ok) { | ||
return response.json(); | ||
} | ||
throw await response.text; | ||
const ingestUuid = | ||
ingests.find((ingest) => ingest.name === ingest_name)?.uuid || ''; | ||
|
||
const sources = await getSources(ingest_name); | ||
const sourceId = sources.find( | ||
(source) => source.name === ingest_source_name | ||
)?.source_id; | ||
|
||
if (ingestUuid !== '' && sourceId !== undefined) { | ||
return fetch(`/api/manager/srt/${ingestUuid}/${sourceId}/`, { | ||
method: 'DELETE', | ||
headers: [['x-api-key', `Bearer ${API_SECRET_KEY}`]] | ||
}) | ||
.finally(() => setDeleteSrtLoading(false)); | ||
.then(async (response) => { | ||
if (response.ok) { | ||
return response.json(); | ||
} | ||
throw response.text; | ||
}) | ||
.finally(() => setDeleteSrtLoading(false)); | ||
} else { | ||
setDeleteSrtLoading(false); | ||
return; | ||
} | ||
}; | ||
return [deleteSrtSource, deleteSrtLoading]; | ||
} |