mirror of
https://github.com/Dvorinka/excalidraw-full.git
synced 2026-06-03 13:52:56 +00:00
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package stores
|
|
|
|
import (
|
|
"excalidraw-complete/core"
|
|
"excalidraw-complete/stores/aws"
|
|
"excalidraw-complete/stores/filesystem"
|
|
"excalidraw-complete/stores/memory"
|
|
"excalidraw-complete/stores/postgres"
|
|
"os"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Store is a union interface that includes all store types.
|
|
type Store interface {
|
|
core.DocumentStore
|
|
core.CanvasStore
|
|
}
|
|
|
|
func GetStore() Store {
|
|
storageType := os.Getenv("STORAGE_TYPE")
|
|
var store Store
|
|
|
|
storageField := logrus.Fields{
|
|
"storageType": storageType,
|
|
}
|
|
|
|
switch storageType {
|
|
case "filesystem":
|
|
basePath := os.Getenv("LOCAL_STORAGE_PATH")
|
|
if basePath == "" {
|
|
basePath = "./data" // Default path
|
|
}
|
|
storageField["basePath"] = basePath
|
|
store = filesystem.NewStore(basePath)
|
|
case "postgres", "":
|
|
databaseURL := os.Getenv("DATABASE_URL")
|
|
if databaseURL == "" {
|
|
logrus.Fatal("DATABASE_URL environment variable must be set for postgres storage")
|
|
}
|
|
storageField["databaseURL"] = "configured"
|
|
store = postgres.NewStore(databaseURL)
|
|
case "s3":
|
|
bucketName := os.Getenv("S3_BUCKET_NAME")
|
|
if bucketName == "" {
|
|
logrus.Fatal("S3_BUCKET_NAME environment variable must be set for s3 storage type")
|
|
}
|
|
storageField["bucketName"] = bucketName
|
|
store = aws.NewStore(bucketName)
|
|
default:
|
|
store = memory.NewStore()
|
|
storageField["storageType"] = "in-memory"
|
|
}
|
|
logrus.WithFields(storageField).Info("Use storage")
|
|
return store
|
|
}
|