This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/handlers/storage.go
Jeffrey Smith 11fd8c1e57 step 1: rename module chat-switchboard → switchboard-core
- go.mod module name
- All 714 import references across 289 Go files
- VERSION: 0.1.0
- CI DB names: switchboard_core_{ci,dev,test}
- Docker image: gobha/switchboard-core
- Test fixtures: JWT issuer, repo names
- .env.example, docker-compose container name
- Compiles clean (go build exit 0)
2026-03-25 19:48:04 -04:00

63 lines
1.5 KiB
Go

package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
"switchboard-core/storage"
)
// storageConfigured is a package-level flag set during init.
// Read by PublicSettings to include in the boot payload.
var storageConfigured bool
// SetStorageConfigured sets the package-level flag indicating whether
// file storage is available. Called from main.go after storage init.
func SetStorageConfigured(configured bool) {
storageConfigured = configured
}
// StorageHandler handles file storage admin endpoints.
type StorageHandler struct {
store storage.ObjectStore
}
// NewStorageHandler creates a StorageHandler.
// store may be nil if storage is not configured.
func NewStorageHandler(store storage.ObjectStore) *StorageHandler {
return &StorageHandler{store: store}
}
// Configured returns true if a storage backend is available.
func (h *StorageHandler) Configured() bool {
return h.store != nil
}
// Status returns storage backend status and statistics.
//
// GET /admin/storage/status
func (h *StorageHandler) Status(c *gin.Context) {
if h.store == nil {
c.JSON(http.StatusOK, gin.H{
"backend": "none",
"configured": false,
"healthy": false,
})
return
}
stats, err := h.store.Stats(c.Request.Context())
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": "failed to collect storage stats",
"backend": h.store.Backend(),
"configured": true,
"healthy": false,
})
return
}
c.JSON(http.StatusOK, stats)
}