diff --git a/backend/handlers/onlyoffice.go b/backend/handlers/onlyoffice.go index 95b8726..ee2802b 100644 --- a/backend/handlers/onlyoffice.go +++ b/backend/handlers/onlyoffice.go @@ -114,7 +114,15 @@ func (h *OnlyOfficeHandler) scheduleThumbnailUpdate(targetPath, relativePath str return } - h.DB.Exec("UPDATE files SET checksum = ?, size = ?, updated_at = CURRENT_TIMESTAMP WHERE path = ?", checksum, info.Size(), filepath.ToSlash(relativePath)) + h.DB.Exec(` + INSERT INTO files (path, name, size, mime_type, checksum) + VALUES (?, ?, ?, ?, ?) + ON CONFLICT(path) DO UPDATE SET + checksum=excluded.checksum, + size=excluded.size, + updated_at=CURRENT_TIMESTAMP`, + filepath.ToSlash(relativePath), filepath.Base(relativePath), info.Size(), mime.TypeByExtension(filepath.Ext(relativePath)), checksum, + ) workers.Instance.Enqueue(workers.ThumbnailJob{ FilePath: relativePath, @@ -209,6 +217,9 @@ func (h *OnlyOfficeHandler) CreateBlank(c *fiber.Ctx) error { // Return the relative path relativePath, _ := filepath.Rel(h.Config.StorageDir, finalPath) + // Enqueue for thumbnail generation (with 10s debounce) + h.scheduleThumbnailUpdate(finalPath, relativePath) + return c.JSON(fiber.Map{ "path": filepath.ToSlash(relativePath), "name": filepath.Base(finalPath), @@ -270,6 +281,9 @@ func (h *OnlyOfficeHandler) CreateFromTemplate(c *fiber.Ctx) error { } relativePath, _ := filepath.Rel(h.Config.StorageDir, finalPath) + + h.scheduleThumbnailUpdate(finalPath, relativePath) + return c.JSON(fiber.Map{ "path": filepath.ToSlash(relativePath), "name": filepath.Base(finalPath),