Files
new-api/controller/model_meta.go

331 lines
8.0 KiB
Go
Raw Permalink Normal View History

🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
package controller
import (
2025-08-10 12:11:31 +08:00
"encoding/json"
"sort"
2025-08-10 12:11:31 +08:00
"strconv"
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
"strings"
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
2025-08-10 12:11:31 +08:00
"one-api/common"
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
"one-api/constant"
2025-08-10 12:11:31 +08:00
"one-api/model"
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
2025-08-10 12:11:31 +08:00
"github.com/gin-gonic/gin"
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
)
// GetAllModelsMeta 获取模型列表(分页)
func GetAllModelsMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
pageInfo := common.GetPageQuery(c)
modelsMeta, err := model.GetAllModels(pageInfo.GetStartIdx(), pageInfo.GetPageSize())
if err != nil {
common.ApiError(c, err)
return
}
// 批量填充附加字段,提升列表接口性能
enrichModels(modelsMeta)
2025-08-10 12:11:31 +08:00
var total int64
model.DB.Model(&model.Model{}).Count(&total)
// 统计供应商计数(全部数据,不受分页影响)
vendorCounts, _ := model.GetVendorModelCounts()
pageInfo.SetTotal(int(total))
pageInfo.SetItems(modelsMeta)
common.ApiSuccess(c, gin.H{
"items": modelsMeta,
"total": total,
"page": pageInfo.GetPage(),
"page_size": pageInfo.GetPageSize(),
"vendor_counts": vendorCounts,
})
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// SearchModelsMeta 搜索模型列表
func SearchModelsMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
keyword := c.Query("keyword")
vendor := c.Query("vendor")
pageInfo := common.GetPageQuery(c)
modelsMeta, total, err := model.SearchModels(keyword, vendor, pageInfo.GetStartIdx(), pageInfo.GetPageSize())
if err != nil {
common.ApiError(c, err)
return
}
// 批量填充附加字段,提升列表接口性能
enrichModels(modelsMeta)
2025-08-10 12:11:31 +08:00
pageInfo.SetTotal(int(total))
pageInfo.SetItems(modelsMeta)
common.ApiSuccess(c, pageInfo)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// GetModelMeta 根据 ID 获取单条模型信息
func GetModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
common.ApiError(c, err)
return
}
var m model.Model
if err := model.DB.First(&m, id).Error; err != nil {
common.ApiError(c, err)
return
}
enrichModels([]*model.Model{&m})
2025-08-10 12:11:31 +08:00
common.ApiSuccess(c, &m)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// CreateModelMeta 新建模型
func CreateModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
var m model.Model
if err := c.ShouldBindJSON(&m); err != nil {
common.ApiError(c, err)
return
}
if m.ModelName == "" {
common.ApiErrorMsg(c, "模型名称不能为空")
return
}
// 名称冲突检查
if dup, err := model.IsModelNameDuplicated(0, m.ModelName); err != nil {
common.ApiError(c, err)
return
} else if dup {
common.ApiErrorMsg(c, "模型名称已存在")
return
}
if err := m.Insert(); err != nil {
common.ApiError(c, err)
return
}
model.RefreshPricing()
common.ApiSuccess(c, &m)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// UpdateModelMeta 更新模型
func UpdateModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
statusOnly := c.Query("status_only") == "true"
var m model.Model
if err := c.ShouldBindJSON(&m); err != nil {
common.ApiError(c, err)
return
}
if m.Id == 0 {
common.ApiErrorMsg(c, "缺少模型 ID")
return
}
if statusOnly {
// 只更新状态,防止误清空其他字段
if err := model.DB.Model(&model.Model{}).Where("id = ?", m.Id).Update("status", m.Status).Error; err != nil {
common.ApiError(c, err)
return
}
} else {
// 名称冲突检查
if dup, err := model.IsModelNameDuplicated(m.Id, m.ModelName); err != nil {
common.ApiError(c, err)
return
} else if dup {
common.ApiErrorMsg(c, "模型名称已存在")
return
}
if err := m.Update(); err != nil {
common.ApiError(c, err)
return
}
}
model.RefreshPricing()
common.ApiSuccess(c, &m)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// DeleteModelMeta 删除模型
func DeleteModelMeta(c *gin.Context) {
2025-08-10 12:11:31 +08:00
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
common.ApiError(c, err)
return
}
if err := model.DB.Delete(&model.Model{}, id).Error; err != nil {
common.ApiError(c, err)
return
}
model.RefreshPricing()
common.ApiSuccess(c, nil)
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}
// enrichModels 批量填充附加信息:端点、渠道、分组、计费类型,避免 N+1 查询
func enrichModels(models []*model.Model) {
if len(models) == 0 {
return
}
// 1) 拆分精确与规则匹配
exactNames := make([]string, 0)
exactIdx := make(map[string][]int) // modelName -> indices in models
ruleIndices := make([]int, 0)
for i, m := range models {
if m == nil {
continue
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
}
if m.NameRule == model.NameRuleExact {
exactNames = append(exactNames, m.ModelName)
exactIdx[m.ModelName] = append(exactIdx[m.ModelName], i)
} else {
ruleIndices = append(ruleIndices, i)
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
}
}
// 2) 批量查询精确模型的绑定渠道
channelsByModel, _ := model.GetBoundChannelsByModelsMap(exactNames)
// 3) 精确模型:端点从缓存、渠道批量映射、分组/计费类型从缓存
for name, indices := range exactIdx {
chs := channelsByModel[name]
for _, idx := range indices {
mm := models[idx]
if mm.Endpoints == "" {
eps := model.GetModelSupportEndpointTypes(mm.ModelName)
if b, err := json.Marshal(eps); err == nil {
mm.Endpoints = string(b)
}
}
mm.BoundChannels = chs
mm.EnableGroups = model.GetModelEnableGroups(mm.ModelName)
mm.QuotaTypes = model.GetModelQuotaTypes(mm.ModelName)
}
}
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
if len(ruleIndices) == 0 {
return
}
// 4) 一次性读取定价缓存,内存匹配所有规则模型
pricings := model.GetPricing()
// 为全部规则模型收集匹配名集合、端点并集、分组并集、配额集合
matchedNamesByIdx := make(map[int][]string)
endpointSetByIdx := make(map[int]map[constant.EndpointType]struct{})
groupSetByIdx := make(map[int]map[string]struct{})
quotaSetByIdx := make(map[int]map[int]struct{})
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
for _, p := range pricings {
for _, idx := range ruleIndices {
mm := models[idx]
var matched bool
switch mm.NameRule {
case model.NameRulePrefix:
matched = strings.HasPrefix(p.ModelName, mm.ModelName)
case model.NameRuleSuffix:
matched = strings.HasSuffix(p.ModelName, mm.ModelName)
case model.NameRuleContains:
matched = strings.Contains(p.ModelName, mm.ModelName)
}
if !matched {
continue
}
matchedNamesByIdx[idx] = append(matchedNamesByIdx[idx], p.ModelName)
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
es := endpointSetByIdx[idx]
if es == nil {
es = make(map[constant.EndpointType]struct{})
endpointSetByIdx[idx] = es
}
for _, et := range p.SupportedEndpointTypes {
es[et] = struct{}{}
}
gs := groupSetByIdx[idx]
if gs == nil {
gs = make(map[string]struct{})
groupSetByIdx[idx] = gs
}
for _, g := range p.EnableGroup {
gs[g] = struct{}{}
}
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
qs := quotaSetByIdx[idx]
if qs == nil {
qs = make(map[int]struct{})
quotaSetByIdx[idx] = qs
}
qs[p.QuotaType] = struct{}{}
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
}
}
// 5) 汇总所有匹配到的模型名称,批量查询一次渠道
allMatchedSet := make(map[string]struct{})
for _, names := range matchedNamesByIdx {
for _, n := range names {
allMatchedSet[n] = struct{}{}
2025-08-10 12:11:31 +08:00
}
}
allMatched := make([]string, 0, len(allMatchedSet))
for n := range allMatchedSet {
allMatched = append(allMatched, n)
}
matchedChannelsByModel, _ := model.GetBoundChannelsByModelsMap(allMatched)
// 6) 回填每个规则模型的并集信息
for _, idx := range ruleIndices {
mm := models[idx]
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
// 端点并集 -> 序列化
if es, ok := endpointSetByIdx[idx]; ok && mm.Endpoints == "" {
eps := make([]constant.EndpointType, 0, len(es))
for et := range es {
eps = append(eps, et)
}
if b, err := json.Marshal(eps); err == nil {
mm.Endpoints = string(b)
}
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
}
// 分组并集
if gs, ok := groupSetByIdx[idx]; ok {
groups := make([]string, 0, len(gs))
for g := range gs {
groups = append(groups, g)
}
mm.EnableGroups = groups
✨ feat: enhance model billing aggregation & UI display for unknown quota type Summary ------- 1. **Backend** • `controller/model_meta.go` – For prefix/suffix/contains rules, aggregate endpoints, bound channels, enable groups, and quota types across all matched models. – When mixed billing types are detected, return `quota_type = -1` (unknown) instead of defaulting to volume-based. 2. **Frontend** • `web/src/helpers/utils.js` – `calculateModelPrice` now handles `quota_type = -1`, returning placeholder `'-'`. • `web/src/components/table/model-pricing/view/card/PricingCardView.jsx` – Billing tag logic updated: displays “按次计费” (times), “按量计费” (volume), or `'-'` for unknown. • `web/src/components/table/model-pricing/view/table/PricingTableColumns.js` – `renderQuotaType` shows “未知” for unknown billing type. • `web/src/components/table/models/ModelsColumnDefs.js` – Unified `renderQuotaType` to return `'-'` when type is unknown. • `web/src/components/table/model-pricing/modal/components/ModelPricingTable.jsx` – Group price table honors unknown billing type; pricing columns show `'-'` and neutral tag color. 3. **Utilities** • Added safe fallback colours/tags for unknown billing type across affected components. Impact ------ • Ensures correct data aggregation for non-exact model matches. • Prevents UI from implying volume billing when actual type is ambiguous. • Provides consistent placeholder display (`'-'` or “未知”) across cards, tables and modals. No breaking API changes; frontend gracefully handles legacy values.
2025-08-10 21:09:49 +08:00
}
// 配额类型集合(保持去重并排序)
if qs, ok := quotaSetByIdx[idx]; ok {
arr := make([]int, 0, len(qs))
for k := range qs {
arr = append(arr, k)
}
sort.Ints(arr)
mm.QuotaTypes = arr
}
// 渠道并集
names := matchedNamesByIdx[idx]
channelSet := make(map[string]model.BoundChannel)
for _, n := range names {
for _, ch := range matchedChannelsByModel[n] {
key := ch.Name + "_" + strconv.Itoa(ch.Type)
channelSet[key] = ch
}
}
if len(channelSet) > 0 {
chs := make([]model.BoundChannel, 0, len(channelSet))
for _, ch := range channelSet {
chs = append(chs, ch)
}
mm.BoundChannels = chs
}
// 匹配信息
mm.MatchedModels = names
mm.MatchedCount = len(names)
}
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements Backend • Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps • Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go` • Auto-migrate new tables in DB startup logic Frontend • Build complete “Model Management” module under `/console/models` - New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs - Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile` • Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature • Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes Table UX improvements • Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style) • Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags • Color all tags deterministically using `stringToColor` for consistent theming • Change vendor column tag color to white for better contrast Misc • Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
}