mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
feat(config): add admin options to customize default "Browse videos" behaviour (#7193)
* feat(customBrowseVideosDefaultSort): update server config * feat(customBrowseVideosDefaultSort): update client admin-config-general component * feat(customBrowseVideosDefaultSort): add new consistency check to server checker-after-init * feat(customBrowseVideosDefaultSort): update config .yaml with more details about available options * feat(customBrowseVideosDefaultSort): refactor consistency check in server checker-after-init * feat(customBrowseVideosDefaultSort): client, add new select-videos-sort shared component * feat(customBrowseVideosDefaultSort): client, refactor admin-config-general component to use new select-videos-sort shared component * feat(customBrowseVideosDefaultSort): client, fix my-select-videos-sort width in admin-config-general * feat(customBrowseVideosDefaultSort): client, update video-filters-header scss * feat(customBrowseVideosDefaultSort): client, update videos-list-all component * feat(config): refactor checkBrowseVideosConfig logic into separate custom validator * feat(config): refactor isBrowseVideosDefaultSortValid to use template literals * feat(config): refactor isBrowseVideosDefaultSortValid * feat(config): add check for invalid browse videos config to customConfigUpdateValidator * feat(config): group browse-videos tests in describe block * feat(config): refactor to use client.browse_videos section, instead of browse.videos section * feat(config): add browse_videos default_scope config key (config and server changes) * feat(config): add browse_videos default_scope config key (client changes) * Reorder browse videos before videos * Fix i18n message --------- Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
parent
9b7edd1c59
commit
e74bf8ae2a
23 changed files with 436 additions and 54 deletions
35
server/core/helpers/custom-validators/browse-videos.ts
Normal file
35
server/core/helpers/custom-validators/browse-videos.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { t } from '../i18n.js'
|
||||
|
||||
export function getBrowseVideosDefaultSortError (value: string, enabledTrendingAlgorithms: string[], language: string) {
|
||||
const availableOptions = [ '-publishedAt', '-originallyPublishedAt', 'name', '-trending', '-hot', '-likes', '-views' ]
|
||||
|
||||
if (availableOptions.includes(value) === false) {
|
||||
return t('Browse videos default sort should be \'' + availableOptions.join('\' or \'') + '\', instead of \'' + value + '\'', language)
|
||||
}
|
||||
|
||||
const trendingSortAlgorithmMap = new Map<string, string>([
|
||||
[ '-trending', 'most-viewed' ],
|
||||
[ '-hot', 'hot' ],
|
||||
[ '-likes', 'most-liked' ]
|
||||
])
|
||||
const currentTrendingSortAlgorithm = trendingSortAlgorithmMap.get(value)
|
||||
|
||||
if (currentTrendingSortAlgorithm && enabledTrendingAlgorithms.includes(currentTrendingSortAlgorithm) === false) {
|
||||
return t(
|
||||
`Trending videos algorithm '${currentTrendingSortAlgorithm}' should be enabled if browse videos default sort is '${value}'`,
|
||||
language
|
||||
)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function getBrowseVideosDefaultScopeError (value: string, language: string) {
|
||||
const availableOptions = [ 'local', 'federated' ]
|
||||
|
||||
if (availableOptions.includes(value) === false) {
|
||||
return t('Browse videos default scope should be \'' + availableOptions.join('\' or \'') + '\', instead of \'' + value + '\'', language)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue