Inject plugin CSS in embed too
This commit is contained in:
parent
5505981154
commit
cf649c2ed9
|
@ -12,7 +12,6 @@ import { asyncMiddleware, embedCSP } from '../middlewares'
|
||||||
const clientsRouter = express.Router()
|
const clientsRouter = express.Router()
|
||||||
|
|
||||||
const distPath = join(root(), 'client', 'dist')
|
const distPath = join(root(), 'client', 'dist')
|
||||||
const embedPath = join(distPath, 'standalone', 'videos', 'embed.html')
|
|
||||||
const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
|
const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
|
||||||
|
|
||||||
// Special route that add OpenGraph and oEmbed tags
|
// Special route that add OpenGraph and oEmbed tags
|
||||||
|
@ -27,11 +26,16 @@ const embedMiddlewares = [
|
||||||
? embedCSP
|
? embedCSP
|
||||||
: (req: express.Request, res: express.Response, next: express.NextFunction) => next(),
|
: (req: express.Request, res: express.Response, next: express.NextFunction) => next(),
|
||||||
|
|
||||||
(req: express.Request, res: express.Response) => {
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
res.removeHeader('X-Frame-Options')
|
res.removeHeader('X-Frame-Options')
|
||||||
|
|
||||||
// Don't cache HTML file since it's an index to the immutable JS/CSS files
|
// Don't cache HTML file since it's an index to the immutable JS/CSS files
|
||||||
res.sendFile(embedPath, { maxAge: 0 })
|
res.setHeader('Cache-Control', 'public, max-age=0')
|
||||||
}
|
|
||||||
|
next()
|
||||||
|
},
|
||||||
|
|
||||||
|
asyncMiddleware(generateEmbedHtmlPage)
|
||||||
]
|
]
|
||||||
|
|
||||||
clientsRouter.use('/videos/embed', ...embedMiddlewares)
|
clientsRouter.use('/videos/embed', ...embedMiddlewares)
|
||||||
|
@ -125,6 +129,12 @@ async function serveIndexHTML (req: express.Request, res: express.Response) {
|
||||||
return res.status(404).end()
|
return res.status(404).end()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function generateEmbedHtmlPage (req: express.Request, res: express.Response) {
|
||||||
|
const html = await ClientHtml.getEmbedHTML()
|
||||||
|
|
||||||
|
return sendHTML(html, res)
|
||||||
|
}
|
||||||
|
|
||||||
async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
|
async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
|
||||||
const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)
|
const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,23 @@ export class ClientHtml {
|
||||||
return this.getAccountOrChannelHTMLPage(() => VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost), req, res)
|
return this.getAccountOrChannelHTMLPage(() => VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost), req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getEmbedHTML () {
|
||||||
|
const path = ClientHtml.getEmbedPath()
|
||||||
|
console.log('coucu')
|
||||||
|
console.log(path)
|
||||||
|
|
||||||
|
if (ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
|
||||||
|
|
||||||
|
const buffer = await readFile(path)
|
||||||
|
|
||||||
|
let html = buffer.toString()
|
||||||
|
html = await ClientHtml.addAsyncPluginCSS(html)
|
||||||
|
|
||||||
|
ClientHtml.htmlCache[path] = html
|
||||||
|
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
private static async getAccountOrChannelHTMLPage (
|
private static async getAccountOrChannelHTMLPage (
|
||||||
loader: () => Bluebird<MAccountActor | MChannelActor>,
|
loader: () => Bluebird<MAccountActor | MChannelActor>,
|
||||||
req: express.Request,
|
req: express.Request,
|
||||||
|
@ -252,6 +269,10 @@ export class ClientHtml {
|
||||||
return join(__dirname, '../../../client/dist/' + buildFileLocale(lang) + '/index.html')
|
return join(__dirname, '../../../client/dist/' + buildFileLocale(lang) + '/index.html')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static getEmbedPath () {
|
||||||
|
return join(__dirname, '../../../client/dist/standalone/videos/embed.html')
|
||||||
|
}
|
||||||
|
|
||||||
private static addHtmlLang (htmlStringPage: string, paramLang: string) {
|
private static addHtmlLang (htmlStringPage: string, paramLang: string) {
|
||||||
return htmlStringPage.replace('<html>', `<html lang="${paramLang}">`)
|
return htmlStringPage.replace('<html>', `<html lang="${paramLang}">`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ import {
|
||||||
updatePluginPackageJSON,
|
updatePluginPackageJSON,
|
||||||
updatePluginSettings,
|
updatePluginSettings,
|
||||||
wait,
|
wait,
|
||||||
waitUntilLog
|
waitUntilLog,
|
||||||
|
makeHTMLRequest
|
||||||
} from '../../../../shared/extra-utils'
|
} from '../../../../shared/extra-utils'
|
||||||
import { PluginType } from '../../../../shared/models/plugins/plugin.type'
|
import { PluginType } from '../../../../shared/models/plugins/plugin.type'
|
||||||
import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
|
import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
|
||||||
|
@ -119,9 +120,15 @@ describe('Test plugins', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have an empty global css', async function () {
|
it('Should have an empty global css', async function () {
|
||||||
|
{
|
||||||
const res = await getPluginsCSS(server.url)
|
const res = await getPluginsCSS(server.url)
|
||||||
|
|
||||||
expect(res.text).to.be.empty
|
expect(res.text).to.be.empty
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
|
||||||
|
const res = await makeHTMLRequest(server.url, path)
|
||||||
|
expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should install a plugin and a theme', async function () {
|
it('Should install a plugin and a theme', async function () {
|
||||||
|
@ -141,9 +148,15 @@ describe('Test plugins', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the correct global css', async function () {
|
it('Should have the correct global css', async function () {
|
||||||
|
{
|
||||||
const res = await getPluginsCSS(server.url)
|
const res = await getPluginsCSS(server.url)
|
||||||
|
|
||||||
expect(res.text).to.contain('background-color: red')
|
expect(res.text).to.contain('background-color: red')
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
|
||||||
|
const res = await makeHTMLRequest(server.url, path)
|
||||||
|
expect(res.text).to.include('link rel="stylesheet" href="/plugins/global.css')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the plugin loaded in the configuration', async function () {
|
it('Should have the plugin loaded in the configuration', async function () {
|
||||||
|
@ -388,9 +401,15 @@ describe('Test plugins', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have an empty global css', async function () {
|
it('Should have an empty global css', async function () {
|
||||||
|
{
|
||||||
const res = await getPluginsCSS(server.url)
|
const res = await getPluginsCSS(server.url)
|
||||||
|
|
||||||
expect(res.text).to.be.empty
|
expect(res.text).to.be.empty
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
|
||||||
|
const res = await makeHTMLRequest(server.url, path)
|
||||||
|
expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list uninstalled plugins', async function () {
|
it('Should list uninstalled plugins', async function () {
|
||||||
|
|
Loading…
Reference in New Issue