1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

Add ability to delete previously added constants

This commit is contained in:
Chocobozzz 2021-06-15 15:18:11 +02:00
parent 4c3e4c3d93
commit 799ece6aae
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 27 additions and 13 deletions

View file

@ -37,18 +37,20 @@ type VideoConstant = { [key in number | string]: string }
type UpdatedVideoConstant = {
[name in AlterableVideoConstant]: {
added: { key: number | string, label: string }[]
deleted: { key: number | string, label: string }[]
[ npmName: string]: {
added: { key: number | string, label: string }[]
deleted: { key: number | string, label: string }[]
}
}
}
export class RegisterHelpers {
private readonly updatedVideoConstants: UpdatedVideoConstant = {
playlistPrivacy: { added: [], deleted: [] },
privacy: { added: [], deleted: [] },
language: { added: [], deleted: [] },
licence: { added: [], deleted: [] },
category: { added: [], deleted: [] }
playlistPrivacy: { },
privacy: { },
language: { },
licence: { },
category: { }
}
private readonly transcodingProfiles: {
@ -377,7 +379,7 @@ export class RegisterHelpers {
const { npmName, type, obj, key } = parameters
if (!obj[key]) {
logger.warn('Cannot delete %s %s by plugin %s: key does not exist.', type, npmName, key)
logger.warn('Cannot delete %s by plugin %s: key %s does not exist.', type, npmName, key)
return false
}
@ -388,7 +390,15 @@ export class RegisterHelpers {
}
}
this.updatedVideoConstants[type][npmName].deleted.push({ key, label: obj[key] })
const updatedConstants = this.updatedVideoConstants[type][npmName]
const alreadyAdded = updatedConstants.added.find(a => a.key === key)
if (alreadyAdded) {
updatedConstants.added.filter(a => a.key !== key)
} else if (obj[key]) {
updatedConstants.deleted.push({ key, label: obj[key] })
}
delete obj[key]
return true