feat: add custom username suggestions pool (#1644)

*  add custom username suggestions pool

* 🚸 add minimum of 10 suggested usernames until custom pool is used
This commit is contained in:
Jannik
2022-01-12 19:18:08 +01:00
committed by GitHub
parent 814c65eeb7
commit d3cfc40b5c
6 changed files with 71 additions and 11 deletions

View File

@@ -603,6 +603,27 @@ func SetForbiddenUsernameList(w http.ResponseWriter, r *http.Request) {
controllers.WriteSimpleResponse(w, true, "forbidden username list updated")
}
// SetSuggestedUsernameList will set the list of suggested usernames that newly registered users are assigned if it isn't inferred otherwise (i.e. through a proxy).
func SetSuggestedUsernameList(w http.ResponseWriter, r *http.Request) {
type suggestedUsernameListRequest struct {
Value []string `json:"value"`
}
decoder := json.NewDecoder(r.Body)
var request suggestedUsernameListRequest
if err := decoder.Decode(&request); err != nil {
controllers.WriteSimpleResponse(w, false, "unable to update suggested usernames with provided values")
return
}
if err := data.SetSuggestedUsernamesList(request.Value); err != nil {
controllers.WriteSimpleResponse(w, false, err.Error())
}
controllers.WriteSimpleResponse(w, true, "suggested username list updated")
}
func requirePOST(w http.ResponseWriter, r *http.Request) bool {
if r.Method != controllers.POST {
controllers.WriteSimpleResponse(w, false, r.Method+" not supported")

View File

@@ -17,6 +17,7 @@ import (
func GetServerConfig(w http.ResponseWriter, r *http.Request) {
ffmpeg := utils.ValidatedFfmpegPath(data.GetFfMpegPath())
usernameBlocklist := data.GetForbiddenUsernameList()
usernameSuggestions := data.GetSuggestedUsernamesList()
videoQualityVariants := make([]models.StreamOutputVariant, 0)
for _, variant := range data.GetStreamOutputVariants() {
@@ -64,6 +65,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
SupportedCodecs: transcoder.GetCodecs(ffmpeg),
VideoCodec: data.GetVideoCodec(),
ForbiddenUsernames: usernameBlocklist,
SuggestedUsernames: usernameSuggestions,
}
w.Header().Set("Content-Type", "application/json")
@@ -89,6 +91,7 @@ type serverConfigAdminResponse struct {
SupportedCodecs []string `json:"supportedCodecs"`
VideoCodec string `json:"videoCodec"`
ForbiddenUsernames []string `json:"forbiddenUsernames"`
SuggestedUsernames []string `json:"suggestedUsernames"`
}
type videoSettings struct {