Sora ed43b16628 fix it
# Code Review Fixes - All Applied 

All suggestions from code review have been successfully implemented.

## Fix #1: Simplified File Reading 
**Location**: `server/public/handle_shares.go`

**Before**:
```go
tmplContent := make([]byte, 0)
buf := make([]byte, 1024)
for {
    n, err := tmplData.Read(buf)
    if n > 0 {
        tmplContent = append(tmplContent, buf[:n]...)
    }
    if err != nil {
        break
    }
}
```

**After**:
```go
tmplContent, err := io.ReadAll(tmplData)
if err != nil {
    log.Error(r.Context(), "Error reading aplayer.html template", err)
    http.Error(w, "Error reading template", http.StatusInternalServerError)
    return
}
```

**Benefits**: More concise, robust error handling, removed unnecessary buffer variable

---

## Fix #2: Simplified Script Reading 
**Location**: `server/public/handle_shares.go`

**Before**:
```go
scriptContent := make([]byte, 0)
for {
    n, err := scriptData.Read(buf)
    if n > 0 {
        scriptContent = append(scriptContent, buf[:n]...)
    }
    if err != nil {
        break
    }
}
```

**After**:
```go
scriptContent, err := io.ReadAll(scriptData)
if err != nil {
    log.Error(r.Context(), "Error reading aplayer-share.js", err)
    http.Error(w, "Error reading script", http.StatusInternalServerError)
    return
}
```

**Benefits**: Consistent with file reading pattern, better error handling

---

## Fix #3: Removed Redundant Code 
**Location**: `server/public/handle_shares.go`

**Before**:
```go
baseURL := str.SanitizeText(conf.Server.BasePath)
if baseURL == "" {
    baseURL = ""
}
```

**After**:
```go
baseURL := str.SanitizeText(conf.Server.BasePath)
```

**Benefits**: Eliminated no-op code

---

## Fix #4: Fixed Material-UI Link Props 
**Location**: `ui/src/share/ShareEdit.jsx`

**Before**:
```jsx
<Link source="URL" href={url} target="_blank" rel="noopener noreferrer">
    {url}
</Link>
<Link source="APlayerURL" href={aplayerUrl} target="_blank" rel="noopener noreferrer">
    {aplayerUrl}
</Link>
```

**After**:
```jsx
<Link href={url} target="_blank" rel="noopener noreferrer">
    {url}
</Link>
<Link href={aplayerUrl} target="_blank" rel="noopener noreferrer">
    {aplayerUrl}
</Link>
```

**Benefits**: Removed invalid `source` prop, proper React component usage

---

## Fix #5: Vendored APlayer Assets 
**Location**: Multiple files

**Before**: CDN-hosted assets from `cdn.jsdelivr.net`

**After**: Local vendored assets

**Implementation**:
- Downloaded `APlayer.min.css` and `APlayer.min.js` to `resources/`
- Created `server/public/handle_aplayer_assets.go` with asset handlers
- Added routes `/public/aplayer/APlayer.min.css` and `/public/aplayer/APlayer.min.js`
- Updated `resources/aplayer.html` to reference local URLs
- Assets cached for 1 year

**Benefits**:
- Works in offline/intranet environments
- No external dependencies
- Better privacy (no CDN tracking)
- Faster load times
- Consistent versioning

---

## Fix #6: Buffer Template Rendering 
**Location**: `server/public/handle_shares.go`

**Before**:
```go
w.Header().Set("Content-Type", "text/html; charset=utf-8")
err = tmpl.Execute(w, data)
if err != nil {
    log.Error(r.Context(), "Error executing aplayer template", err)
}
```

**After**:
```go
var buf bytes.Buffer
if err := tmpl.Execute(&buf, data); err != nil {
    log.Error(r.Context(), "Error executing aplayer template", err)
    http.Error(w, "Error rendering page", http.StatusInternalServerError)
    return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write(buf.Bytes())
```

**Benefits**:
- Prevents partial HTML responses on template errors
- Proper HTTP error response if rendering fails
- More robust error handling
- Clients only receive complete, valid HTML

---

## Build Status

 All fixes applied
 Code compiles successfully
 No errors or warnings
 Ready for production

## Files Modified Summary

1. `server/public/handle_shares.go` - 4 improvements
2. `server/public/handle_aplayer_assets.go` - New file (asset handlers)
3. `server/public/public.go` - Added routes
4. `ui/src/share/ShareEdit.jsx` - Fixed component props
5. `resources/aplayer.html` - Updated to use local assets
6. `resources/APlayer.min.css` - Vendored asset
7. `resources/APlayer.min.js` - Vendored asset

## Code Quality Metrics

- **Readability**: Improved with `io.ReadAll()` usage
- **Robustness**: Better error handling throughout
- **Performance**: Assets cached for 1 year
- **Reliability**: Buffer rendering prevents partial responses
- **Maintainability**: Removed redundant code
- **Standards Compliance**: Fixed React component usage

---

**Status**:  All Code Review Suggestions Implemented
**Last Updated**: 2025-12-16
2025-12-16 09:50:52 +08:00
2025-12-16 09:39:32 +08:00
2025-12-16 09:50:52 +08:00
2025-12-16 09:39:32 +08:00
2025-12-16 09:05:07 +08:00
2025-12-16 09:05:07 +08:00

Navidrome logo

Navidrome Music Server  Tweet

Last Release Build Downloads Docker Pulls Dev Chat Subreddit Contributor Covenant Gurubase

Navidrome is an open source web-based music collection server and streamer. It gives you freedom to listen to your music collection from any browser or mobile device. It's like your personal Spotify!

Note: The master branch may be in an unstable or even broken state during development. Please use releases instead of the master branch in order to get a stable set of binaries.

Check out our Live Demo!

Any feedback is welcome! If you need/want a new feature, find a bug or think of any way to improve Navidrome, please file a GitHub issue or join the discussion in our Subreddit. If you want to contribute to the project in any other way (ui/backend dev, translations, themes), please join the chat in our Discord server.

Installation

See instructions on the project's website

Cloud Hosting

PikaPods has partnered with us to offer you an officially supported, cloud-hosted solution. A share of the revenue helps fund the development of Navidrome at no additional cost for you.

PikaPods

Features

  • Handles very large music collections
  • Streams virtually any audio format available
  • Reads and uses all your beautifully curated metadata
  • Great support for compilations (Various Artists albums) and box sets (multi-disc albums)
  • Multi-user, each user has their own play counts, playlists, favourites, etc...
  • Very low resource usage
  • Multi-platform, runs on macOS, Linux and Windows. Docker images are also provided
  • Ready to use binaries for all major platforms, including Raspberry Pi
  • Automatically monitors your library for changes, importing new files and reloading new metadata
  • Themeable, modern and responsive Web interface based on Material UI
  • Compatible with all Subsonic/Madsonic/Airsonic clients
  • Transcoding on the fly. Can be set per user/player. Opus encoding is supported
  • Translated to various languages

Translations

Navidrome uses POEditor for translations, and we are always looking for more contributors

Documentation

All documentation can be found in the project's website: https://www.navidrome.org/docs. Here are some useful direct links:

Screenshots

Languages
Go 81.8%
JavaScript 15.2%
Rust 2.3%
Makefile 0.2%
Shell 0.2%
Other 0.2%