Add db support for workspaces

This commit is contained in:
2024-10-14 21:08:37 +02:00
parent b36c5b30c6
commit 2d2b596f2c
8 changed files with 212 additions and 38 deletions

View File

@@ -0,0 +1,29 @@
package filesystem
import (
"fmt"
"os"
"path/filepath"
"novamd/internal/models"
)
// GetWorkspacePath returns the file system path for a given workspace
func GetWorkspacePath(workspace *models.Workspace) string {
baseDir := os.Getenv("NOVAMD_WORKDIR")
if baseDir == "" {
baseDir = "./data" // Default if not set
}
return filepath.Join(baseDir, fmt.Sprintf("%d", workspace.UserID), workspace.Name)
}
// GetFilePath returns the file system path for a given file within a workspace
func GetFilePath(workspace *models.Workspace, relativeFilePath string) string {
return filepath.Join(GetWorkspacePath(workspace), relativeFilePath)
}
// EnsureWorkspaceDirectory creates the workspace directory if it doesn't exist
func EnsureWorkspaceDirectory(workspace *models.Workspace) error {
dir := GetWorkspacePath(workspace)
return os.MkdirAll(dir, 0755)
}