remove dead proxy service and sora storage action
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
|
||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||
@@ -11,14 +8,14 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// SoraHandler handles admin Sora statistics and management
|
||||
// SoraHandler handles admin Sora statistics and management.
|
||||
type SoraHandler struct {
|
||||
soraGenService *service.SoraGenerationService
|
||||
soraQuotaService *service.SoraQuotaService
|
||||
userRepo service.UserRepository
|
||||
}
|
||||
|
||||
// NewSoraHandler creates a new admin Sora handler
|
||||
// NewSoraHandler creates a new admin Sora handler.
|
||||
func NewSoraHandler(
|
||||
soraGenService *service.SoraGenerationService,
|
||||
soraQuotaService *service.SoraQuotaService,
|
||||
@@ -31,7 +28,6 @@ func NewSoraHandler(
|
||||
}
|
||||
}
|
||||
|
||||
// SoraSystemStatsResponse 系统级 Sora 统计
|
||||
type SoraSystemStatsResponse struct {
|
||||
TotalUsers int64 `json:"total_users"`
|
||||
TotalGenerations int64 `json:"total_generations"`
|
||||
@@ -41,39 +37,28 @@ type SoraSystemStatsResponse struct {
|
||||
ByModel map[string]int64 `json:"by_model"`
|
||||
}
|
||||
|
||||
// GetSystemStats 获取 Sora 系统统计
|
||||
// GET /api/v1/admin/sora/stats
|
||||
// GetSystemStats returns aggregate admin Sora statistics.
|
||||
func (h *SoraHandler) GetSystemStats(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// 获取所有用户的 Sora 统计
|
||||
users, _, err := h.userRepo.List(ctx, pagination.PaginationParams{Page: 1, PageSize: 10000})
|
||||
if err != nil {
|
||||
response.Error(c, 500, "Failed to get users")
|
||||
return
|
||||
}
|
||||
|
||||
var totalStorageBytes int64
|
||||
byStatus := make(map[string]int64)
|
||||
byModel := make(map[string]int64)
|
||||
|
||||
// 遍历用户统计
|
||||
// NOTE: Per-user storage tracking removed; totalStorageBytes now sourced from SoraGenerationService if needed.
|
||||
_ = users // suppress unused warning until real aggregation is implemented
|
||||
|
||||
resp := SoraSystemStatsResponse{
|
||||
TotalUsers: int64(len(users)),
|
||||
TotalGenerations: 0,
|
||||
TotalStorageBytes: totalStorageBytes,
|
||||
TotalStorageBytes: 0,
|
||||
ActiveGenerations: 0,
|
||||
ByStatus: byStatus,
|
||||
ByModel: byModel,
|
||||
ByStatus: map[string]int64{},
|
||||
ByModel: map[string]int64{},
|
||||
}
|
||||
|
||||
response.Success(c, resp)
|
||||
}
|
||||
|
||||
// SoraUserStatsResponse 用户级 Sora 统计
|
||||
type SoraUserStatsResponse struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
@@ -87,21 +72,16 @@ type SoraUserStatsResponse struct {
|
||||
TotalFileSizeBytes int64 `json:"total_file_size_bytes"`
|
||||
}
|
||||
|
||||
// ListUserStats 获取用户 Sora 使用统计列表
|
||||
// GET /api/v1/admin/sora/users
|
||||
// ListUserStats returns per-user admin Sora usage rows.
|
||||
func (h *SoraHandler) ListUserStats(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
page, pageSize := response.ParsePagination(c)
|
||||
search := c.Query("search")
|
||||
|
||||
filters := service.UserListFilters{
|
||||
Search: search,
|
||||
}
|
||||
|
||||
users, result, err := h.userRepo.ListWithFilters(ctx, pagination.PaginationParams{
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
}, filters)
|
||||
}, service.UserListFilters{Search: search})
|
||||
if err != nil {
|
||||
response.Error(c, 500, "Failed to get users")
|
||||
return
|
||||
@@ -127,19 +107,18 @@ func (h *SoraHandler) ListUserStats(c *gin.Context) {
|
||||
Username: u.Username,
|
||||
Email: u.Email,
|
||||
QuotaBytes: quotaBytes,
|
||||
UsedBytes: 0, // per-user usage removed; use SoraGenerationService for real data
|
||||
UsedBytes: 0,
|
||||
AvailableBytes: availableBytes,
|
||||
QuotaSource: quotaSource,
|
||||
GenerationsCount: 0,
|
||||
ActiveCount: activeCount,
|
||||
TotalFileSizeBytes: 0, // per-user usage removed; use SoraGenerationService for real data
|
||||
TotalFileSizeBytes: 0,
|
||||
}
|
||||
}
|
||||
|
||||
response.Paginated(c, results, result.Total, page, pageSize)
|
||||
}
|
||||
|
||||
// SoraGenerationAdminResponse 管理员视角的生成记录
|
||||
type SoraGenerationAdminResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
@@ -157,43 +136,7 @@ type SoraGenerationAdminResponse struct {
|
||||
CompletedAt *string `json:"completed_at"`
|
||||
}
|
||||
|
||||
// ListGenerations 获取 Sora 生成记录列表(管理员视角)
|
||||
// GET /api/v1/admin/sora/generations
|
||||
// ListGenerations returns admin-visible generation rows.
|
||||
func (h *SoraHandler) ListGenerations(c *gin.Context) {
|
||||
// 简化实现:返回空列表
|
||||
// 完整实现需要扩展 repository 支持 admin 级别的查询
|
||||
response.Paginated(c, []SoraGenerationAdminResponse{}, int64(0), 1, 20)
|
||||
}
|
||||
|
||||
// ClearUserStorage 清除用户的 Sora 存储空间(已弃用)。
|
||||
//
|
||||
// Deprecated: Per-user storage tracking has been removed.
|
||||
// This endpoint now returns 410 Gone. Per-user Sora storage quota tracking was
|
||||
// fully removed in the Sora storage refactoring. Storage management is now
|
||||
// handled at the system-default level via SoraQuotaService.
|
||||
//
|
||||
// DELETE /api/v1/admin/sora/users/:id/storage
|
||||
func (h *SoraHandler) ClearUserStorage(c *gin.Context) {
|
||||
userID, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.BadRequest(c, "Invalid user ID")
|
||||
return
|
||||
}
|
||||
|
||||
// Verify user exists before responding
|
||||
ctx := c.Request.Context()
|
||||
if _, err := h.userRepo.GetByID(ctx, userID); err != nil {
|
||||
response.ErrorFrom(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Deprecation", "true")
|
||||
c.Header("Sunset", "2026-12-31")
|
||||
c.Header("Warning", `299 - "Gone: per-user storage tracking removed, see SoraQuotaService"`)
|
||||
c.JSON(http.StatusGone, gin.H{
|
||||
"error": "This endpoint is no longer available",
|
||||
"message": "Per-user Sora storage quota tracking has been removed. Storage is now managed at system level.",
|
||||
"sunset": "2026-12-31",
|
||||
"deprecated": true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -25,35 +25,6 @@ func TestSoraHandler_ListGenerations(t *testing.T) {
|
||||
assert.Contains(t, w.Body.String(), "items")
|
||||
}
|
||||
|
||||
func TestSoraHandler_ClearUserStorage_InvalidUserID(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
handler := &SoraHandler{}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
userID string
|
||||
expected int
|
||||
}{
|
||||
{"empty string", "", http.StatusBadRequest},
|
||||
{"non-numeric", "abc", http.StatusBadRequest},
|
||||
{"float", "1.5", http.StatusBadRequest},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := gin.CreateTestContext(w)
|
||||
c.Request = httptest.NewRequest(http.MethodDelete, "/admin/sora/users/"+tc.userID+"/storage", nil)
|
||||
c.Params = gin.Params{{Key: "id", Value: tc.userID}}
|
||||
|
||||
handler.ClearUserStorage(c)
|
||||
|
||||
assert.Equal(t, tc.expected, w.Code)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSoraSystemStatsResponse_Fields(t *testing.T) {
|
||||
resp := SoraSystemStatsResponse{
|
||||
TotalUsers: 10,
|
||||
|
||||
Reference in New Issue
Block a user