Add thumbnail support to Canvas and storage backends

Introduces a 'thumbnail' field to the Canvas model and updates all storage backends (AWS S3, filesystem, memory, and SQLite) to handle storing and retrieving this field. Also updates the API handler to accept and save the thumbnail, and switches SQLite driver to modernc.org/sqlite for improved compatibility. Updates .gitignore to exclude .db files.
This commit is contained in:
Yuzhong Zhang
2025-07-06 15:02:58 +08:00
parent e4981703fe
commit 44414af085
9 changed files with 189 additions and 87 deletions
+13 -6
View File
@@ -113,20 +113,27 @@ func HandleSaveCanvas(store stores.Store) http.HandlerFunc {
AppState struct {
Name string `json:"name"`
} `json:"appState"`
Thumbnail string `json:"thumbnail"`
}
// We make a copy of the body because json.Unmarshal will consume the reader.
bodyCopy := make([]byte, len(body))
copy(bodyCopy, body)
canvasName := key // Default to key
if err := json.Unmarshal(bodyCopy, &canvasData); err == nil && canvasData.AppState.Name != "" {
canvasName = canvasData.AppState.Name
var canvasThumbnail string
if err := json.Unmarshal(bodyCopy, &canvasData); err == nil {
if canvasData.AppState.Name != "" {
canvasName = canvasData.AppState.Name
}
canvasThumbnail = canvasData.Thumbnail
}
canvas := &core.Canvas{
ID: key,
UserID: claims.Subject,
Name: canvasName,
Data: body,
ID: key,
UserID: claims.Subject,
Name: canvasName,
Thumbnail: canvasThumbnail,
Data: body,
}
if err := store.Save(r.Context(), canvas); err != nil {