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:
@@ -4,6 +4,7 @@ import (
|
|||||||
"bookmann/internal/database"
|
"bookmann/internal/database"
|
||||||
"bookmann/internal/services"
|
"bookmann/internal/services"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"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()})
|
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(
|
folder, err := h.libraryService.AddLibraryFolder(
|
||||||
c.Request().Context(),
|
c.Request().Context(),
|
||||||
libraryID,
|
libraryID,
|
||||||
|
|||||||
Reference in New Issue
Block a user