Skip to content

Commit 6550898

Browse files
committed
chore: make sure we are using the playlistExternalId in ingestRundown
1 parent 8ac0bb7 commit 6550898

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

meteor/server/api/rest/v1/ingest.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -457,43 +457,60 @@ class IngestServerAPI implements IngestRestAPI {
457457
_event: string,
458458
studioId: StudioId,
459459
playlistId: string | undefined,
460-
ingestRundown: RestApiIngestRundown
460+
rawIngestRundown: RestApiIngestRundown
461461
): Promise<ClientAPI.ClientResponse<void>> {
462462
check(studioId, String)
463463
if (playlistId !== undefined) check(playlistId, String)
464-
check(ingestRundown, Object)
464+
check(rawIngestRundown, Object)
465465

466466
const studio = await this.findStudio(studioId)
467467

468-
this.validateRundown(ingestRundown)
469-
await this.validateAPIPayloadsForRundown(studio.blueprintId, ingestRundown)
468+
this.validateRundown(rawIngestRundown)
469+
await this.validateAPIPayloadsForRundown(studio.blueprintId, rawIngestRundown)
470470

471471
// IMPORTANT: Do not scope rundown existence checks by playlistId.
472472
// Rundowns are unique per studio, not per playlist.
473473
const existingRundown = await Rundowns.findOneAsync({
474474
$or: [
475475
{
476-
_id: protectString<RundownId>(ingestRundown.externalId),
476+
_id: protectString<RundownId>(rawIngestRundown.externalId),
477477
studioId: studio._id,
478478
},
479479
{
480-
externalId: ingestRundown.externalId,
480+
externalId: rawIngestRundown.externalId,
481481
studioId: studio._id,
482482
},
483483
],
484484
})
485485
if (existingRundown) {
486-
throw new Meteor.Error(400, `Rundown '${ingestRundown.externalId}' already exists`)
486+
throw new Meteor.Error(400, `Rundown '${rawIngestRundown.externalId}' already exists`)
487487
}
488488

489+
// We look up the playlist to look up the existing playlistExternalId
490+
// to make sure we don't treat the internal playlistId as a playlistExternalId.
491+
const playlist =
492+
playlistId !== undefined
493+
? await RundownPlaylists.findOneAsync({
494+
$or: [
495+
{ _id: protectString<RundownPlaylistId>(playlistId), studioId: studio._id },
496+
{ externalId: playlistId, studioId: studio._id },
497+
],
498+
})
499+
: undefined
500+
501+
const ingestRundown =
502+
// If we don't have a playlist Id, then we don't override the playlistExternalId property of the rundown.
503+
playlistId === undefined
504+
? rawIngestRundown
505+
: { ...rawIngestRundown, playlistExternalId: playlist?.externalId ?? playlistId } // We override if the endpoint specified the playlist.
506+
489507
await runIngestOperation(studio._id, IngestJobs.UpdateRundown, {
490-
rundownExternalId: ingestRundown.externalId,
491-
ingestRundown:
492-
playlistId !== undefined ? { ...ingestRundown, playlistExternalId: playlistId } : ingestRundown,
508+
rundownExternalId: rawIngestRundown.externalId,
509+
ingestRundown,
493510
isCreateAction: true,
494511
rundownSource: {
495512
type: 'restApi',
496-
resyncUrl: ingestRundown.resyncUrl,
513+
resyncUrl: rawIngestRundown.resyncUrl,
497514
},
498515
})
499516

0 commit comments

Comments
 (0)