diff --git a/internal/store/store_query.go b/internal/store/store_query.go index 7de7487..c02f8b3 100644 --- a/internal/store/store_query.go +++ b/internal/store/store_query.go @@ -339,6 +339,19 @@ func applyDiscardDetailsFilters(q *gorm.DB, opts ListOptions) *gorm.DB { return q } +func (s *Store) DeleteDiscardDetailsByIDs(ids []uint64) (int64, error) { + if len(ids) == 0 { + return 0, nil + } + result := s.db.Where("id IN ?", ids).Delete(&DiscardDetailsRecord{}) + return result.RowsAffected, result.Error +} + +func (s *Store) DeleteAllDiscardDetails() (int64, error) { + result := s.db.Where("1 = 1").Delete(&DiscardDetailsRecord{}) + return result.RowsAffected, result.Error +} + func (s *Store) DeleteTextMessage(id uint64) error { result := s.db.Where("id = ?", id).Delete(&TextMessageRecord{}) if result.Error != nil { diff --git a/internal/web/web.go b/internal/web/web.go index 279a0be..300966a 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -84,7 +84,7 @@ func NewRouter(cfg configpkg.WebConfig, consoleLog bool, store *storepkg.Store, return r } -const BackendVersion = "1.1.0" +const BackendVersion = "1.2.0" var CommitVersion = "dev" @@ -399,6 +399,33 @@ func registerAdminRoutes(r gin.IRouter, store *storepkg.Store, sessions *auth.Ma rows, err := store.ListLoginLogs(opts) writeListResponse(c, rows, opts, err, loginLogDTO) }) + protected.POST("/discard-details/batch-delete", func(c *gin.Context) { + var req struct { + IDs []uint64 `json:"ids"` + } + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + if len(req.IDs) == 0 { + c.JSON(http.StatusBadRequest, gin.H{"error": "ids is empty"}) + return + } + count, err := store.DeleteDiscardDetailsByIDs(req.IDs) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{"status": "ok", "deleted_count": count}) + }) + protected.DELETE("/discard-details", func(c *gin.Context) { + count, err := store.DeleteAllDiscardDetails() + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{"status": "ok", "deleted_count": count}) + }) protected.DELETE("/text-messages/:id", func(c *gin.Context) { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil || id == 0 { diff --git a/meshmap_frontend/src/api.ts b/meshmap_frontend/src/api.ts index a99fb55..a0c3a46 100644 --- a/meshmap_frontend/src/api.ts +++ b/meshmap_frontend/src/api.ts @@ -235,6 +235,14 @@ export function getDiscardDetails(limit = 100, offset = 0): Promise>(listPath('/api/discard-details', limit, offset)) } +export function deleteDiscardDetailsByIDs(ids: number[]): Promise<{ status: string; deleted_count: number }> { + return postJSON<{ status: string; deleted_count: number }>('/api/admin/discard-details/batch-delete', { ids }) +} + +export function clearDiscardDetails(): Promise<{ status: string; deleted_count: number }> { + return deleteJSON<{ status: string; deleted_count: number }>('/api/admin/discard-details') +} + export function getTelemetry(limit = 500, offset = 0, nodeId = ''): Promise> { return getJSON>(listPath('/api/telemetry', limit, offset, nodeId)) } diff --git a/meshmap_frontend/src/components/AdminDiscardDetails.vue b/meshmap_frontend/src/components/AdminDiscardDetails.vue index 328bfd8..c82675b 100644 --- a/meshmap_frontend/src/components/AdminDiscardDetails.vue +++ b/meshmap_frontend/src/components/AdminDiscardDetails.vue @@ -1,7 +1,8 @@ @@ -45,7 +119,19 @@ onMounted(refreshItems)

Discard details

丢弃数据

- +
+ + + +

{{ error }}

@@ -53,6 +139,15 @@ onMounted(refreshItems) + @@ -67,6 +162,13 @@ onMounted(refreshItems) + @@ -90,5 +192,14 @@ onMounted(refreshItems) + + diff --git a/meshmap_frontend/src/version.ts b/meshmap_frontend/src/version.ts index 2b17820..8c81056 100644 --- a/meshmap_frontend/src/version.ts +++ b/meshmap_frontend/src/version.ts @@ -1 +1 @@ -export const FRONTEND_VERSION = '0.2.0' +export const FRONTEND_VERSION = '0.3.0'
+ + 时间 Topic Error
+ + {{ formatTime(item.created_at) }} {{ item.topic || '-' }} {{ item.error || '-' }}