Fix: ensure DB updates for thumbnails
All checks were successful
Automated Container Build / build-and-push (push) Successful in 59s

This commit is contained in:
Elijah 2026-05-25 14:49:29 -07:00
parent 80d60d540a
commit 8995b48eb5

View file

@ -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),