updated file browser url logic
All checks were successful
Build and Push Docker Image / Build image (push) Successful in 1m40s

This commit is contained in:
2025-05-27 13:20:37 +03:00
parent 8e2806deb2
commit 1be267e0ff
4 changed files with 35 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package docker
import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"maps"
@@ -656,6 +657,14 @@ func (im *InstanceManager) StopFileBrowser(ctx context.Context, serverId string)
return nil
}
func (im *InstanceManager) GetServerIdFromFileBrowserUrl(ctx context.Context, url string) (string, error) {
pathSegments := strings.Split(url, "/")
if len(pathSegments) < 3 {
return "", errors.New("invalid url")
}
return pathSegments[2], nil
}
func NewInstanceManager(config models.DockerInstanceManagerConfig, siteDomain string) (*InstanceManager, error) {
apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {

View File

@@ -60,6 +60,7 @@ type InstanceManager interface {
// Read Only
GetFileBrowser(ctx context.Context, serverId string) (*models.FileBrowser, error)
ListFileBrowsers(ctx context.Context) ([]models.FileBrowser, error)
GetServerIdFromFileBrowserUrl(ctx context.Context, serverId string) (string, error)
// Status Changing
StartFileBrowser(ctx context.Context, serverId string) (*models.FileBrowser, error)

View File

@@ -8,6 +8,8 @@ import (
"strings"
"time"
gerrors "errors"
"git.acooldomain.co/server-manager/backend/instancemanager"
"git.acooldomain.co/server-manager/backend/models"
servermanagerv1 "git.acooldomain.co/server-manager/kubernetes-operator/api/v1alpha1"
@@ -355,6 +357,14 @@ func (i *InstanceManager) StopFileBrowser(ctx context.Context, serverId string)
return nil
}
func (im *InstanceManager) GetServerIdFromFileBrowserUrl(ctx context.Context, url string) (string, error) {
pathSegments := strings.Split(url, "/")
if len(pathSegments) < 4 {
return "", gerrors.New("invalid url")
}
return pathSegments[3], nil
}
func NewInstanceManager(config models.KubernetesInstanceManagerConfig) (*InstanceManager, error) {
c, err := rest.InClusterConfig()
if err != nil {