- private buildVideoLanguageManager (): PluginVideoLanguageManager {
- return {
- addLanguage: (key: string, label: string) => {
- return this.addConstant({ npmName: this.npmName, type: 'language', obj: VIDEO_LANGUAGES, key, label })
- },
-
- deleteLanguage: (key: string) => {
- return this.deleteConstant({ npmName: this.npmName, type: 'language', obj: VIDEO_LANGUAGES, key })
- }
- }
- }
-
- private buildVideoCategoryManager (): PluginVideoCategoryManager {
- return {
- addCategory: (key: number, label: string) => {
- return this.addConstant({ npmName: this.npmName, type: 'category', obj: VIDEO_CATEGORIES, key, label })
- },
-
- deleteCategory: (key: number) => {
- return this.deleteConstant({ npmName: this.npmName, type: 'category', obj: VIDEO_CATEGORIES, key })
- }
- }
- }
-
- private buildVideoPrivacyManager (): PluginVideoPrivacyManager {
- return {
- deletePrivacy: (key: number) => {
- return this.deleteConstant({ npmName: this.npmName, type: 'privacy', obj: VIDEO_PRIVACIES, key })
- }
- }
- }
-
- private buildPlaylistPrivacyManager (): PluginPlaylistPrivacyManager {
- return {
- deletePlaylistPrivacy: (key: number) => {
- return this.deleteConstant({ npmName: this.npmName, type: 'playlistPrivacy', obj: VIDEO_PLAYLIST_PRIVACIES, key })
- }
- }
- }
-
- private buildVideoLicenceManager (): PluginVideoLicenceManager {
- return {
- addLicence: (key: number, label: string) => {
- return this.addConstant({ npmName: this.npmName, type: 'licence', obj: VIDEO_LICENCES, key, label })
- },
-
- deleteLicence: (key: number) => {
- return this.deleteConstant({ npmName: this.npmName, type: 'licence', obj: VIDEO_LICENCES, key })
- }
- }
- }
-
- private addConstant<T extends string | number> (parameters: {
- npmName: string
- type: AlterableVideoConstant
- obj: VideoConstant
- key: T
- label: string
- }) {
- const { npmName, type, obj, key, label } = parameters
-
- if (obj[key]) {
- logger.warn('Cannot add %s %s by plugin %s: key already exists.', type, npmName, key)
- return false
- }
-
- if (!this.updatedVideoConstants[type][npmName]) {
- this.updatedVideoConstants[type][npmName] = {
- added: [],
- deleted: []
- }
- }
-
- this.updatedVideoConstants[type][npmName].added.push({ key, label })
- obj[key] = label
-
- return true
- }
-
- private deleteConstant<T extends string | number> (parameters: {
- npmName: string
- type: AlterableVideoConstant
- obj: VideoConstant
- key: T
- }) {
- 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)
- return false
- }
-
- if (!this.updatedVideoConstants[type][npmName]) {
- this.updatedVideoConstants[type][npmName] = {
- added: [],
- deleted: []
- }
- }
-
- this.updatedVideoConstants[type][npmName].deleted.push({ key, label: obj[key] })
- delete obj[key]
-
- return true
- }
-