Skip to content

Commit

Permalink
fix: rundown.deleteElement() didn't work
Browse files Browse the repository at this point in the history
Apparently the delete command requires an unescaped path, in contrast to the others whic uses an escaped path.
  • Loading branch information
nytamin committed Sep 17, 2021
1 parent 201f289 commit 645e486
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/rundown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,18 @@ export class Rundown implements VRundown {
: false
}

private ref(vcpid: number, channel?: string): string {
private ref(vcpid: number, channel?: string, unescape = false): string {
const key = Rundown.makeKey(vcpid, channel)
return this.channelMap[key]?.refName ? this.channelMap[key].refName.replace('#', '%23') : 'ref'
let str = this.channelMap[key]?.refName || 'ref'

if (unescape) {
// Return the unescaped string
str = str.replace('%23', '#')
} else {
// Return the escaped string
str = str.replace('#', '%23')
}
return str
}

async listTemplates(): Promise<string[]> {
Expand Down Expand Up @@ -265,7 +274,8 @@ ${entries}
if (typeof elementName === 'string') {
return this.pep.delete(`/storage/shows/{${this.show}}/elements/${elementName}`)
} else {
const path = this.getExternalElementPath(elementName, channel)
// Note: For some reason, in contrast to the other commands, the delete command only works with the path being unescaped:
const path = this.getExternalElementPath(elementName, channel, true)
if (await this.buildChannelMap(elementName, channel)) {
return this.pep.delete(path)
} else {
Expand Down Expand Up @@ -440,7 +450,7 @@ ${entries}
return playlist.active_profile && typeof playlist.active_profile.value !== 'undefined'
}

private getExternalElementPath(elementName: number, channel?: string): string {
return `/storage/playlists/{${this.playlist}}/elements/${this.ref(elementName, channel)}`
private getExternalElementPath(elementName: number, channel?: string, unescape = false): string {
return `/storage/playlists/{${this.playlist}}/elements/${this.ref(elementName, channel, unescape)}`
}
}

0 comments on commit 645e486

Please sign in to comment.