Skip to content

Commit

Permalink
feat!: SOF-1081 Only clean Shows that belongs to Sofie
Browse files Browse the repository at this point in the history
  • Loading branch information
LindvedKrvang committed Nov 9, 2022
1 parent 4302be3 commit b5889e3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"build": "rimraf dist && yarn build:main",
"buildtest": "yarn build && jest",
"build:main": "tsc -p tsconfig.build.json",
"lint": "eslint . --ext .ts --ext .js --ext .tsx --ext .jsx --ignore-pattern dist",
"lint": "eslint . --ext .ts --ext .js --ext .tsx --ext .jsx --ignore-pattern dist --ignore-pattern docs",
"lint-fix": "yarn lint --fix",
"unitci": "jest",
"unit": "jest",
Expand Down Expand Up @@ -96,7 +96,7 @@
"watch-server": "Run HTTP server and restart when changes are made."
},
"engines": {
"node": ">=10.10"
"node": "^16.17"
},
"prettier": "@sofie-automation/code-standard-preset/.prettierrc.json",
"lint-staged": {
Expand Down
46 changes: 37 additions & 9 deletions src/rundown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,47 @@ ${entries}
return this.msehttp.cleanupShow(showId)
}

async cleanupAllShows(): Promise<CommandResult[]> {
const showIds: string[] = await this.findAllShowIds()
await this.purgeInternalElements(showIds, true)
async cleanupAllSofieShows(): Promise<CommandResult[]> {
const showIds: string[] = await this.findAllSofieShowIds()
await this.purgeInternalElements(showIds, false)
return Promise.all(showIds.map(async (showId) => this.cleanupShow(showId)))
}

private async findAllShowIds(): Promise<string[]> {
private async findAllSofieShowIds(): Promise<string[]> {
await this.mse.checkConnection()
const shows = await this.pep.getJS(`/storage/shows`, 1)
const flatEntry: FlatEntry = await flattenEntry(shows.js as AtomEntry)
return Object.keys(flatEntry)
.map((entry) => entry)
.filter((entry) => entry.startsWith('{'))
const pepResponseJS = await this.pep.getJS(`/storage/shows`, 1)
const shows: FlatEntry = await flattenEntry(pepResponseJS.js as AtomEntry)

const settledResultShowIds: PromiseSettledResult<string>[] = await Promise.allSettled(
Object.keys(shows).map(this.isSofieShow.bind(this))
)
return this.mapToStringArray(settledResultShowIds).map(this.stripCurlyBrackets.bind(this))
}

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')
? Promise.resolve(showId)
: Promise.reject()
}

private mapToStringArray(settledResultShowIds: PromiseSettledResult<string>[]): string[] {
return settledResultShowIds.reduce((showIds: string[], promise: PromiseSettledResult<string>) => {
if (promise.status === 'fulfilled') {
return [...showIds, promise.value]
}
return showIds
}, [] as string[])
}

private stripCurlyBrackets(value: string): string {
return value.replace('{', '').replace('}', '')
}

async activate(twice?: boolean, initPlaylist = true): Promise<CommandResult> {
Expand Down
2 changes: 1 addition & 1 deletion src/v-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export interface VRundown {
*/
cleanupShow(showId: string): Promise<CommandResult>

cleanupAllShows(): Promise<CommandResult[]>
cleanupAllSofieShows(): Promise<CommandResult[]>

/**
* Clear up all Internal Elements and state associated with given shows,
Expand Down

0 comments on commit b5889e3

Please sign in to comment.