fix: validate library folder paths before saving

- Add os package import for file system checks
- Validate that folder paths exist before adding to library
- Check folder accessibility to prevent invalid paths
- Return clear error messages for invalid folders

Improves user experience by catching path errors early
This commit is contained in:
2026-01-29 09:23:33 -05:00
parent 7f8b898105
commit 1b5c70be71
+9
View File
@@ -4,6 +4,7 @@ import (
"bookmann/internal/database"
"bookmann/internal/services"
"net/http"
"os"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
@@ -173,6 +174,14 @@ func (h *LibraryHandler) AddLibraryFolder(c echo.Context) error {
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
}
// Validate that folder path exists and is accessible
if _, err := os.Stat(req.FolderPath); os.IsNotExist(err) {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "folder path does not exist"})
}
if err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "folder is not accessible"})
}
folder, err := h.libraryService.AddLibraryFolder(
c.Request().Context(),
libraryID,