fix(api): ensure files array is never null in API response

Add null safety checks to prevent TypeError when backend returns null
instead of empty array for files list. Initialize empty slices on backend
and add null coalescing on frontend when accessing files state.

- Backend: Initialize files slice to always return [] instead of null
- Frontend: Add null checks for files state in all map/filter operations
This commit is contained in:
2026-02-06 08:59:11 -05:00
parent a80de1730c
commit 10f584f9a8
3 changed files with 15 additions and 10 deletions

View File

@@ -44,23 +44,23 @@ func (s *Storage) List() ([]*File, error) {
return nil, fmt.Errorf("failed to read directory: %w", err)
}
var files []*File
files := make([]*File, 0)
for _, entry := range entries {
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".md") {
continue
}
info, err := entry.Info()
if err != nil {
continue
}
files = append(files, &File{
Name: entry.Name(),
Modified: info.ModTime().Unix(),
})
}
logging.Logger.WithField("count", len(files)).Info("Listed files")
return files, nil
}