mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 23:16:37 +08:00
refactor(arch): decouple private imports, enforce contracts and comply with cordis architecture
This commit is contained in:
@@ -4,8 +4,34 @@
|
||||
package analytics
|
||||
|
||||
import (
|
||||
risklogstore "Wavelet/plugins/domain/risk_control/logstore"
|
||||
"time"
|
||||
)
|
||||
|
||||
// UserAccessLog is Wavelet risk_control's w_user_access_logs entity.
|
||||
type UserAccessLog = risklogstore.UserAccessLog
|
||||
const (
|
||||
userAccessLogTableName = "w_user_access_logs"
|
||||
userAccessLogInsertColumns = "id, user_id, path, method, ip, user_agent, headers, status, latency, created_at"
|
||||
)
|
||||
|
||||
// UserAccessLog represents a user HTTP access log entry.
|
||||
type UserAccessLog struct {
|
||||
ID uint64 `gorm:"column:id"`
|
||||
UserID uint64 `gorm:"column:user_id"`
|
||||
Path string `gorm:"column:path"`
|
||||
Method string `gorm:"column:method"`
|
||||
IP string `gorm:"column:ip"`
|
||||
UserAgent string `gorm:"column:user_agent"`
|
||||
Headers string `gorm:"column:headers"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
Latency int64 `gorm:"column:latency"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
}
|
||||
|
||||
// TableName returns the table name.
|
||||
func (UserAccessLog) TableName() string {
|
||||
return userAccessLogTableName
|
||||
}
|
||||
|
||||
// InsertColumns returns comma-separated column names for batch insert.
|
||||
func (UserAccessLog) InsertColumns() string {
|
||||
return userAccessLogInsertColumns
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
adminmodel "Wavelet/plugins/domain/admin/model"
|
||||
authmodel "Wavelet/plugins/domain/auth"
|
||||
uploadmodels "Wavelet/plugins/domain/upload/models"
|
||||
usermodel "Wavelet/plugins/domain/user"
|
||||
"time"
|
||||
|
||||
"Wavelet/core/contracts"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -20,57 +19,161 @@ const (
|
||||
maskThreshold = 8
|
||||
)
|
||||
|
||||
// User is the Wavelet w_users entity.
|
||||
type User = usermodel.User
|
||||
// User represents a user identity view.
|
||||
type User struct {
|
||||
ID uint64 `json:"id,string" gorm:"primaryKey"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"-"`
|
||||
Nickname string `json:"nickname"`
|
||||
Email string `json:"email"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
IsActive bool `json:"is_active"`
|
||||
LastLoginAt time.Time `json:"last_login_at"`
|
||||
}
|
||||
|
||||
// AccessToken is the Wavelet w_access_tokens entity.
|
||||
type AccessToken = usermodel.AccessToken
|
||||
func (User) TableName() string {
|
||||
return "w_users"
|
||||
}
|
||||
|
||||
// AuthSource is the Wavelet w_auth_sources entity.
|
||||
type AuthSource = authmodel.AuthSource
|
||||
func (u *User) SetEncryptedPassword(pwd string) error {
|
||||
u.Password = pwd
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExternalAccount is the Wavelet w_external_accounts entity.
|
||||
type ExternalAccount = authmodel.ExternalAccount
|
||||
// AccessToken represents an access token view.
|
||||
type AccessToken struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
UserID uint64 `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
Token string `json:"token"`
|
||||
MaskedToken string `json:"masked_token"`
|
||||
TokenHash string `json:"token_hash"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
ExpiredAt time.Time `json:"expired_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TaskExecution is the Wavelet w_task_executions entity.
|
||||
type TaskExecution = adminmodel.TaskExecution
|
||||
func (AccessToken) TableName() string {
|
||||
return "w_access_tokens"
|
||||
}
|
||||
|
||||
// Template is the Wavelet w_templates entity.
|
||||
type Template = adminmodel.Template
|
||||
// AuthSource represents an authentication source view.
|
||||
type AuthSource struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
IconURL string `json:"icon_url"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
// Schedule is the Wavelet w_schedules entity.
|
||||
type Schedule = adminmodel.Schedule
|
||||
// TaskExecution represents task execution entity.
|
||||
type TaskExecution struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
TaskID string `json:"task_id" gorm:"size:64;index"`
|
||||
TaskType string `json:"task_type" gorm:"size:100;index"`
|
||||
TaskName string `json:"task_name" gorm:"size:255"`
|
||||
Status string `json:"status" gorm:"size:20;index"`
|
||||
Retryable bool `json:"retryable"`
|
||||
MaxRetry int `json:"max_retry"`
|
||||
RetryCount int `json:"retry_count"`
|
||||
Log string `json:"log" gorm:"type:text"`
|
||||
ErrorMessage string `json:"error_message" gorm:"type:text"`
|
||||
Result string `json:"result" gorm:"type:text"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
FinishedAt *time.Time `json:"finished_at"`
|
||||
Duration int64 `json:"duration"`
|
||||
Payload string `json:"payload" gorm:"type:text"`
|
||||
TriggeredBy string `json:"triggered_by" gorm:"size:100"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Upload is the Wavelet w_uploads entity.
|
||||
type Upload = uploadmodels.Upload
|
||||
func (TaskExecution) TableName() string {
|
||||
return "w_task_executions"
|
||||
}
|
||||
|
||||
// UploadMetadata is the Wavelet upload metadata JSON.
|
||||
type UploadMetadata = uploadmodels.UploadMetadata
|
||||
|
||||
// UploadStatus is the Wavelet upload status.
|
||||
type UploadStatus = uploadmodels.UploadStatus
|
||||
|
||||
// UploadStat is the Wavelet w_upload_stats entity.
|
||||
type UploadStat = uploadmodels.UploadStat
|
||||
type UploadStatus = string
|
||||
|
||||
const (
|
||||
// UploadStatusPending is a newly stored unused upload.
|
||||
UploadStatusPending = uploadmodels.UploadStatusPending
|
||||
// UploadStatusUsed is an in-use upload.
|
||||
UploadStatusUsed = uploadmodels.UploadStatusUsed
|
||||
// UploadStatusDeleted is a soft-deleted upload.
|
||||
UploadStatusDeleted = uploadmodels.UploadStatusDeleted
|
||||
|
||||
// UploadStatDimensionTotal is the total stats dimension.
|
||||
UploadStatDimensionTotal = uploadmodels.UploadStatDimensionTotal
|
||||
// UploadStatDimensionType is the type stats dimension.
|
||||
UploadStatDimensionType = uploadmodels.UploadStatDimensionType
|
||||
// UploadStatDimensionCategory is the category stats dimension.
|
||||
UploadStatDimensionCategory = uploadmodels.UploadStatDimensionCategory
|
||||
// UploadStatDimensionTrend is the trend stats dimension.
|
||||
UploadStatDimensionTrend = uploadmodels.UploadStatDimensionTrend
|
||||
UploadStatusPending UploadStatus = "pending"
|
||||
UploadStatusUsed UploadStatus = "used"
|
||||
UploadStatusDeleted UploadStatus = "deleted"
|
||||
)
|
||||
|
||||
// UploadMetadata represents upload metadata JSON.
|
||||
type UploadMetadata = contracts.UploadMetadataDTO
|
||||
|
||||
// Upload represents file upload entity.
|
||||
type Upload struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
UserID uint64 `json:"user_id" gorm:"index"`
|
||||
FileName string `json:"file_name" gorm:"size:255"`
|
||||
FilePath string `json:"file_path" gorm:"size:500"`
|
||||
MimeType string `json:"mime_type" gorm:"size:100"`
|
||||
Size int64 `json:"size"`
|
||||
Hash string `json:"hash" gorm:"size:64"`
|
||||
Status string `json:"status" gorm:"type:varchar(20)"`
|
||||
Type string `json:"type" gorm:"size:50;index"`
|
||||
Metadata contracts.UploadMetadataDTO `json:"metadata"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (Upload) TableName() string {
|
||||
return "w_uploads"
|
||||
}
|
||||
|
||||
func (u *Upload) ToDTO() contracts.UploadDTO {
|
||||
return contracts.UploadDTO{
|
||||
ID: u.ID,
|
||||
UserID: u.UserID,
|
||||
FileName: u.FileName,
|
||||
FilePath: u.FilePath,
|
||||
MimeType: u.MimeType,
|
||||
Size: u.Size,
|
||||
Hash: u.Hash,
|
||||
Status: u.Status,
|
||||
Type: u.Type,
|
||||
Metadata: u.Metadata,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: u.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func FromUploadDTO(d contracts.UploadDTO) Upload {
|
||||
return Upload{
|
||||
ID: d.ID,
|
||||
UserID: d.UserID,
|
||||
FileName: d.FileName,
|
||||
FilePath: d.FilePath,
|
||||
MimeType: d.MimeType,
|
||||
Size: d.Size,
|
||||
Hash: d.Hash,
|
||||
Status: d.Status,
|
||||
Type: d.Type,
|
||||
Metadata: d.Metadata,
|
||||
CreatedAt: d.CreatedAt,
|
||||
UpdatedAt: d.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
const UploadStatDimensionTotal = "total"
|
||||
|
||||
// UploadStat tracks upload statistics by dimension.
|
||||
type UploadStat struct {
|
||||
ID uint64 `gorm:"primaryKey"`
|
||||
Dimension string `gorm:"size:50;not null"`
|
||||
TargetID uint64 `gorm:"not null"`
|
||||
TotalSize int64 `gorm:"not null"`
|
||||
FileCount int `gorm:"not null"`
|
||||
}
|
||||
|
||||
func (UploadStat) TableName() string {
|
||||
return "w_upload_stats"
|
||||
}
|
||||
|
||||
// GenerateTokenString 生成加密安全的随机 Token 值
|
||||
func GenerateTokenString() (string, error) {
|
||||
bytes := make([]byte, tokenByteLength)
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
adminmodel "Wavelet/plugins/domain/admin/model"
|
||||
"time"
|
||||
|
||||
"Wavelet/core/contracts"
|
||||
)
|
||||
|
||||
// 配置键常量 - 所有系统配置的 key 定义
|
||||
@@ -136,10 +138,46 @@ const (
|
||||
|
||||
const (
|
||||
// ConfigVisibilityHidden 表示配置不通过公共配置接口暴露
|
||||
ConfigVisibilityHidden = adminmodel.ConfigVisibilityHidden
|
||||
ConfigVisibilityHidden = 0
|
||||
// ConfigVisibilityVisible 表示配置通过公共配置接口暴露
|
||||
ConfigVisibilityVisible = adminmodel.ConfigVisibilityVisible
|
||||
ConfigVisibilityVisible = 1
|
||||
)
|
||||
|
||||
// SystemConfig is the Wavelet w_system_configs entity.
|
||||
type SystemConfig = adminmodel.SystemConfig
|
||||
// SystemConfig is the system configuration model.
|
||||
type SystemConfig struct {
|
||||
Key string `json:"key" gorm:"primaryKey"`
|
||||
Value string `json:"value"`
|
||||
Type string `json:"type"`
|
||||
Visibility int `json:"visibility"`
|
||||
Description string `json:"description"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (SystemConfig) TableName() string {
|
||||
return "w_system_configs"
|
||||
}
|
||||
|
||||
func (c *SystemConfig) ToDTO() contracts.SystemConfigDTO {
|
||||
return contracts.SystemConfigDTO{
|
||||
Key: c.Key,
|
||||
Value: c.Value,
|
||||
Type: c.Type,
|
||||
Visibility: c.Visibility,
|
||||
Description: c.Description,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
CreatedAt: c.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func FromSystemConfigDTO(d contracts.SystemConfigDTO) SystemConfig {
|
||||
return SystemConfig{
|
||||
Key: d.Key,
|
||||
Value: d.Value,
|
||||
Type: d.Type,
|
||||
Visibility: d.Visibility,
|
||||
Description: d.Description,
|
||||
UpdatedAt: d.UpdatedAt,
|
||||
CreatedAt: d.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user