文件系统的存储方式

This commit is contained in:
Yuzhong Zhang
2025-07-06 15:38:14 +08:00
parent 44414af085
commit 7083d04fbf
4 changed files with 22 additions and 1 deletions
+1
View File
@@ -9,3 +9,4 @@ node_modules
*.env *.env
*/build/* */build/*
*.db *.db
data/
+1 -1
View File
@@ -12,7 +12,7 @@ type (
UserID string `json:"-"` // Not exposed in JSON responses, used internally. UserID string `json:"-"` // Not exposed in JSON responses, used internally.
Name string `json:"name"` Name string `json:"name"`
Thumbnail string `json:"thumbnail,omitempty"` Thumbnail string `json:"thumbnail,omitempty"`
Data []byte `json:"-"` // The full canvas data, not included in list views. Data []byte `json:"data,omitempty"` // The full canvas data, not included in list views.
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"` UpdatedAt time.Time `json:"updatedAt"`
} }
+12
View File
@@ -0,0 +1,12 @@
version: '3.8'
services:
excalidraw:
image: ghcr.io/betterandbetterii/excalidraw-full-linuxdo:linux-do
ports:
- "3002:3002"
volumes:
- ./data:/root/data
- ./excalidraw.db:/root/excalidraw.db
env_file:
- .env
+8
View File
@@ -92,6 +92,12 @@ func (s *fsStore) List(ctx context.Context, userID string) ([]*core.Canvas, erro
for _, file := range files { for _, file := range files {
if !file.IsDir() { if !file.IsDir() {
filePath := filepath.Join(userPath, file.Name()) filePath := filepath.Join(userPath, file.Name())
fileInfo, err := file.Info()
if err != nil {
log.WithError(err).Warnf("Failed to get file info for %s, skipping", file.Name())
continue
}
data, err := os.ReadFile(filePath) data, err := os.ReadFile(filePath)
if err != nil { if err != nil {
log.WithError(err).Warnf("Failed to read canvas file %s, skipping", file.Name()) log.WithError(err).Warnf("Failed to read canvas file %s, skipping", file.Name())
@@ -105,7 +111,9 @@ func (s *fsStore) List(ctx context.Context, userID string) ([]*core.Canvas, erro
} }
// For list view, we don't need the full data blob. // For list view, we don't need the full data blob.
// Also ensure we populate metadata from the filesystem.
canvas.Data = nil canvas.Data = nil
canvas.UpdatedAt = fileInfo.ModTime()
canvases = append(canvases, &canvas) canvases = append(canvases, &canvas)
} }
} }