From 10e78bb778e6c0cd13c2cbcc901e9e3347d2c229 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Mar 2024 10:49:08 +0100 Subject: [PATCH] Remove twitter whitelisted option It doesn't seem to be required --- .../edit-basic-configuration.component.html | 37 +--- .../edit-custom-config.component.ts | 3 +- config/default.yaml | 11 +- config/production.yaml.example | 11 +- .../models/src/server/custom-config.model.ts | 1 - .../src/server/config-command.ts | 3 +- packages/tests/src/api/check-params/config.ts | 3 +- packages/tests/src/api/server/config.ts | 5 +- packages/tests/src/client/og-twitter-tags.ts | 187 ++++++------------ server/core/controllers/api/config.ts | 3 +- server/core/helpers/audit-logger.ts | 1 - .../core/initializers/checker-before-init.ts | 2 +- server/core/initializers/config.ts | 3 +- server/core/lib/html/shared/playlist-html.ts | 9 +- server/core/lib/html/shared/video-html.ts | 15 +- server/core/middlewares/validators/config.ts | 1 - support/doc/api/openapi.yaml | 2 - 17 files changed, 92 insertions(+), 205 deletions(-) diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html index 1f3ba283f..d63f13c33 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html +++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html @@ -671,10 +671,10 @@
-

TWITTER

+

TWITTER/X

+
- Provide the Twitter account representing your instance to improve link previews. - If you don't have a Twitter account, just leave the default value. + Extra configuration required by Twitter/X. All other social media (Facebook, Mastodon, etc.) are supported out of the box.
@@ -684,7 +684,13 @@
- + + +
+

Indicates the Twitter/X account for the website or platform where the content was published.

+ +

This is just an extra information injected in PeerTube HTML that is required by Twitter/X. If you don't have a Twitter/X account, just leave the default value.

+
{{ formErrors.services.twitter.username }}
-
- - - Instance allowed by Twitter/X - - - - -

- If your instance is explicitly allowed by Twitter/X, a video player will be embedded in the Twitter feed on PeerTube video share.
- If the instance is not, we use an image link card that will redirect to your PeerTube instance. -

- -

- Check this checkbox, save the configuration and test with a video URL of your instance (https://example.com/w/blabla) on - https://cards-dev.twitter.com/validator - to see if you instance is allowed. -

-
-
-
-
- diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 452c259c0..08fb9e29e 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -131,8 +131,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { }, services: { twitter: { - username: SERVICES_TWITTER_USERNAME_VALIDATOR, - whitelisted: null + username: SERVICES_TWITTER_USERNAME_VALIDATOR } }, client: { diff --git a/config/default.yaml b/config/default.yaml index 7787dc1d6..4bd0c9a7a 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -841,13 +841,12 @@ instance: Expires: 2025-12-31T11:00:00.000Z' services: - # Cards configuration to format video in Twitter + # Cards configuration to format video in Twitter/X + # All other social media (Facebook, Mastodon, etc.) are supported out of the box twitter: - username: '@Chocobozzz' # Indicates the Twitter account for the website or platform on which the content was published - # If true, a video player will be embedded in the Twitter feed on PeerTube video share - # If false, we use an image link card that will redirect on your PeerTube instance - # Change it to `true`, and then test on https://cards-dev.twitter.com/validator to see if you are whitelisted - whitelisted: false + # Indicates the Twitter account for the website or platform where the content was published + # This is just an information injected in HTML that is required by Twitter/X + username: '@Chocobozzz' followers: instance: diff --git a/config/production.yaml.example b/config/production.yaml.example index 05577c202..b645c5fda 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example @@ -851,13 +851,12 @@ instance: Expires: 2025-12-31T11:00:00.000Z' services: - # Cards configuration to format video in Twitter + # Cards configuration to format video in Twitter/X + # All other social media (Facebook, Mastodon, etc.) are supported out of the box twitter: - username: '@Chocobozzz' # Indicates the Twitter account for the website or platform on which the content was published - # If true, a video player will be embedded in the Twitter feed on PeerTube video share - # If false, we use an image link card that will redirect on your PeerTube instance - # Change it to `true`, and then test on https://cards-dev.twitter.com/validator to see if you are whitelisted - whitelisted: false + # Indicates the Twitter/X account for the website or platform where the content was published + # This is just an information injected in HTML that is required by Twitter/X + username: '@Chocobozzz' followers: instance: diff --git a/packages/models/src/server/custom-config.model.ts b/packages/models/src/server/custom-config.model.ts index 3f52fb31a..9b77147b9 100644 --- a/packages/models/src/server/custom-config.model.ts +++ b/packages/models/src/server/custom-config.model.ts @@ -48,7 +48,6 @@ export interface CustomConfig { services: { twitter: { username: string - whitelisted: boolean } } diff --git a/packages/server-commands/src/server/config-command.ts b/packages/server-commands/src/server/config-command.ts index cd3fc6f44..64be64bf5 100644 --- a/packages/server-commands/src/server/config-command.ts +++ b/packages/server-commands/src/server/config-command.ts @@ -503,8 +503,7 @@ export class ConfigCommand extends AbstractCommand { }, services: { twitter: { - username: '@MySuperUsername', - whitelisted: true + username: '@MySuperUsername' } }, client: { diff --git a/packages/tests/src/api/check-params/config.ts b/packages/tests/src/api/check-params/config.ts index 4e093ed26..3eef13e6f 100644 --- a/packages/tests/src/api/check-params/config.ts +++ b/packages/tests/src/api/check-params/config.ts @@ -52,8 +52,7 @@ describe('Test config API validators', function () { }, services: { twitter: { - username: '@MySuperUsername', - whitelisted: true + username: '@MySuperUsername' } }, client: { diff --git a/packages/tests/src/api/server/config.ts b/packages/tests/src/api/server/config.ts index 85d40e232..e503541a8 100644 --- a/packages/tests/src/api/server/config.ts +++ b/packages/tests/src/api/server/config.ts @@ -42,7 +42,6 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) { expect(data.instance.customizations.javascript).to.be.empty expect(data.services.twitter.username).to.equal('@Chocobozzz') - expect(data.services.twitter.whitelisted).to.be.false expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.false expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.false @@ -161,7 +160,6 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.instance.customizations.css).to.equal('body { background-color: red; }') expect(data.services.twitter.username).to.equal('@Kuja') - expect(data.services.twitter.whitelisted).to.be.true expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.true expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.true @@ -291,8 +289,7 @@ const newCustomConfig: CustomConfig = { }, services: { twitter: { - username: '@Kuja', - whitelisted: true + username: '@Kuja' } }, client: { diff --git a/packages/tests/src/client/og-twitter-tags.ts b/packages/tests/src/client/og-twitter-tags.ts index d5480087d..0244dce0b 100644 --- a/packages/tests/src/client/og-twitter-tags.ts +++ b/packages/tests/src/client/og-twitter-tags.ts @@ -120,148 +120,73 @@ describe('Test Open Graph and Twitter cards HTML tags', function () { describe('Twitter card', async function () { - describe('Not whitelisted', function () { - - async function accountPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') - expect(text).to.contain(``) - expect(text).to.contain(``) + before(async function () { + const config = await servers[0].config.getCustomConfig() + config.services.twitter = { + username: '@Kuja' } - async function channelPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') - expect(text).to.contain(``) - expect(text).to.contain(``) - } - - async function watchVideoPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') - expect(text).to.contain(``) - expect(text).to.contain(``) - } - - async function watchPlaylistPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') - expect(text).to.contain(``) - expect(text).to.contain(``) - } - - it('Should have valid twitter card on the watch video page', async function () { - for (const path of getWatchVideoBasePaths()) { - for (const id of videoIds) { - await watchVideoPageTest(path + id) - } - } - }) - - it('Should have valid twitter card on the watch playlist page', async function () { - for (const path of getWatchPlaylistBasePaths()) { - for (const id of playlistIds) { - await watchPlaylistPageTest(path + id) - } - } - }) - - it('Should have valid twitter card on the account page', async function () { - await accountPageTest('/accounts/' + account.name) - await accountPageTest('/a/' + account.name) - await accountPageTest('/@' + account.name) - }) - - it('Should have valid twitter card on the channel page', async function () { - await channelPageTest('/video-channels/' + servers[0].store.channel.name) - await channelPageTest('/c/' + servers[0].store.channel.name) - await channelPageTest('/@' + servers[0].store.channel.name) - }) + await servers[0].config.updateCustomConfig({ newCustomConfig: config }) }) - describe('Whitelisted', function () { + async function accountPageTest (path: string) { + const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) + const text = res.text - before(async function () { - const config = await servers[0].config.getCustomConfig() - config.services.twitter = { - username: '@Kuja', - whitelisted: true + expect(text).to.contain('') + expect(text).to.contain('') + } + + async function channelPageTest (path: string) { + const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) + const text = res.text + + expect(text).to.contain('') + expect(text).to.contain('') + } + + async function watchVideoPageTest (path: string) { + const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) + const text = res.text + + expect(text).to.contain('') + expect(text).to.contain('') + } + + async function watchPlaylistPageTest (path: string) { + const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) + const text = res.text + + expect(text).to.contain('') + expect(text).to.contain('') + } + + it('Should have valid twitter card on the watch video page', async function () { + for (const path of getWatchVideoBasePaths()) { + for (const id of videoIds) { + await watchVideoPageTest(path + id) } - - await servers[0].config.updateCustomConfig({ newCustomConfig: config }) - }) - - async function accountPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') } + }) - async function channelPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') - } - - async function watchVideoPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') - } - - async function watchPlaylistPageTest (path: string) { - const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) - const text = res.text - - expect(text).to.contain('') - expect(text).to.contain('') - } - - it('Should have valid twitter card on the watch video page', async function () { - for (const path of getWatchVideoBasePaths()) { - for (const id of videoIds) { - await watchVideoPageTest(path + id) - } + it('Should have valid twitter card on the watch playlist page', async function () { + for (const path of getWatchPlaylistBasePaths()) { + for (const id of playlistIds) { + await watchPlaylistPageTest(path + id) } - }) + } + }) - it('Should have valid twitter card on the watch playlist page', async function () { - for (const path of getWatchPlaylistBasePaths()) { - for (const id of playlistIds) { - await watchPlaylistPageTest(path + id) - } - } - }) + it('Should have valid twitter card on the account page', async function () { + await accountPageTest('/accounts/' + account.name) + await accountPageTest('/a/' + account.name) + await accountPageTest('/@' + account.name) + }) - it('Should have valid twitter card on the account page', async function () { - await accountPageTest('/accounts/' + account.name) - await accountPageTest('/a/' + account.name) - await accountPageTest('/@' + account.name) - }) - - it('Should have valid twitter card on the channel page', async function () { - await channelPageTest('/video-channels/' + servers[0].store.channel.name) - await channelPageTest('/c/' + servers[0].store.channel.name) - await channelPageTest('/@' + servers[0].store.channel.name) - }) + it('Should have valid twitter card on the channel page', async function () { + await channelPageTest('/video-channels/' + servers[0].store.channel.name) + await channelPageTest('/c/' + servers[0].store.channel.name) + await channelPageTest('/@' + servers[0].store.channel.name) }) }) diff --git a/server/core/controllers/api/config.ts b/server/core/controllers/api/config.ts index a04524714..bbaa9f69e 100644 --- a/server/core/controllers/api/config.ts +++ b/server/core/controllers/api/config.ts @@ -263,8 +263,7 @@ function customConfig (): CustomConfig { }, services: { twitter: { - username: CONFIG.SERVICES.TWITTER.USERNAME, - whitelisted: CONFIG.SERVICES.TWITTER.WHITELISTED + username: CONFIG.SERVICES.TWITTER.USERNAME } }, client: { diff --git a/server/core/helpers/audit-logger.ts b/server/core/helpers/audit-logger.ts index f5fbb9d84..5958acbf5 100644 --- a/server/core/helpers/audit-logger.ts +++ b/server/core/helpers/audit-logger.ts @@ -243,7 +243,6 @@ const customConfigKeysToKeep = new Set([ 'instance-customizations-javascript', 'instance-customizations-css', 'services-twitter-username', - 'services-twitter-whitelisted', 'cache-previews-size', 'cache-captions-size', 'signup-enabled', diff --git a/server/core/initializers/checker-before-init.ts b/server/core/initializers/checker-before-init.ts index d7415958f..a75a4ecab 100644 --- a/server/core/initializers/checker-before-init.ts +++ b/server/core/initializers/checker-before-init.ts @@ -51,7 +51,7 @@ function checkMissedConfig () { 'defaults.publish.download_enabled', 'defaults.publish.comments_enabled', 'defaults.publish.privacy', 'defaults.publish.licence', 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', - 'services.twitter.username', 'services.twitter.whitelisted', + 'services.twitter.username', 'followers.instance.enabled', 'followers.instance.manual_approval', 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces', 'history.videos.max_age', 'views.videos.remote.max_age', 'views.videos.local_buffer_update_interval', 'views.videos.ip_view_expiration', diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts index 4da75126d..51845b4a0 100644 --- a/server/core/initializers/config.ts +++ b/server/core/initializers/config.ts @@ -596,8 +596,7 @@ const CONFIG = { }, SERVICES: { TWITTER: { - get USERNAME () { return config.get('services.twitter.username') }, - get WHITELISTED () { return config.get('services.twitter.whitelisted') } + get USERNAME () { return config.get('services.twitter.username') } } }, FOLLOWERS: { diff --git a/server/core/lib/html/shared/playlist-html.ts b/server/core/lib/html/shared/playlist-html.ts index 17d9e180f..e5df277ea 100644 --- a/server/core/lib/html/shared/playlist-html.ts +++ b/server/core/lib/html/shared/playlist-html.ts @@ -87,12 +87,9 @@ export class PlaylistHtml { const list = { numberOfItems: playlist.get('videosLength') as number } const schemaType = 'ItemList' - let twitterCard: 'player' | 'summary' - if (addTwitterCard) { - twitterCard = CONFIG.SERVICES.TWITTER.WHITELISTED - ? 'player' - : 'summary' - } + const twitterCard = addTwitterCard + ? 'player' + : undefined const ogType = addOG ? 'video' as 'video' diff --git a/server/core/lib/html/shared/video-html.ts b/server/core/lib/html/shared/video-html.ts index 1649228e2..ccffc683d 100644 --- a/server/core/lib/html/shared/video-html.ts +++ b/server/core/lib/html/shared/video-html.ts @@ -1,6 +1,7 @@ import { escapeHTML } from '@peertube/peertube-core-utils' import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models' import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js' +import { Memoize } from '@server/helpers/memoize.js' import express from 'express' import validator from 'validator' import { CONFIG } from '../../../initializers/config.js' @@ -9,10 +10,9 @@ import { VideoModel } from '../../../models/video/video.js' import { MVideo, MVideoThumbnailBlacklist } from '../../../types/models/index.js' import { getActivityStreamDuration } from '../../activitypub/activity.js' import { isVideoInPrivateDirectory } from '../../video-privacy.js' -import { Memoize } from '@server/helpers/memoize.js' -import { TagsHtml } from './tags-html.js' -import { PageHtml } from './page-html.js' import { CommonEmbedHtml } from './common-embed-html.js' +import { PageHtml } from './page-html.js' +import { TagsHtml } from './tags-html.js' export class VideoHtml { @@ -99,12 +99,9 @@ export class VideoHtml { ? 'video' as 'video' : undefined - let twitterCard: 'player' | 'summary_large_image' - if (addTwitterCard) { - twitterCard = CONFIG.SERVICES.TWITTER.WHITELISTED - ? 'player' - : 'summary_large_image' - } + const twitterCard = addTwitterCard + ? 'player' + : undefined const schemaType = 'VideoObject' diff --git a/server/core/middlewares/validators/config.ts b/server/core/middlewares/validators/config.ts index b9477b75e..f3bab5851 100644 --- a/server/core/middlewares/validators/config.ts +++ b/server/core/middlewares/validators/config.ts @@ -19,7 +19,6 @@ const customConfigUpdateValidator = [ body('instance.customizations.javascript').exists(), body('services.twitter.username').exists(), - body('services.twitter.whitelisted').isBoolean(), body('cache.previews.size').isInt(), body('cache.captions.size').isInt(), diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml index 983b65c13..e6884fee9 100644 --- a/support/doc/api/openapi.yaml +++ b/support/doc/api/openapi.yaml @@ -8743,8 +8743,6 @@ components: properties: username: type: string - whitelisted: - type: boolean cache: type: object properties: