Skip to content

Commit

Permalink
fix: SOF-1081 Refactor duplicated logic away
Browse files Browse the repository at this point in the history
  • Loading branch information
LindvedKrvang committed Nov 9, 2022
1 parent f855545 commit b6737fb
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/rundown.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
VRundown,
VTemplate,
InternalElement,
ElementId,
ExternalElement,
VElement,
ExternalElementId,
ElementId,
isExternalElement,
InternalElement,
InternalElementId,
isInternalElement,
InternalElementIdWithCreator,
isExternalElement,
isInternalElement,
VElement,
VRundown,
VTemplate,
} from './v-connection'
import { CommandResult, createHTTPContext, HttpMSEClient, HTTPRequestError } from './msehttp'
import { getPepErrorMessage, InexistentError, LocationType, PepResponse } from './peptalk'
import { CREATOR_NAME, MSERep } from './mse'
import { flattenEntry, AtomEntry, FlatEntry } from './xml'
import { AtomEntry, FlatEntry, flattenEntry } from './xml'
import * as uuid from 'uuid'
import { has, wrapInBracesIfNeeded } from './util'

Expand Down Expand Up @@ -247,16 +247,16 @@ ${entries}

async listInternalElements(showId: string): Promise<InternalElementIdWithCreator[]> {
await this.mse.checkConnection()
const showElementsList = await this.pep.getJS(`/storage/shows/{${showId}}/elements`, 1)
const flatShowElements = await flattenEntry(showElementsList.js as AtomEntry)
const elementNames: Array<InternalElementIdWithCreator> = Object.keys(flatShowElements)
const pepResponseJS = await this.pep.getJS(`/storage/shows/${wrapInBracesIfNeeded(showId)}/elements`, 1)
const flatEntry: FlatEntry = await flattenEntry(pepResponseJS.js as AtomEntry)
const elementsParentNode = flatEntry['elements'] as FlatEntry
return Object.keys(elementsParentNode)
.filter((x) => x !== 'name')
.map((element) => ({
instanceName: element,
.map((elementName) => ({
instanceName: elementName,
showId,
creator: (flatShowElements[element] as FlatEntry).creator as string | undefined,
creator: (elementsParentNode[elementName] as FlatEntry).creator as string | undefined,
}))
return elementNames
}

async listExternalElements(): Promise<Array<ExternalElementId>> {
Expand Down Expand Up @@ -299,14 +299,8 @@ ${entries}
}

private async isSofieShow(showId: string): Promise<string> {
const pepResponseJS = await this.pep.getJS(`/storage/shows/${showId}/elements`, 1)
const flatEntry: FlatEntry = await flattenEntry(pepResponseJS.js as AtomEntry)
const elementsParentNode = flatEntry['elements'] as FlatEntry
if (!elementsParentNode) {
return Promise.reject()
}
const elements: FlatEntry[] = Object.values(elementsParentNode) as FlatEntry[]
return elements.find((element: FlatEntry) => element['creator'] === 'Sofie')
const elements: InternalElementIdWithCreator[] = await this.listInternalElements(showId)
return elements.find((element: InternalElementIdWithCreator) => element.creator === CREATOR_NAME)
? Promise.resolve(showId)
: Promise.reject()
}
Expand Down

0 comments on commit b6737fb

Please sign in to comment.