mirror of
https://github.com/renorris/openfsd
synced 2026-04-16 23:25:35 +08:00
Add ConfigRepository and enhance server configuration management
1. Database Enhancements (db/repositories.go): - Added ConfigRepository interface and implementations for PostgreSQL and SQLite - Updated Repositories struct to include ConfigRepository - Modified NewRepositories to initialize both UserRepo and ConfigRepo 2. FSD Server Improvements: - Removed hardcoded jwtSecret, now retrieved from ConfigRepository (fsd/conn.go, web/auth.go) - Added dynamic welcome message retrieval from ConfigRepository (fsd/conn.go) - Optimized METAR buffer size from 4096 to 512 bytes (fsd/metar.go) - Reduced minimum fields for DeleteATC and DeletePilot packets (fsd/packet.go) - Improved Haversine distance calculation with constants (fsd/postoffice.go) - Added thread-safety documentation for sendError (fsd/client.go) 3. Server Configuration (fsd/server.go): - Added NewDefaultServer to initialize server with environment-based config - Implemented automatic database migration and default admin user creation - Added configurable METAR worker count - Improved logging with slog and environment-based debug level 4. Web Interface Enhancements: - Added user and config editor frontend routes (web/frontend.go, web/routes.go) - Improved JWT handling by retrieving secret from ConfigRepository (web/auth.go) - Enhanced user management API endpoints (web/user.go) - Updated dashboard to display CID and conditional admin links (web/templates/dashboard.html) - Embedded templates using go:embed (web/templates.go) 5. Frontend JavaScript Improvements: - Added networkRatingFromInt helper for readable ratings (web/static/js/openfsd/dashboard.js) - Improved API request handling with auth/no-auth variants (web/static/js/openfsd/api.js) 6. Miscellaneous: - Added sethvargo/go-envconfig dependency for environment variable parsing - Fixed parseVisRange to use 64-bit float parsing (fsd/util.go) - Added strPtr utility function (fsd/util.go, web/main.go) - Improved SVG logo rendering in layout (web/templates/layout.html)
This commit is contained in:
12
fsd/util.go
12
fsd/util.go
@@ -194,7 +194,7 @@ func parseLatLon(packet []byte, latIndex, lonIndex int) (lat float64, lon float6
|
||||
|
||||
// parseVisRange parses an FSD-encoded visibility range and returns the distance in meters
|
||||
func parseVisRange(packet []byte, index int) (visRange float64, ok bool) {
|
||||
visRangeNauticalMiles, err := strconv.ParseFloat(string(getField(packet, index)), 10)
|
||||
visRangeNauticalMiles, err := strconv.ParseFloat(string(getField(packet, index)), 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func broadcastRanged(po *postOffice, client *Client, packet []byte) {
|
||||
func broadcastRangedVelocity(po *postOffice, client *Client, packet []byte) {
|
||||
packetStr := string(packet)
|
||||
po.search(client, func(recipient *Client) bool {
|
||||
if client.protoRevision != 101 {
|
||||
if recipient.protoRevision != 101 {
|
||||
return true
|
||||
}
|
||||
recipient.send(packetStr)
|
||||
@@ -232,7 +232,7 @@ func broadcastRangedVelocity(po *postOffice, client *Client, packet []byte) {
|
||||
func broadcastRangedAtcOnly(po *postOffice, client *Client, packet []byte) {
|
||||
packetStr := string(packet)
|
||||
po.search(client, func(recipient *Client) bool {
|
||||
if !client.isAtc {
|
||||
if !recipient.isAtc {
|
||||
return true
|
||||
}
|
||||
recipient.send(packetStr)
|
||||
@@ -265,7 +265,7 @@ func broadcastAllATC(po *postOffice, client *Client, packet []byte) {
|
||||
func broadcastAllSupervisors(po *postOffice, client *Client, packet []byte) {
|
||||
packetStr := string(packet)
|
||||
po.all(client, func(recipient *Client) bool {
|
||||
if client.networkRating < NetworkRatingSupervisor {
|
||||
if recipient.networkRating < NetworkRatingSupervisor {
|
||||
return true
|
||||
}
|
||||
recipient.send(packetStr)
|
||||
@@ -352,3 +352,7 @@ func buildBeaconCodePacket(source, recipient, targetCallsign, beaconCode string)
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func strPtr(str string) *string {
|
||||
return &str
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user