Only can create boost on enabled destinations

This commit is contained in:
LittleSheep 2024-12-28 23:12:19 +08:00
parent 49a8159e35
commit ec0444b35c

View File

@ -1,6 +1,7 @@
package services package services
import ( import (
"encoding/json"
"fmt" "fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec" "git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
@ -63,9 +64,14 @@ func CreateBoost(user *sec.UserInfo, source models.Attachment, destination int)
AccountID: user.ID, AccountID: user.ID,
} }
dests := cast.ToSlice(viper.Get("destinations")) if des, ok := destinationsByIndex[destination]; !ok {
if destination >= len(dests) {
return boost, fmt.Errorf("invalid destination: %d", destination) return boost, fmt.Errorf("invalid destination: %d", destination)
} else {
var destBase models.BaseDestination
json.Unmarshal(des.Raw, &destBase)
if !destBase.IsBoost {
return boost, fmt.Errorf("invalid destination: %d; wasn't available for boost", destination)
}
} }
if err := database.C.Create(&boost).Error; err != nil { if err := database.C.Create(&boost).Error; err != nil {