const clientsRouter = express.Router()
const distPath = join(root(), 'client', 'dist')
-const embedPath = join(distPath, 'standalone', 'videos', 'embed.html')
const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
// Special route that add OpenGraph and oEmbed tags
? embedCSP
: (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')
+
// 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)
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) {
const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)
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 (
loader: () => Bluebird<MAccountActor | MChannelActor>,
req: express.Request,
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) {
return htmlStringPage.replace('<html>', `<html lang="${paramLang}">`)
}
updatePluginPackageJSON,
updatePluginSettings,
wait,
- waitUntilLog
+ waitUntilLog,
+ makeHTMLRequest
} from '../../../../shared/extra-utils'
import { PluginType } from '../../../../shared/models/plugins/plugin.type'
import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
})
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 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 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 () {