mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Ability for admins to set default upload values
This commit is contained in:
@@ -216,10 +216,10 @@ async function buildVideo (channelId: number, body: VideoImportCreate, importDat
|
||||
name: body.name || importData.name || 'Unknown name',
|
||||
remote: false,
|
||||
category: body.category || importData.category,
|
||||
licence: body.licence || importData.licence,
|
||||
licence: body.licence ?? importData.licence ?? CONFIG.DEFAULTS.PUBLISH.LICENCE,
|
||||
language: body.language || importData.language,
|
||||
commentsEnabled: body.commentsEnabled !== false, // If the value is not "false", the default is "true"
|
||||
downloadEnabled: body.downloadEnabled !== false,
|
||||
commentsEnabled: body.commentsEnabled ?? CONFIG.DEFAULTS.PUBLISH.COMMENTS_ENABLED,
|
||||
downloadEnabled: body.downloadEnabled ?? CONFIG.DEFAULTS.PUBLISH.DOWNLOAD_ENABLED,
|
||||
waitTranscoding: body.waitTranscoding || false,
|
||||
state: VideoState.TO_IMPORT,
|
||||
nsfw: body.nsfw || importData.nsfw || false,
|
||||
|
||||
@@ -34,6 +34,7 @@ function checkMissedConfig () {
|
||||
'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'auto_blacklist.videos.of_users.enabled',
|
||||
'trending.videos.interval_days',
|
||||
'client.videos.miniature.prefer_author_display_name', 'client.menu.login.redirect_on_single_external_auth',
|
||||
'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',
|
||||
|
||||
@@ -4,7 +4,7 @@ import { dirname, join } from 'path'
|
||||
import { decacheModule } from '@server/helpers/decache'
|
||||
import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type'
|
||||
import { BroadcastMessageLevel } from '@shared/models/server'
|
||||
import { VideosRedundancyStrategy } from '../../shared/models'
|
||||
import { VideoPrivacy, VideosRedundancyStrategy } from '../../shared/models'
|
||||
import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
|
||||
import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils'
|
||||
|
||||
@@ -71,6 +71,15 @@ const CONFIG = {
|
||||
}
|
||||
},
|
||||
|
||||
DEFAULTS: {
|
||||
PUBLISH: {
|
||||
DOWNLOAD_ENABLED: config.get<boolean>('defaults.publish.download_enabled'),
|
||||
COMMENTS_ENABLED: config.get<boolean>('defaults.publish.comments_enabled'),
|
||||
PRIVACY: config.get<VideoPrivacy>('defaults.publish.privacy'),
|
||||
LICENCE: config.get<number>('defaults.publish.licence')
|
||||
}
|
||||
},
|
||||
|
||||
STORAGE: {
|
||||
TMP_DIR: buildPath(config.get<string>('storage.tmp')),
|
||||
BIN_DIR: buildPath(config.get<string>('storage.bin')),
|
||||
|
||||
@@ -55,6 +55,15 @@ class ServerConfigManager {
|
||||
}
|
||||
},
|
||||
|
||||
defaults: {
|
||||
publish: {
|
||||
downloadEnabled: CONFIG.DEFAULTS.PUBLISH.DOWNLOAD_ENABLED,
|
||||
commentsEnabled: CONFIG.DEFAULTS.PUBLISH.COMMENTS_ENABLED,
|
||||
privacy: CONFIG.DEFAULTS.PUBLISH.PRIVACY,
|
||||
licence: CONFIG.DEFAULTS.PUBLISH.LICENCE
|
||||
}
|
||||
},
|
||||
|
||||
webadmin: {
|
||||
configuration: {
|
||||
edition: {
|
||||
|
||||
@@ -9,16 +9,17 @@ import { MThumbnail, MUserId, MVideoFile, MVideoTag, MVideoThumbnail, MVideoUUID
|
||||
import { ThumbnailType, VideoCreate, VideoPrivacy, VideoTranscodingPayload } from '@shared/models'
|
||||
import { CreateJobOptions, JobQueue } from './job-queue/job-queue'
|
||||
import { updateVideoMiniatureFromExisting } from './thumbnail'
|
||||
import { CONFIG } from '@server/initializers/config'
|
||||
|
||||
function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> {
|
||||
return {
|
||||
name: videoInfo.name,
|
||||
remote: false,
|
||||
category: videoInfo.category,
|
||||
licence: videoInfo.licence,
|
||||
licence: videoInfo.licence ?? CONFIG.DEFAULTS.PUBLISH.LICENCE,
|
||||
language: videoInfo.language,
|
||||
commentsEnabled: videoInfo.commentsEnabled !== false, // If the value is not "false", the default is "true"
|
||||
downloadEnabled: videoInfo.downloadEnabled !== false,
|
||||
commentsEnabled: videoInfo.commentsEnabled ?? CONFIG.DEFAULTS.PUBLISH.COMMENTS_ENABLED,
|
||||
downloadEnabled: videoInfo.downloadEnabled ?? CONFIG.DEFAULTS.PUBLISH.DOWNLOAD_ENABLED,
|
||||
waitTranscoding: videoInfo.waitTranscoding || false,
|
||||
nsfw: videoInfo.nsfw || false,
|
||||
description: videoInfo.description,
|
||||
|
||||
116
server/tests/api/server/config-defaults.ts
Normal file
116
server/tests/api/server/config-defaults.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import 'mocha'
|
||||
import * as chai from 'chai'
|
||||
import { cleanupTests, createSingleServer, FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils'
|
||||
import { VideoDetails, VideoPrivacy } from '@shared/models'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Test config defaults', function () {
|
||||
let server: PeerTubeServer
|
||||
let channelId: number
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
const overrideConfig = {
|
||||
defaults: {
|
||||
publish: {
|
||||
comments_enabled: false,
|
||||
download_enabled: false,
|
||||
privacy: VideoPrivacy.INTERNAL,
|
||||
licence: 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server = await createSingleServer(1, overrideConfig)
|
||||
await setAccessTokensToServers([ server ])
|
||||
await setDefaultVideoChannel([ server ])
|
||||
|
||||
channelId = server.store.channel.id
|
||||
})
|
||||
|
||||
describe('Default publish values', function () {
|
||||
const attributes = {
|
||||
name: 'video',
|
||||
downloadEnabled: undefined,
|
||||
commentsEnabled: undefined,
|
||||
licence: undefined,
|
||||
privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
|
||||
}
|
||||
|
||||
function checkVideo (video: VideoDetails) {
|
||||
expect(video.downloadEnabled).to.be.false
|
||||
expect(video.commentsEnabled).to.be.false
|
||||
expect(video.licence.id).to.equal(4)
|
||||
}
|
||||
|
||||
before(async function () {
|
||||
await server.config.disableTranscoding()
|
||||
await server.config.enableImports()
|
||||
await server.config.enableLive({ allowReplay: false, transcoding: false })
|
||||
})
|
||||
|
||||
it('Should have the correct server configuration', async function () {
|
||||
const config = await server.config.getConfig()
|
||||
|
||||
expect(config.defaults.publish.commentsEnabled).to.be.false
|
||||
expect(config.defaults.publish.downloadEnabled).to.be.false
|
||||
expect(config.defaults.publish.licence).to.equal(4)
|
||||
expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL)
|
||||
})
|
||||
|
||||
it('Should respect default values when uploading a video', async function () {
|
||||
for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
|
||||
const { id } = await server.videos.upload({ attributes, mode })
|
||||
|
||||
const video = await server.videos.get({ id })
|
||||
checkVideo(video)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should respect default values when importing a video using URL', async function () {
|
||||
const { video: { id } } = await server.imports.importVideo({
|
||||
attributes: {
|
||||
...attributes,
|
||||
channelId,
|
||||
targetUrl: FIXTURE_URLS.goodVideo
|
||||
}
|
||||
})
|
||||
|
||||
const video = await server.videos.get({ id })
|
||||
checkVideo(video)
|
||||
})
|
||||
|
||||
it('Should respect default values when importing a video using magnet URI', async function () {
|
||||
const { video: { id } } = await server.imports.importVideo({
|
||||
attributes: {
|
||||
...attributes,
|
||||
channelId,
|
||||
magnetUri: FIXTURE_URLS.magnet
|
||||
}
|
||||
})
|
||||
|
||||
const video = await server.videos.get({ id })
|
||||
checkVideo(video)
|
||||
})
|
||||
|
||||
it('Should respect default values when creating a live', async function () {
|
||||
const { id } = await server.live.create({
|
||||
fields: {
|
||||
...attributes,
|
||||
channelId
|
||||
}
|
||||
})
|
||||
|
||||
const video = await server.videos.get({ id })
|
||||
checkVideo(video)
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests([ server ])
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,6 @@
|
||||
import './auto-follows'
|
||||
import './bulk'
|
||||
import './config-defaults'
|
||||
import './config'
|
||||
import './contact-form'
|
||||
import './email'
|
||||
|
||||
Reference in New Issue
Block a user