Skip to content

Commit

Permalink
fix: updated srt-delete fetch and added label reset in mv
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Nov 12, 2024
1 parent 3d8435d commit 347c867
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import { NextRequest, NextResponse } from 'next/server';
import { isAuthenticated } from '../../../../../../api/manager/auth';
import { deleteSrtSource } from '../../../../../../api/ateliereLive/ingest';
import { Log } from '../../../../../../api/logger';
import {
getUuidFromIngestName,
getSourceIdFromSourceName
} from '../../../../../../api/ateliereLive/ingest';

type Params = {
ingest_name: string;
ingest_source_name: string;
ingest_uuid: string;
ingest_source_id: number;
};

export async function DELETE(
Expand All @@ -22,23 +18,15 @@ export async function DELETE(
});
}

const ingestUuid = await getUuidFromIngestName(params.ingest_name, false);
const sourceId = ingestUuid
? await getSourceIdFromSourceName(
ingestUuid,
params.ingest_source_name,
false
)
: 0;
return await deleteSrtSource(ingestUuid || '', sourceId || 0)
return await deleteSrtSource(params.ingest_uuid, params.ingest_source_id)
.then((response) => {
return new NextResponse(JSON.stringify(response));
})
.catch((error) => {
Log().error(error);
const errorResponse = {
ok: false,
error: 'unexpected'
error: 'Failed to delete SRT source'
};
return new NextResponse(JSON.stringify(errorResponse), { status: 500 });
});
Expand Down
35 changes: 24 additions & 11 deletions src/hooks/sources/useDeleteSource.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
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];
}
3 changes: 2 additions & 1 deletion src/hooks/useUpdateSourceInputSlotOnMultiviewLayouts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export function useUpdateSourceInputSlotOnMultiviewLayouts(): CallbackHook<
} else {
return {
...view,
input_slot: 0
input_slot: 0,
label: ''
};
}
}
Expand Down

0 comments on commit 347c867

Please sign in to comment.