Terms&Conditions (#18):

* new settings for instance's terms
* new channel option for channel's terms
This commit is contained in:
John Livingston
2024-06-21 18:18:11 +02:00
parent 4b49037f68
commit 45a63eaecd
13 changed files with 93 additions and 3 deletions

View File

@ -4,6 +4,7 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { ChannelConfigurationOptions } from '../../../../shared/lib/types'
import { channelTermsMaxLength } from '../../../../shared/lib/constants'
/**
* Sanitize data so that they can safely be used/stored for channel configuration configuration.
@ -43,6 +44,16 @@ async function sanitizeChannelConfigurationOptions (
throw new Error('Invalid data.mute data type')
}
// terms not present in livechat <= 10.2.0
let terms = data.terms
if (terms !== undefined && (typeof terms !== 'string')) {
throw new Error('Invalid data.terms data type')
}
if (terms && terms.length > channelTermsMaxLength) {
throw new Error('data.terms value too long')
}
if (terms === '') { terms = undefined }
const result: ChannelConfigurationOptions = {
bot: {
enabled: _readBoolean(botData, 'enabled'),
@ -59,6 +70,9 @@ async function sanitizeChannelConfigurationOptions (
anonymous: _readBoolean(mute, 'anonymous')
}
}
if (terms !== undefined) {
result.terms = terms
}
return result
}

View File

@ -52,7 +52,8 @@ function getDefaultChannelConfigurationOptions (_options: RegisterServerOptions)
},
mute: {
anonymous: false
}
},
terms: undefined
}
}