feat(*): 创作工作台 - 完善媒体上传预览与连线交互并修复任务章节及日志筛选

This commit is contained in:
ddCat
2026-09-08 17:26:34 +08:00
parent 95b004ec0f
commit 068a8daea6
56 changed files with 3316 additions and 274 deletions

View File

@@ -21,11 +21,12 @@ type AnalyticsFilter struct {
type APICallLogFilter struct {
AnalyticsFilter
Keyword string
Status string
IDs []string
Page int
Limit int
RecordType string
Keyword string
Status string
IDs []string
Page int
Limit int
}
func (r *Repository) RecordUserActivity(userID string, event string, count int, now time.Time) error {
@@ -137,7 +138,14 @@ func (r *Repository) ExportAPICallLogs(filter APICallLogFilter, limit int) ([]mo
}
func (r *Repository) filteredAPICallLogQuery(filter APICallLogFilter) *gorm.DB {
query := visibleAPICallLogQuery(r.apiCallLogQuery(filter.AnalyticsFilter))
query := r.apiCallLogQuery(filter.AnalyticsFilter)
switch filter.RecordType {
case "download":
query = query.Where("api_call_logs.request_kind = ?", "download")
case "all":
default:
query = visibleAPICallLogQuery(query).Where("COALESCE(api_call_logs.request_kind, '') <> ?", "download")
}
if value := strings.TrimSpace(filter.Keyword); value != "" {
pattern := "%" + strings.ToLower(value) + "%"
query = query.

View File

@@ -18,6 +18,45 @@ type sqlCaptureLogger struct {
statements []string
}
func TestAPICallLogRecordTypeFiltersListAndExport(t *testing.T) {
db, err := gorm.Open(sqlite.Open("file:api-log-record-types?mode=memory&cache=shared"), &gorm.Config{})
if err != nil {
t.Fatal(err)
}
if err := db.AutoMigrate(&model.ApiCallLog{}); err != nil {
t.Fatal(err)
}
now := time.Now()
for _, item := range []model.ApiCallLog{
{ID: "request", Capability: "video", RequestKind: "create", CreatedAt: now},
{ID: "poll", Capability: "video", RequestKind: "poll", CreatedAt: now},
{ID: "video-download", Capability: "video", RequestKind: "download", CreatedAt: now},
{ID: "image-download", Capability: "image", RequestKind: "download", CreatedAt: now},
} {
if err := db.Create(&item).Error; err != nil {
t.Fatal(err)
}
}
repo := New(db)
for _, tc := range []struct {
kind string
count int
}{{"", 1}, {"request", 1}, {"download", 2}, {"all", 4}} {
filter := APICallLogFilter{AnalyticsFilter: AnalyticsFilter{From: now.Add(-time.Hour), To: now.Add(time.Hour)}, RecordType: tc.kind}
logs, total, err := repo.QueryAPICallLogs(filter)
if err != nil {
t.Fatal(err)
}
if len(logs) != tc.count || total != int64(tc.count) {
t.Fatalf("kind=%s: count=%d total=%d", tc.kind, len(logs), total)
}
exported, err := repo.ExportAPICallLogs(filter, 100)
if err != nil || len(exported) != tc.count {
t.Fatalf("kind=%s: export count=%d err=%v", tc.kind, len(exported), err)
}
}
}
func (l *sqlCaptureLogger) LogMode(logger.LogLevel) logger.Interface { return l }
func (*sqlCaptureLogger) Info(context.Context, string, ...any) {}
func (*sqlCaptureLogger) Warn(context.Context, string, ...any) {}