mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
use slices.Contains.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,7 +17,6 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/m1k1o/neko-rooms/internal/types"
|
"github.com/m1k1o/neko-rooms/internal/types"
|
||||||
"github.com/m1k1o/neko-rooms/internal/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PullManagerCtx struct {
|
type PullManagerCtx struct {
|
||||||
@@ -75,7 +75,7 @@ func (manager *PullManagerCtx) setDone() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (manager *PullManagerCtx) Start(request types.PullStart) error {
|
func (manager *PullManagerCtx) Start(request types.PullStart) error {
|
||||||
if in, _ := utils.ArrayIn(request.NekoImage, manager.images); !in {
|
if !slices.Contains(manager.images, request.NekoImage) {
|
||||||
return fmt.Errorf("unknown neko image")
|
return fmt.Errorf("unknown neko image")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -246,12 +247,10 @@ func (manager *RoomManagerCtx) Create(ctx context.Context, settings types.RoomSe
|
|||||||
return "", fmt.Errorf("invalid container name, must match %s", dockerNames.RestrictedNameChars)
|
return "", fmt.Errorf("invalid container name, must match %s", dockerNames.RestrictedNameChars)
|
||||||
}
|
}
|
||||||
|
|
||||||
if in, _ := utils.ArrayIn(settings.NekoImage, manager.config.NekoImages); !in {
|
if !slices.Contains(manager.config.NekoImages, settings.NekoImage) {
|
||||||
return "", fmt.Errorf("invalid neko image")
|
return "", fmt.Errorf("invalid neko image")
|
||||||
}
|
}
|
||||||
|
|
||||||
isPrivilegedImage, _ := utils.ArrayIn(settings.NekoImage, manager.config.NekoPrivilegedImages)
|
|
||||||
|
|
||||||
// if api version is not set, try to detect it
|
// if api version is not set, try to detect it
|
||||||
if settings.ApiVersion == 0 {
|
if settings.ApiVersion == 0 {
|
||||||
inspect, _, err := manager.client.ImageInspectWithRaw(ctx, settings.NekoImage)
|
inspect, _, err := manager.client.ImageInspectWithRaw(ctx, settings.NekoImage)
|
||||||
@@ -669,7 +668,7 @@ func (manager *RoomManagerCtx) Create(ctx context.Context, settings types.RoomSe
|
|||||||
// DNS
|
// DNS
|
||||||
DNS: settings.DNS,
|
DNS: settings.DNS,
|
||||||
// Privileged
|
// Privileged
|
||||||
Privileged: isPrivilegedImage,
|
Privileged: slices.Contains(manager.config.NekoPrivilegedImages, settings.NekoImage),
|
||||||
}
|
}
|
||||||
|
|
||||||
networkingConfig := &network.NetworkingConfig{
|
networkingConfig := &network.NetworkingConfig{
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/m1k1o/neko-rooms/internal/config"
|
"github.com/m1k1o/neko-rooms/internal/config"
|
||||||
"github.com/m1k1o/neko-rooms/internal/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -98,7 +98,7 @@ func (settings *RoomSettings) toEnvV2(config *config.Room, ports PortSettings) [
|
|||||||
}
|
}
|
||||||
|
|
||||||
for key, val := range settings.Envs {
|
for key, val := range settings.Envs {
|
||||||
if in, _ := utils.ArrayIn(key, blacklistedEnvsV2); !in {
|
if !slices.Contains(blacklistedEnvsV2, key) {
|
||||||
env = append(env, fmt.Sprintf("%s=%s", key, val))
|
env = append(env, fmt.Sprintf("%s=%s", key, val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ func (settings *RoomSettings) fromEnvV2(envs []string) error {
|
|||||||
case "NEKO_AUDIO":
|
case "NEKO_AUDIO":
|
||||||
settings.AudioPipeline = val
|
settings.AudioPipeline = val
|
||||||
default:
|
default:
|
||||||
if in, _ := utils.ArrayIn(key, blacklistedEnvsV2); !in {
|
if !slices.Contains(blacklistedEnvsV2, key) {
|
||||||
settings.Envs[key] = val
|
settings.Envs[key] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/m1k1o/neko-rooms/internal/config"
|
"github.com/m1k1o/neko-rooms/internal/config"
|
||||||
"github.com/m1k1o/neko-rooms/internal/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -107,7 +107,7 @@ func (settings *RoomSettings) toEnvV3(config *config.Room, ports PortSettings) [
|
|||||||
}
|
}
|
||||||
|
|
||||||
for key, val := range settings.Envs {
|
for key, val := range settings.Envs {
|
||||||
if in, _ := utils.ArrayIn(key, blacklistedEnvsV3); !in {
|
if !slices.Contains(blacklistedEnvsV3, key) {
|
||||||
env = append(env, fmt.Sprintf("%s=%s", key, val))
|
env = append(env, fmt.Sprintf("%s=%s", key, val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ func (settings *RoomSettings) fromEnvV3(envs []string) error {
|
|||||||
case "NEKO_CAPTURE_AUDIO_PIPELINE":
|
case "NEKO_CAPTURE_AUDIO_PIPELINE":
|
||||||
settings.AudioPipeline = val
|
settings.AudioPipeline = val
|
||||||
default:
|
default:
|
||||||
if in, _ := utils.ArrayIn(key, blacklistedEnvsV3); !in {
|
if !slices.Contains(blacklistedEnvsV3, key) {
|
||||||
settings.Envs[key] = val
|
settings.Envs[key] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
func ArrayIn[T comparable](val T, array []T) (exists bool, index int) {
|
|
||||||
exists, index = false, -1
|
|
||||||
|
|
||||||
for i, a := range array {
|
|
||||||
if a == val {
|
|
||||||
exists, index = true, i
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user