aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/client.ts11
-rw-r--r--server/lib/client-html.ts17
-rw-r--r--server/tests/client.ts154
3 files changed, 142 insertions, 40 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index 022a17ff4..35e5af9d1 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -21,8 +21,9 @@ const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
21// Do not use a template engine for a so little thing 21// Do not use a template engine for a so little thing
22clientsRouter.use('/videos/watch/playlist/:id', asyncMiddleware(generateWatchPlaylistHtmlPage)) 22clientsRouter.use('/videos/watch/playlist/:id', asyncMiddleware(generateWatchPlaylistHtmlPage))
23clientsRouter.use('/videos/watch/:id', asyncMiddleware(generateWatchHtmlPage)) 23clientsRouter.use('/videos/watch/:id', asyncMiddleware(generateWatchHtmlPage))
24clientsRouter.use('/accounts/:nameWithHost', asyncMiddleware(generateAccountHtmlPage)) 24clientsRouter.use([ '/accounts/:nameWithHost', '/a/:nameWithHost' ], asyncMiddleware(generateAccountHtmlPage))
25clientsRouter.use('/video-channels/:nameWithHost', asyncMiddleware(generateVideoChannelHtmlPage)) 25clientsRouter.use([ '/video-channels/:nameWithHost', '/c/:nameWithHost' ], asyncMiddleware(generateVideoChannelHtmlPage))
26clientsRouter.use('/@:nameWithHost', asyncMiddleware(generateActorHtmlPage))
26 27
27const embedMiddlewares = [ 28const embedMiddlewares = [
28 CONFIG.CSP.ENABLED 29 CONFIG.CSP.ENABLED
@@ -155,6 +156,12 @@ async function generateVideoChannelHtmlPage (req: express.Request, res: express.
155 return sendHTML(html, res) 156 return sendHTML(html, res)
156} 157}
157 158
159async function generateActorHtmlPage (req: express.Request, res: express.Response) {
160 const html = await ClientHtml.getActorHTMLPage(req.params.nameWithHost, req, res)
161
162 return sendHTML(html, res)
163}
164
158async function generateManifest (req: express.Request, res: express.Response) { 165async function generateManifest (req: express.Request, res: express.Response) {
159 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest') 166 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest')
160 const manifestJson = await readFile(manifestPhysicalPath, 'utf8') 167 const manifestJson = await readFile(manifestPhysicalPath, 'utf8')
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index 203bd3893..cac9edb30 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -196,11 +196,24 @@ class ClientHtml {
196 } 196 }
197 197
198 static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) { 198 static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
199 return this.getAccountOrChannelHTMLPage(() => AccountModel.loadByNameWithHost(nameWithHost), req, res) 199 const accountModelPromise = AccountModel.loadByNameWithHost(nameWithHost)
200 return this.getAccountOrChannelHTMLPage(() => accountModelPromise, req, res)
200 } 201 }
201 202
202 static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) { 203 static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
203 return this.getAccountOrChannelHTMLPage(() => VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost), req, res) 204 const videoChannelModelPromise = VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
205 return this.getAccountOrChannelHTMLPage(() => videoChannelModelPromise, req, res)
206 }
207
208 static async getActorHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
209 const accountModel = await AccountModel.loadByNameWithHost(nameWithHost)
210
211 if (accountModel) {
212 return this.getAccountOrChannelHTMLPage(() => new Promise(resolve => resolve(accountModel)), req, res)
213 } else {
214 const videoChannelModelPromise = VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
215 return this.getAccountOrChannelHTMLPage(() => videoChannelModelPromise, req, res)
216 }
204 } 217 }
205 218
206 static async getEmbedHTML () { 219 static async getEmbedHTML () {
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 3c99bcd1f..e76220631 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -140,27 +140,51 @@ describe('Test a client controllers', function () {
140 describe('Open Graph', function () { 140 describe('Open Graph', function () {
141 141
142 it('Should have valid Open Graph tags on the account page', async function () { 142 it('Should have valid Open Graph tags on the account page', async function () {
143 const res = await request(servers[0].url) 143 const accountPageTests = (res) => {
144 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
145 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
146 expect(res.text).to.contain('<meta property="og:type" content="website" />')
147 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`)
148 }
149
150 accountPageTests(await request(servers[0].url)
144 .get('/accounts/' + servers[0].user.username) 151 .get('/accounts/' + servers[0].user.username)
145 .set('Accept', 'text/html') 152 .set('Accept', 'text/html')
146 .expect(HttpStatusCode.OK_200) 153 .expect(HttpStatusCode.OK_200))
154
155 accountPageTests(await request(servers[0].url)
156 .get('/a/' + servers[0].user.username)
157 .set('Accept', 'text/html')
158 .expect(HttpStatusCode.OK_200))
147 159
148 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) 160 accountPageTests(await request(servers[0].url)
149 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`) 161 .get('/@' + servers[0].user.username)
150 expect(res.text).to.contain('<meta property="og:type" content="website" />') 162 .set('Accept', 'text/html')
151 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`) 163 .expect(HttpStatusCode.OK_200))
152 }) 164 })
153 165
154 it('Should have valid Open Graph tags on the channel page', async function () { 166 it('Should have valid Open Graph tags on the channel page', async function () {
155 const res = await request(servers[0].url) 167 const channelPageOGtests = (res) => {
168 expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`)
169 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
170 expect(res.text).to.contain('<meta property="og:type" content="website" />')
171 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
172 }
173
174 channelPageOGtests(await request(servers[0].url)
156 .get('/video-channels/' + servers[0].videoChannel.name) 175 .get('/video-channels/' + servers[0].videoChannel.name)
157 .set('Accept', 'text/html') 176 .set('Accept', 'text/html')
158 .expect(HttpStatusCode.OK_200) 177 .expect(HttpStatusCode.OK_200))
178
179 channelPageOGtests(await request(servers[0].url)
180 .get('/c/' + servers[0].videoChannel.name)
181 .set('Accept', 'text/html')
182 .expect(HttpStatusCode.OK_200))
159 183
160 expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`) 184 channelPageOGtests(await request(servers[0].url)
161 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) 185 .get('/@' + servers[0].videoChannel.name)
162 expect(res.text).to.contain('<meta property="og:type" content="website" />') 186 .set('Accept', 'text/html')
163 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`) 187 .expect(HttpStatusCode.OK_200))
164 }) 188 })
165 189
166 it('Should have valid Open Graph tags on the watch page with video id', async function () { 190 it('Should have valid Open Graph tags on the watch page with video id', async function () {
@@ -227,27 +251,51 @@ describe('Test a client controllers', function () {
227 }) 251 })
228 252
229 it('Should have valid twitter card on the account page', async function () { 253 it('Should have valid twitter card on the account page', async function () {
230 const res = await request(servers[0].url) 254 const accountPageTests = (res) => {
255 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
256 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
257 expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
258 expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
259 }
260
261 accountPageTests(await request(servers[0].url)
231 .get('/accounts/' + account.name) 262 .get('/accounts/' + account.name)
232 .set('Accept', 'text/html') 263 .set('Accept', 'text/html')
233 .expect(HttpStatusCode.OK_200) 264 .expect(HttpStatusCode.OK_200))
234 265
235 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 266 accountPageTests(await request(servers[0].url)
236 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 267 .get('/a/' + account.name)
237 expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`) 268 .set('Accept', 'text/html')
238 expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`) 269 .expect(HttpStatusCode.OK_200))
270
271 accountPageTests(await request(servers[0].url)
272 .get('/@' + account.name)
273 .set('Accept', 'text/html')
274 .expect(HttpStatusCode.OK_200))
239 }) 275 })
240 276
241 it('Should have valid twitter card on the channel page', async function () { 277 it('Should have valid twitter card on the channel page', async function () {
242 const res = await request(servers[0].url) 278 const channelPageTests = (res) => {
279 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
280 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
281 expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`)
282 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
283 }
284
285 channelPageTests(await request(servers[0].url)
243 .get('/video-channels/' + servers[0].videoChannel.name) 286 .get('/video-channels/' + servers[0].videoChannel.name)
244 .set('Accept', 'text/html') 287 .set('Accept', 'text/html')
245 .expect(HttpStatusCode.OK_200) 288 .expect(HttpStatusCode.OK_200))
246 289
247 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 290 channelPageTests(await request(servers[0].url)
248 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 291 .get('/c/' + servers[0].videoChannel.name)
249 expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`) 292 .set('Accept', 'text/html')
250 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) 293 .expect(HttpStatusCode.OK_200))
294
295 channelPageTests(await request(servers[0].url)
296 .get('/@' + servers[0].videoChannel.name)
297 .set('Accept', 'text/html')
298 .expect(HttpStatusCode.OK_200))
251 }) 299 })
252 300
253 it('Should have valid twitter card if Twitter is whitelisted', async function () { 301 it('Should have valid twitter card if Twitter is whitelisted', async function () {
@@ -275,21 +323,45 @@ describe('Test a client controllers', function () {
275 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />') 323 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
276 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 324 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
277 325
278 const resAccountRequest = await request(servers[0].url) 326 const accountTests = (res) => {
327 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
328 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
329 }
330
331 accountTests(await request(servers[0].url)
279 .get('/accounts/' + account.name) 332 .get('/accounts/' + account.name)
280 .set('Accept', 'text/html') 333 .set('Accept', 'text/html')
281 .expect(HttpStatusCode.OK_200) 334 .expect(HttpStatusCode.OK_200))
335
336 accountTests(await request(servers[0].url)
337 .get('/a/' + account.name)
338 .set('Accept', 'text/html')
339 .expect(HttpStatusCode.OK_200))
340
341 accountTests(await request(servers[0].url)
342 .get('/@' + account.name)
343 .set('Accept', 'text/html')
344 .expect(HttpStatusCode.OK_200))
282 345
283 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 346 const channelTests = (res) => {
284 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 347 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
348 expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
349 }
285 350
286 const resChannelRequest = await request(servers[0].url) 351 channelTests(await request(servers[0].url)
287 .get('/video-channels/' + servers[0].videoChannel.name) 352 .get('/video-channels/' + servers[0].videoChannel.name)
288 .set('Accept', 'text/html') 353 .set('Accept', 'text/html')
289 .expect(HttpStatusCode.OK_200) 354 .expect(HttpStatusCode.OK_200))
355
356 channelTests(await request(servers[0].url)
357 .get('/c/' + servers[0].videoChannel.name)
358 .set('Accept', 'text/html')
359 .expect(HttpStatusCode.OK_200))
290 360
291 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 361 channelTests(await request(servers[0].url)
292 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 362 .get('/@' + servers[0].videoChannel.name)
363 .set('Accept', 'text/html')
364 .expect(HttpStatusCode.OK_200))
293 }) 365 })
294 }) 366 })
295 367
@@ -335,13 +407,23 @@ describe('Test a client controllers', function () {
335 }) 407 })
336 408
337 it('Should use the original account URL for the canonical tag', async function () { 409 it('Should use the original account URL for the canonical tag', async function () {
338 const res = await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host) 410 const accountURLtest = (res) => {
339 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`) 411 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`)
412 }
413
414 accountURLtest(await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host))
415 accountURLtest(await makeHTMLRequest(servers[1].url, '/a/root@' + servers[0].host))
416 accountURLtest(await makeHTMLRequest(servers[1].url, '/@root@' + servers[0].host))
340 }) 417 })
341 418
342 it('Should use the original channel URL for the canonical tag', async function () { 419 it('Should use the original channel URL for the canonical tag', async function () {
343 const res = await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host) 420 const channelURLtests = (res) => {
344 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`) 421 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`)
422 }
423
424 channelURLtests(await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host))
425 channelURLtests(await makeHTMLRequest(servers[1].url, '/c/root_channel@' + servers[0].host))
426 channelURLtests(await makeHTMLRequest(servers[1].url, '/@root_channel@' + servers[0].host))
345 }) 427 })
346 428
347 it('Should use the original playlist URL for the canonical tag', async function () { 429 it('Should use the original playlist URL for the canonical tag', async function () {