宇恒一号官网

This commit is contained in:
whm
2026-03-17 00:59:32 +08:00
commit eb56519df7
105 changed files with 10783 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package models
import "go.mongodb.org/mongo-driver/v2/bson"
type Conversation struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
Title string `bson:"title" json:"title"`
UserID string `bson:"user_id" json:"user_id"`
WorkspaceID string `bson:"workspace_id" json:"workspace_id"`
CreatedAt string `bson:"created_at" json:"created_at"`
UpdatedAt string `bson:"updated_at" json:"updated_at"`
}

24
server/models/payment.go Normal file
View File

@@ -0,0 +1,24 @@
package models
// WechatPayConfig 微信支付配置
type WechatPayConfig struct {
AppID string `bson:"app_id" json:"app_id"`
MchID string `bson:"mch_id" json:"mch_id"`
APIKey string `bson:"api_key" json:"api_key"`
APIKeyV3 string `bson:"api_key_v3" json:"api_key_v3"`
Enabled bool `bson:"enabled" json:"enabled"`
}
// AlipayConfig 支付宝配置
type AlipayConfig struct {
AppID string `bson:"app_id" json:"app_id"`
PrivateKey string `bson:"private_key" json:"private_key"`
AlipayPublicKey string `bson:"alipay_public_key" json:"alipay_public_key"`
Enabled bool `bson:"enabled" json:"enabled"`
}
// PaymentConfig 支付配置(微信+支付宝)
type PaymentConfig struct {
Wechat *WechatPayConfig `bson:"wechat,omitempty" json:"wechat,omitempty"`
Alipay *AlipayConfig `bson:"alipay,omitempty" json:"alipay,omitempty"`
}

View File

@@ -0,0 +1,38 @@
package models
// 权限码(与前端、路由 meta.permission 一致)
const (
PermSiteManage = "site:manage"
PermHomepageEdit = "homepage:edit"
PermPageManage = "page:manage"
PermModuleUpload = "module:upload"
PermUserManage = "user:manage"
PermWorkspaceManage = "workspace:manage"
PermConversationManage = "conversation:manage"
PermSMSConfig = "sms_config"
PermPaymentConfig = "payment_config"
PermRolePermission = "role:permission" // 角色权限管理
)
// AllPermissions 所有可配置权限(用于角色权限管理页)
var AllPermissions = []struct {
Key string
Name string
}{
{PermSiteManage, "站点管理"},
{PermHomepageEdit, "首页编辑"},
{PermPageManage, "网页管理"},
{PermModuleUpload, "功能模块上传"},
{PermUserManage, "用户管理"},
{PermWorkspaceManage, "工作空间"},
{PermConversationManage, "对话管理"},
{PermSMSConfig, "短信配置"},
{PermPaymentConfig, "支付配置"},
{PermRolePermission, "角色权限管理"},
}
// RolePermissionsDoc MongoDB 文档:角色 ID -> 权限列表
type RolePermissionsDoc struct {
RoleID int `bson:"role_id" json:"role_id"`
Permissions []string `bson:"permissions" json:"permissions"`
}

66
server/models/site.go Normal file
View File

@@ -0,0 +1,66 @@
package models
import "go.mongodb.org/mongo-driver/v2/bson"
// Site 站点
type Site struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
Name string `bson:"name" json:"name"`
Domain string `bson:"domain" json:"domain"`
Description string `bson:"description,omitempty" json:"description,omitempty"`
CreatedAt string `bson:"created_at" json:"created_at"`
}
// Page 网页(属于某站点)
type Page struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
SiteID string `bson:"site_id" json:"site_id"`
Slug string `bson:"slug" json:"slug"` // index, about, ...
Title string `bson:"title" json:"title"`
Type string `bson:"type" json:"type"` // homepage, page
Content string `bson:"content" json:"content"` // HTML 或 JSON 字符串
UpdatedAt string `bson:"updated_at" json:"updated_at"`
}
// HomepageData 首页可编辑数据(与 yuheng-download-space 对应)
type HomepageData struct {
LogoText string `json:"logo_text"` // YUHENG ONE
NavLinks []NavLink `json:"nav_links"` // MISSION, DOWNLOAD, CONTACT
Title string `json:"title"` // 宇恒一号
Subtitle string `json:"subtitle"` // INTERSTELLAR EXPLORER EDITION
Description string `json:"description"` // 跨越星际的智能伙伴...
DownloadText string `json:"download_text"` // START EXPLORING
DownloadURL string `json:"download_url"` // #
Platforms []PlatformItem `json:"platforms"` // Windows, macOS, ...
Version string `json:"version"` // VERSION 3.2.1
LaunchYear string `json:"launch_year"` // LAUNCH: 2024
BadgeText string `json:"badge_text"` // FREE ACCESS
Features []FeatureItem `json:"features"` // 星际导航等
FooterText string `json:"footer_text"` // © 2024 YUHENG ONE
}
type NavLink struct {
Label string `json:"label"`
URL string `json:"url"`
}
type PlatformItem struct {
Name string `json:"name"` // WINDOWS, MACOS, ...
URL string `json:"url"`
}
type FeatureItem struct {
Title string `json:"title"`
Desc string `json:"desc"`
}
// SiteAsset 站点功能模块/上传文件
type SiteAsset struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
SiteID string `bson:"site_id" json:"site_id"`
Name string `bson:"name" json:"name"`
FilePath string `bson:"file_path" json:"file_path"` // 相对路径
Size int64 `bson:"size" json:"size"`
ContentType string `bson:"content_type" json:"content_type"`
CreatedAt string `bson:"created_at" json:"created_at"`
}

11
server/models/sms.go Normal file
View File

@@ -0,0 +1,11 @@
package models
// SMSConfig 短信平台配置(仅超级用户 role_id=0, role=admin 可配置)
type SMSConfig struct {
Provider string `bson:"provider" json:"provider"` // 服务商aliyun/tencent/...
AccessKey string `bson:"access_key" json:"access_key"` // AccessKey
SecretKey string `bson:"secret_key" json:"secret_key"` // SecretKey
SignName string `bson:"sign_name" json:"sign_name"` // 签名
TemplateID string `bson:"template_id" json:"template_id"` // 模板ID
Enabled bool `bson:"enabled" json:"enabled"` // 是否已启用
}

77
server/models/user.go Normal file
View File

@@ -0,0 +1,77 @@
package models
import (
"fmt"
"time"
"go.mongodb.org/mongo-driver/v2/bson"
)
const (
RoleIDSuperAdmin = 9527 // 超级管理员(后台登录)
RoleIDSuperUser = 0 // 超级用户role_id=0 且 role=admin可配置短信平台
RoleIDUser = 1 // 普通用户
)
// FlexDate 可解码 BSON DateTime 或 string统一以 string 输出(兼容库中既有日期类型又有字符串的情况)
type FlexDate string
func (d *FlexDate) UnmarshalBSONValue(typ byte, data []byte) error {
rv := bson.RawValue{Type: bson.Type(typ), Value: data}
switch bson.Type(typ) {
case bson.TypeDateTime:
if dt, ok := rv.DateTimeOK(); ok {
*d = FlexDate(time.UnixMilli(dt).Format("2006-01-02"))
}
return nil
case bson.TypeString:
if s, ok := rv.StringValueOK(); ok {
*d = FlexDate(s)
}
return nil
case bson.TypeNull, bson.TypeUndefined:
*d = ""
return nil
default:
return fmt.Errorf("FlexDate: cannot decode type %v", typ)
}
}
type User struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
Username string `bson:"username" json:"username"`
Mobile string `bson:"mobile,omitempty" json:"mobile,omitempty"`
Email string `bson:"email" json:"email"`
Password string `bson:"password" json:"-"` // 不返回给前端
Role string `bson:"role" json:"role"`
RoleID int `bson:"role_id,omitempty" json:"role_id"` // 9527=超级管理员 1=普通用户
IsBeta bool `bson:"is_beta,omitempty" json:"is_beta"`
TrialStartDate FlexDate `bson:"trial_start_date,omitempty" json:"trial_start_date,omitempty"`
TrialEndDate FlexDate `bson:"trial_end_date,omitempty" json:"trial_end_date,omitempty"`
LastLogin string `bson:"lastLogin,omitempty" json:"last_login,omitempty"`
LLM string `bson:"llm,omitempty" json:"llm,omitempty"`
}
type UserCreateInput struct {
Username string `json:"username" binding:"required"`
Email string `json:"email" binding:"required"`
Password string `json:"password" binding:"required"`
Role string `json:"role"`
RoleID int `json:"role_id"` // 9527=超级管理员 1=普通用户
IsBeta bool `json:"is_beta"`
TrialStartDate string `json:"trial_start_date"`
TrialEndDate string `json:"trial_end_date"`
LLM string `json:"llm"`
}
type UserUpdateInput struct {
Username *string `json:"username"`
Email *string `json:"email"`
Password *string `json:"password"` // 若提供则更新
Role *string `json:"role"`
RoleID *int `json:"role_id"`
IsBeta *bool `json:"is_beta"`
TrialStartDate *string `json:"trial_start_date"`
TrialEndDate *string `json:"trial_end_date"`
LLM *string `json:"llm"`
}

View File

@@ -0,0 +1,10 @@
package models
import "go.mongodb.org/mongo-driver/v2/bson"
type Workspace struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
Name string `bson:"name" json:"name"`
UserID string `bson:"user_id" json:"user_id"`
CreatedAt string `bson:"created_at" json:"created_at"`
}