更新项目架构与存储适配器,添加用户认证功能

本次提交包含以下主要更改:
1. 更新 `.gitignore` 文件,添加对 `node_modules` 和环境变量文件的忽略。
2. 修改 `.gitmodules` 文件,替换为新的子模块 `cloudflare-worker`。
3. 新增 `ARCHITECTURE.md` 和 `PROJECT_REFACTOR_PLAN.md` 文档,详细描述项目架构和改造计划。
4. 实现用户认证功能,添加 GitHub OAuth 处理逻辑,支持 JWT 生成与解析。
5. 引入新的存储接口 `CanvasStore`,并实现相应的存储逻辑,支持用户画布的增删改查。
6. 更新 `main.go` 文件,整合新的认证与存储逻辑,优化路由设置。

这些更改旨在提升项目的可扩展性与用户体验,支持多用户环境下的画布管理与存储。
This commit is contained in:
Yuzhong Zhang
2025-07-05 23:13:17 +08:00
parent 61abbc612b
commit 94953a5eac
26 changed files with 2078 additions and 293 deletions
+21 -6
View File
@@ -11,9 +11,15 @@ import (
"github.com/sirupsen/logrus"
)
func GetStore() core.DocumentStore {
// 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 core.DocumentStore
var store Store
storageField := logrus.Fields{
"storageType": storageType,
@@ -22,18 +28,27 @@ func GetStore() core.DocumentStore {
switch storageType {
case "filesystem":
basePath := os.Getenv("LOCAL_STORAGE_PATH")
if basePath == "" {
basePath = "./data" // Default path
}
storageField["basePath"] = basePath
store = filesystem.NewDocumentStore(basePath)
store = filesystem.NewStore(basePath)
case "sqlite":
dataSourceName := os.Getenv("DATA_SOURCE_NAME")
if dataSourceName == "" {
dataSourceName = "excalidraw.db" // Default filename
}
storageField["dataSourceName"] = dataSourceName
store = sqlite.NewDocumentStore(dataSourceName)
store = sqlite.NewStore(dataSourceName)
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.NewDocumentStore(bucketName)
store = aws.NewStore(bucketName)
default:
store = memory.NewDocumentStore()
store = memory.NewStore()
storageField["storageType"] = "in-memory"
}
logrus.WithFields(storageField).Info("Use storage")