aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/lib/plugins/register-helpers.ts28
-rw-r--r--server/tests/fixtures/peertube-plugin-test-video-constants/main.js (renamed from server/tests/fixtures/peertube-plugin-test-three/main.js)2
-rw-r--r--server/tests/fixtures/peertube-plugin-test-video-constants/package.json (renamed from server/tests/fixtures/peertube-plugin-test-three/package.json)4
-rw-r--r--server/tests/plugins/video-constants.ts6
4 files changed, 27 insertions, 13 deletions
diff --git a/server/lib/plugins/register-helpers.ts b/server/lib/plugins/register-helpers.ts
index f5b573370..09275f9ba 100644
--- a/server/lib/plugins/register-helpers.ts
+++ b/server/lib/plugins/register-helpers.ts
@@ -37,18 +37,20 @@ type VideoConstant = { [key in number | string]: string }
37 37
38type UpdatedVideoConstant = { 38type UpdatedVideoConstant = {
39 [name in AlterableVideoConstant]: { 39 [name in AlterableVideoConstant]: {
40 added: { key: number | string, label: string }[] 40 [ npmName: string]: {
41 deleted: { key: number | string, label: string }[] 41 added: { key: number | string, label: string }[]
42 deleted: { key: number | string, label: string }[]
43 }
42 } 44 }
43} 45}
44 46
45export class RegisterHelpers { 47export class RegisterHelpers {
46 private readonly updatedVideoConstants: UpdatedVideoConstant = { 48 private readonly updatedVideoConstants: UpdatedVideoConstant = {
47 playlistPrivacy: { added: [], deleted: [] }, 49 playlistPrivacy: { },
48 privacy: { added: [], deleted: [] }, 50 privacy: { },
49 language: { added: [], deleted: [] }, 51 language: { },
50 licence: { added: [], deleted: [] }, 52 licence: { },
51 category: { added: [], deleted: [] } 53 category: { }
52 } 54 }
53 55
54 private readonly transcodingProfiles: { 56 private readonly transcodingProfiles: {
@@ -377,7 +379,7 @@ export class RegisterHelpers {
377 const { npmName, type, obj, key } = parameters 379 const { npmName, type, obj, key } = parameters
378 380
379 if (!obj[key]) { 381 if (!obj[key]) {
380 logger.warn('Cannot delete %s %s by plugin %s: key does not exist.', type, npmName, key) 382 logger.warn('Cannot delete %s by plugin %s: key %s does not exist.', type, npmName, key)
381 return false 383 return false
382 } 384 }
383 385
@@ -388,7 +390,15 @@ export class RegisterHelpers {
388 } 390 }
389 } 391 }
390 392
391 this.updatedVideoConstants[type][npmName].deleted.push({ key, label: obj[key] }) 393 const updatedConstants = this.updatedVideoConstants[type][npmName]
394
395 const alreadyAdded = updatedConstants.added.find(a => a.key === key)
396 if (alreadyAdded) {
397 updatedConstants.added.filter(a => a.key !== key)
398 } else if (obj[key]) {
399 updatedConstants.deleted.push({ key, label: obj[key] })
400 }
401
392 delete obj[key] 402 delete obj[key]
393 403
394 return true 404 return true
diff --git a/server/tests/fixtures/peertube-plugin-test-three/main.js b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js
index f2b89bcf0..3e650e0a1 100644
--- a/server/tests/fixtures/peertube-plugin-test-three/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js
@@ -11,8 +11,10 @@ async function register ({
11}) { 11}) {
12 videoLanguageManager.addLanguage('al_bhed', 'Al Bhed') 12 videoLanguageManager.addLanguage('al_bhed', 'Al Bhed')
13 videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2') 13 videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2')
14 videoLanguageManager.addLanguage('al_bhed3', 'Al Bhed 3')
14 videoLanguageManager.deleteLanguage('en') 15 videoLanguageManager.deleteLanguage('en')
15 videoLanguageManager.deleteLanguage('fr') 16 videoLanguageManager.deleteLanguage('fr')
17 videoLanguageManager.deleteLanguage('al_bhed3')
16 18
17 videoCategoryManager.addCategory(42, 'Best category') 19 videoCategoryManager.addCategory(42, 'Best category')
18 videoCategoryManager.addCategory(43, 'High best category') 20 videoCategoryManager.addCategory(43, 'High best category')
diff --git a/server/tests/fixtures/peertube-plugin-test-three/package.json b/server/tests/fixtures/peertube-plugin-test-video-constants/package.json
index 41d4c93fe..0fcf39933 100644
--- a/server/tests/fixtures/peertube-plugin-test-three/package.json
+++ b/server/tests/fixtures/peertube-plugin-test-video-constants/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "name": "peertube-plugin-test-three", 2 "name": "peertube-plugin-test-video-constants",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "description": "Plugin test 3", 4 "description": "Plugin test video constants",
5 "engine": { 5 "engine": {
6 "peertube": ">=1.3.0" 6 "peertube": ">=1.3.0"
7 }, 7 },
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index 5ee41fee1..eb014c596 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -32,7 +32,7 @@ describe('Test plugin altering video constants', function () {
32 await installPlugin({ 32 await installPlugin({
33 url: server.url, 33 url: server.url,
34 accessToken: server.accessToken, 34 accessToken: server.accessToken,
35 path: getPluginTestPath('-three') 35 path: getPluginTestPath('-video-constants')
36 }) 36 })
37 }) 37 })
38 38
@@ -45,6 +45,7 @@ describe('Test plugin altering video constants', function () {
45 45
46 expect(languages['al_bhed']).to.equal('Al Bhed') 46 expect(languages['al_bhed']).to.equal('Al Bhed')
47 expect(languages['al_bhed2']).to.equal('Al Bhed 2') 47 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
48 expect(languages['al_bhed3']).to.not.exist
48 }) 49 })
49 50
50 it('Should have updated categories', async function () { 51 it('Should have updated categories', async function () {
@@ -116,7 +117,7 @@ describe('Test plugin altering video constants', function () {
116 }) 117 })
117 118
118 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { 119 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
119 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-three' }) 120 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' })
120 121
121 { 122 {
122 const res = await getVideoLanguages(server.url) 123 const res = await getVideoLanguages(server.url)
@@ -127,6 +128,7 @@ describe('Test plugin altering video constants', function () {
127 128
128 expect(languages['al_bhed']).to.not.exist 129 expect(languages['al_bhed']).to.not.exist
129 expect(languages['al_bhed2']).to.not.exist 130 expect(languages['al_bhed2']).to.not.exist
131 expect(languages['al_bhed3']).to.not.exist
130 } 132 }
131 133
132 { 134 {