aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-17 09:09:06 +0100
committerChocobozzz <me@florianbigard.com>2022-03-17 09:09:06 +0100
commit2769876fb26742f5cc8aa4b761be7bafca97d18d (patch)
tree250988e78313840b15f925a40d20c7109adb4ab5
parent52fe4b671a20c37ae46cf88d175dd16cddfc4de7 (diff)
downloadPeerTube-2769876fb26742f5cc8aa4b761be7bafca97d18d.tar.gz
PeerTube-2769876fb26742f5cc8aa4b761be7bafca97d18d.tar.zst
PeerTube-2769876fb26742f5cc8aa4b761be7bafca97d18d.zip
Fix client html cache on theme update
-rw-r--r--server/lib/client-html.ts5
-rw-r--r--server/lib/plugins/plugin-manager.ts8
-rw-r--r--server/tests/api/check-params/video-editor.ts3
-rw-r--r--server/tests/api/server/plugins.ts104
-rw-r--r--shared/server-commands/server/config-command.ts15
5 files changed, 85 insertions, 50 deletions
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index 0142b248b..38697401a 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -12,7 +12,6 @@ import { HTMLServerConfig } from '@shared/models'
12import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' 12import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n'
13import { HttpStatusCode } from '../../shared/models/http/http-error-codes' 13import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
14import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' 14import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos'
15import { isTestInstance } from '../helpers/core-utils'
16import { logger } from '../helpers/logger' 15import { logger } from '../helpers/logger'
17import { CONFIG } from '../initializers/config' 16import { CONFIG } from '../initializers/config'
18import { 17import {
@@ -231,7 +230,7 @@ class ClientHtml {
231 static async getEmbedHTML () { 230 static async getEmbedHTML () {
232 const path = ClientHtml.getEmbedPath() 231 const path = ClientHtml.getEmbedPath()
233 232
234 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] 233 if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
235 234
236 const buffer = await readFile(path) 235 const buffer = await readFile(path)
237 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig() 236 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig()
@@ -303,7 +302,7 @@ class ClientHtml {
303 302
304 private static async getIndexHTML (req: express.Request, res: express.Response, paramLang?: string) { 303 private static async getIndexHTML (req: express.Request, res: express.Response, paramLang?: string) {
305 const path = ClientHtml.getIndexPath(req, res, paramLang) 304 const path = ClientHtml.getIndexPath(req, res, paramLang)
306 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] 305 if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
307 306
308 const buffer = await readFile(path) 307 const buffer = await readFile(path)
309 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig() 308 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig()
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 39e7f9a5b..1305f660f 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -277,6 +277,8 @@ export class PluginManager implements ServerHook {
277 logger.info('Regenerating registered plugin CSS to global file.') 277 logger.info('Regenerating registered plugin CSS to global file.')
278 await this.regeneratePluginGlobalCSS() 278 await this.regeneratePluginGlobalCSS()
279 } 279 }
280
281 ClientHtml.invalidCache()
280 } 282 }
281 283
282 // ###################### Installation ###################### 284 // ###################### Installation ######################
@@ -419,6 +421,8 @@ export class PluginManager implements ServerHook {
419 } 421 }
420 422
421 await this.addTranslations(plugin, npmName, packageJSON.translations) 423 await this.addTranslations(plugin, npmName, packageJSON.translations)
424
425 ClientHtml.invalidCache()
422 } 426 }
423 427
424 private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJSON) { 428 private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJSON) {
@@ -473,8 +477,6 @@ export class PluginManager implements ServerHook {
473 // ###################### CSS ###################### 477 // ###################### CSS ######################
474 478
475 private resetCSSGlobalFile () { 479 private resetCSSGlobalFile () {
476 ClientHtml.invalidCache()
477
478 return outputFile(PLUGIN_GLOBAL_CSS_PATH, '') 480 return outputFile(PLUGIN_GLOBAL_CSS_PATH, '')
479 } 481 }
480 482
@@ -482,8 +484,6 @@ export class PluginManager implements ServerHook {
482 for (const cssPath of cssRelativePaths) { 484 for (const cssPath of cssRelativePaths) {
483 await this.concatFiles(join(pluginPath, cssPath), PLUGIN_GLOBAL_CSS_PATH) 485 await this.concatFiles(join(pluginPath, cssPath), PLUGIN_GLOBAL_CSS_PATH)
484 } 486 }
485
486 ClientHtml.invalidCache()
487 } 487 }
488 488
489 private concatFiles (input: string, output: string) { 489 private concatFiles (input: string, output: string) {
diff --git a/server/tests/api/check-params/video-editor.ts b/server/tests/api/check-params/video-editor.ts
index 1fd22c497..5f5faf8fb 100644
--- a/server/tests/api/check-params/video-editor.ts
+++ b/server/tests/api/check-params/video-editor.ts
@@ -122,7 +122,10 @@ describe('Test video editor API validator', function () {
122 }) 122 })
123 123
124 it('Should fail with an already in transcoding state video', async function () { 124 it('Should fail with an already in transcoding state video', async function () {
125 this.timeout(30000)
126
125 const { uuid } = await server.videos.quickUpload({ name: 'transcoded video' }) 127 const { uuid } = await server.videos.quickUpload({ name: 'transcoded video' })
128 await waitJobs([ server ])
126 129
127 await server.jobs.pauseJobQueue() 130 await server.jobs.pauseJobQueue()
128 await server.videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' }) 131 await server.videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' })
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index 76d3e2481..8aa34fb15 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -95,15 +95,15 @@ describe('Test plugins', function () {
95 }) 95 })
96 96
97 it('Should have the plugin loaded in the configuration', async function () { 97 it('Should have the plugin loaded in the configuration', async function () {
98 const config = await server.config.getConfig() 98 for (const config of [ await server.config.getConfig(), await server.config.getIndexHTMLConfig() ]) {
99 99 const theme = config.theme.registered.find(r => r.name === 'background-red')
100 const theme = config.theme.registered.find(r => r.name === 'background-red') 100 expect(theme).to.not.be.undefined
101 expect(theme).to.not.be.undefined 101 expect(theme.npmName).to.equal('peertube-theme-background-red')
102 expect(theme.npmName).to.equal('peertube-theme-background-red') 102
103 103 const plugin = config.plugin.registered.find(r => r.name === 'hello-world')
104 const plugin = config.plugin.registered.find(r => r.name === 'hello-world') 104 expect(plugin).to.not.be.undefined
105 expect(plugin).to.not.be.undefined 105 expect(plugin.npmName).to.equal('peertube-plugin-hello-world')
106 expect(plugin.npmName).to.equal('peertube-plugin-hello-world') 106 }
107 }) 107 })
108 108
109 it('Should update the default theme in the configuration', async function () { 109 it('Should update the default theme in the configuration', async function () {
@@ -113,8 +113,9 @@ describe('Test plugins', function () {
113 } 113 }
114 }) 114 })
115 115
116 const config = await server.config.getConfig() 116 for (const config of [ await server.config.getConfig(), await server.config.getIndexHTMLConfig() ]) {
117 expect(config.theme.default).to.equal('background-red') 117 expect(config.theme.default).to.equal('background-red')
118 }
118 }) 119 })
119 120
120 it('Should update my default theme', async function () { 121 it('Should update my default theme', async function () {
@@ -228,45 +229,62 @@ describe('Test plugins', function () {
228 }) 229 })
229 230
230 it('Should update the plugin and the theme', async function () { 231 it('Should update the plugin and the theme', async function () {
231 this.timeout(90000) 232 this.timeout(180000)
232 233
233 // Wait the scheduler that get the latest plugins versions 234 // Wait the scheduler that get the latest plugins versions
234 await wait(6000) 235 await wait(6000)
235 236
236 // Fake update our plugin version 237 async function testUpdate (type: 'plugin' | 'theme', name: string) {
237 await server.sql.setPluginVersion('hello-world', '0.0.1') 238 // Fake update our plugin version
239 await server.sql.setPluginVersion(name, '0.0.1')
238 240
239 // Fake update package.json 241 // Fake update package.json
240 const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') 242 const packageJSON = await command.getPackageJSON(`peertube-${type}-${name}`)
241 const oldVersion = packageJSON.version 243 const oldVersion = packageJSON.version
242 244
243 packageJSON.version = '0.0.1' 245 packageJSON.version = '0.0.1'
244 await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON) 246 await command.updatePackageJSON(`peertube-${type}-${name}`, packageJSON)
245 247
246 // Restart the server to take into account this change 248 // Restart the server to take into account this change
247 await killallServers([ server ]) 249 await killallServers([ server ])
248 await server.run() 250 await server.run()
249 251
250 { 252 const checkConfig = async (version: string) => {
251 const body = await command.list({ pluginType: PluginType.PLUGIN }) 253 for (const config of [ await server.config.getConfig(), await server.config.getIndexHTMLConfig() ]) {
254 expect(config[type].registered.find(r => r.name === name).version).to.equal(version)
255 }
256 }
252 257
253 const plugin = body.data[0] 258 const getPluginFromAPI = async () => {
254 expect(plugin.version).to.equal('0.0.1') 259 const body = await command.list({ pluginType: type === 'plugin' ? PluginType.PLUGIN : PluginType.THEME })
255 expect(plugin.latestVersion).to.exist
256 expect(plugin.latestVersion).to.not.equal('0.0.1')
257 }
258 260
259 { 261 return body.data.find(p => p.name === name)
260 await command.update({ npmName: 'peertube-plugin-hello-world' }) 262 }
261 263
262 const body = await command.list({ pluginType: PluginType.PLUGIN }) 264 {
265 const plugin = await getPluginFromAPI()
266 expect(plugin.version).to.equal('0.0.1')
267 expect(plugin.latestVersion).to.exist
268 expect(plugin.latestVersion).to.not.equal('0.0.1')
269
270 await checkConfig('0.0.1')
271 }
272
273 {
274 await command.update({ npmName: `peertube-${type}-${name}` })
263 275
264 const plugin = body.data[0] 276 const plugin = await getPluginFromAPI()
265 expect(plugin.version).to.equal(oldVersion) 277 expect(plugin.version).to.equal(oldVersion)
266 278
267 const updatedPackageJSON = await command.getPackageJSON('peertube-plugin-hello-world') 279 const updatedPackageJSON = await command.getPackageJSON(`peertube-${type}-${name}`)
268 expect(updatedPackageJSON.version).to.equal(oldVersion) 280 expect(updatedPackageJSON.version).to.equal(oldVersion)
281
282 await checkConfig(oldVersion)
283 }
269 } 284 }
285
286 await testUpdate('theme', 'background-red')
287 await testUpdate('plugin', 'hello-world')
270 }) 288 })
271 289
272 it('Should uninstall the plugin', async function () { 290 it('Should uninstall the plugin', async function () {
@@ -293,15 +311,15 @@ describe('Test plugins', function () {
293 }) 311 })
294 312
295 it('Should have updated the configuration', async function () { 313 it('Should have updated the configuration', async function () {
296 const config = await server.config.getConfig() 314 for (const config of [ await server.config.getConfig(), await server.config.getIndexHTMLConfig() ]) {
315 expect(config.theme.default).to.equal('default')
297 316
298 expect(config.theme.default).to.equal('default') 317 const theme = config.theme.registered.find(r => r.name === 'background-red')
318 expect(theme).to.be.undefined
299 319
300 const theme = config.theme.registered.find(r => r.name === 'background-red') 320 const plugin = config.plugin.registered.find(r => r.name === 'hello-world')
301 expect(theme).to.be.undefined 321 expect(plugin).to.be.undefined
302 322 }
303 const plugin = config.plugin.registered.find(r => r.name === 'hello-world')
304 expect(plugin).to.be.undefined
305 }) 323 })
306 324
307 it('Should have updated the user theme', async function () { 325 it('Should have updated the user theme', async function () {
diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts
index e47a0d346..1dd6e1ea4 100644
--- a/shared/server-commands/server/config-command.ts
+++ b/shared/server-commands/server/config-command.ts
@@ -123,6 +123,21 @@ export class ConfigCommand extends AbstractCommand {
123 }) 123 })
124 } 124 }
125 125
126 async getIndexHTMLConfig (options: OverrideCommandOptions = {}) {
127 const text = await this.getRequestText({
128 ...options,
129
130 path: '/',
131 implicitToken: false,
132 defaultExpectedStatus: HttpStatusCode.OK_200
133 })
134
135 const match = text.match('<script type="application/javascript">window.PeerTubeServerConfig = (".+?")</script>')
136
137 // We parse the string twice, first to extract the string and then to extract the JSON
138 return JSON.parse(JSON.parse(match[1])) as ServerConfig
139 }
140
126 getAbout (options: OverrideCommandOptions = {}) { 141 getAbout (options: OverrideCommandOptions = {}) {
127 const path = '/api/v1/config/about' 142 const path = '/api/v1/config/about'
128 143