models

package
v1.1.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventOffline = "Offline"
	EventOnline  = "Online"
	EventExpire  = "Expire"
	EventRenew   = "Renew"
	EventLogin   = "Login"
	EventAlert   = "Alert"
	EventTraffic = "Traffic"
)

Message event names carried by EventMessage.Event.

View Source
const (
	ThemeConfigurationManaged  = "managed"
	ThemeConfigurationRaw      = "raw"
	ThemeConfigurationRedirect = "redirect"
)

Variables

This section is empty.

Functions

func IsLocalizedText

func IsLocalizedText(value any) bool

IsLocalizedText reports whether a manifest text field has a usable value.

Types

type Client

type Client struct {
	UUID             string     `json:"uuid,omitempty" gorm:"type:varchar(36);primaryKey"`
	Token            string     `json:"token,omitempty" gorm:"type:varchar(255);unique;not null"`
	Name             string     `json:"name" gorm:"type:varchar(100)"`
	CPUName          string     `json:"cpu_name" gorm:"type:varchar(100)"`
	Virtualization   string     `json:"virtualization" gorm:"type:varchar(50)"`
	Arch             string     `json:"arch" gorm:"type:varchar(50)"`
	CPUCores         int        `json:"cpu_cores" gorm:"type:int"`
	CPUPhysicalCores int        `json:"cpu_physical_cores" gorm:"type:int"`
	OS               string     `json:"os" gorm:"type:varchar(100)"`
	KernelVersion    string     `json:"kernel_version" gorm:"type:varchar(100)"`
	GPUName          string     `json:"gpu_name" gorm:"type:varchar(100)"`
	IPv4             string     `json:"ipv4,omitempty" gorm:"type:varchar(100)"`
	IPv6             string     `json:"ipv6,omitempty" gorm:"type:varchar(100)"`
	Region           string     `json:"region" gorm:"type:varchar(100)"`
	Remark           string     `json:"remark,omitempty" gorm:"type:longtext"`
	PublicRemark     string     `json:"public_remark,omitempty" gorm:"type:longtext"`
	MemTotal         int64      `json:"mem_total" gorm:"type:bigint"`
	SwapTotal        int64      `json:"swap_total" gorm:"type:bigint"`
	DiskTotal        int64      `json:"disk_total" gorm:"type:bigint"`
	Version          string     `json:"version,omitempty" gorm:"type:varchar(100)"`
	Weight           int        `json:"weight" gorm:"type:int"`
	Price            float64    `json:"price"`
	BillingCycle     int        `json:"billing_cycle"`
	AutoRenewal      bool       `json:"auto_renewal" gorm:"default:false"` // 是否自动续费
	Currency         string     `json:"currency" gorm:"type:varchar(20);default:'$'"`
	ExpiredAt        *time.Time `json:"expired_at" gorm:"type:timestamp"`
	Group            string     `json:"group" gorm:"type:varchar(100)"`
	Tags             string     `json:"tags" gorm:"type:text"` // split by ';'
	Hidden           bool       `json:"hidden" gorm:"default:false"`
	TrafficLimit     int64      `json:"traffic_limit" gorm:"type:bigint"`
	TrafficLimitType string     `json:"traffic_limit_type" gorm:"type:varchar(10);default:'max'"` // 流量阈值类型:sum max min up down
	CreatedAt        time.Time  `json:"created_at"`
	UpdatedAt        time.Time  `json:"updated_at"`
}

Client represents a registered client device

type Configuration

type Configuration struct {
	Type string `json:"type"` // managed raw redirect
	Icon string `json:"icon"` // 图标
	Name any    `json:"name"`
	Data any    `json:"data"` // 配置数据
}

type EventMessage

type EventMessage struct {
	Event   any       `json:"event"`
	Clients []Client  `json:"clients"`
	Time    time.Time `json:"time"`
	Message any       `json:"message"`
	Emoji   any       `json:"emoji"`
}

type GPURecord

type GPURecord struct {
	Client      string    `json:"client" gorm:"type:varchar(36);index"` // 客户端UUID
	Time        time.Time `json:"time" gorm:"index"`                    // 记录时间
	DeviceIndex int       `json:"device_index" gorm:"index"`            // GPU设备索引 (0,1,2...)
	DeviceName  string    `json:"device_name" gorm:"type:varchar(100)"` // GPU型号
	MemTotal    int64     `json:"mem_total" gorm:"type:bigint"`         // 显存总量(字节)
	MemUsed     int64     `json:"mem_used" gorm:"type:bigint"`          // 显存使用(字节)
	Utilization float32   `json:"utilization" gorm:"type:decimal(5,2)"` // GPU使用率(%)
	Temperature int       `json:"temperature"`                          // GPU温度(°C)
}

GPURecord logs individual GPU metrics over time

type LoadNotification

type LoadNotification struct {
	ID           uint        `json:"id,omitempty" gorm:"primaryKey;autoIncrement"`
	Name         string      `json:"name" gorm:"type:varchar(255)"`
	Clients      StringArray `json:"clients" gorm:"type:longtext"`
	Metric       string      `json:"metric" gorm:"type:varchar(50);not null;default:'cpu'"`     // 监控指标,如 cpu, ram, load
	Threshold    float32     `json:"threshold" gorm:"type:decimal(5,2);not null;default:80.00"` // 阈值百分比
	Ratio        float32     `json:"ratio" gorm:"type:decimal(5,2);not null;default:0.80"`      // 达标时间比
	Interval     int         `json:"interval" gorm:"type:int;not null;default:15"`              // 监测间隔(分钟)
	LastNotified *time.Time  `json:"last_notified"`                                             // 上次通知时间
}

LoadNotification 定义了基于资源占用达标时间比的负载通知规则

type Log

type Log struct {
	ID      uint      `json:"id,omitempty" gorm:"primaryKey;autoIncrement"`
	IP      string    `json:"ip" gorm:"type:varchar(45);"` // IPv4 or IPv6
	UUID    string    `json:"uuid" gorm:"type:varchar(36);"`
	Message string    `json:"message" gorm:"type:text;not null"`
	MsgType string    `json:"msg_type" gorm:"type:varchar(20);not null;index:idx_logs_msg_type_time,priority:1"`
	Time    time.Time `json:"time" gorm:"autoCreateTime;not null;index:idx_logs_time;index:idx_logs_msg_type_time,priority:2"`
}

type ManagedThemeConfigurationItem

type ManagedThemeConfigurationItem struct {
	Key      string `json:"key"`
	Name     any    `json:"name"`
	Required bool   `json:"required"`
	Type     string `json:"type"` // string number select switch title textbox richtext nodes pingtasks
	Options  string `json:"options"`
	Default  any    `json:"default"`
	Help     any    `json:"help"`
}

type MessageSenderProvider

type MessageSenderProvider struct {
	Name     string `json:"name" gorm:"primaryKey;unique;not null"`
	Addition string `json:"addition" gorm:"type:longtext;default:'{}'"`
}

type OfflineNotification

type OfflineNotification struct {
	Client     string `` /* 138-byte string literal not displayed */
	ClientInfo Client `json:"client_info,omitempty" gorm:"foreignKey:Client;references:UUID"`
	Enable     bool   `json:"enable" gorm:"type:boolean;default:false"`
	//Cooldown     int       `json:"cooldown" gorm:"type:int;not null;default:1800"`                // 冷却时间(秒),默认 30 分钟
	GracePeriod  int        `json:"grace_period" gorm:"type:int;not null;default:180"` // 宽限期(秒),默认 3 分钟
	LastNotified *time.Time `json:"last_notified"`                                     // 上次通知时间
}

Notification 定义了通知相关的数据库模型

type OidcProvider

type OidcProvider struct {
	Name     string `json:"name" gorm:"primaryKey;unique;not null"`
	Addition string `json:"addition" gorm:"type:longtext;default:'{}'"`
}

type PageType

type PageType string

PageType controls how a plugin page is presented.

const (
	// PageTypeIframe embeds a static file from the plugin directory.
	PageTypeIframe PageType = "iframe"
	// PageTypeRedirect navigates to an internal site path, mirroring the
	// theme redirect configuration. The URL must stay on the same origin.
	PageTypeRedirect PageType = "redirect"
)

type PageVisibility

type PageVisibility string

PageVisibility controls who can reach a plugin page.

const (
	// PageVisibilityAdmin limits the page to the admin sidebar.
	PageVisibilityAdmin PageVisibility = "admin"
	// PageVisibilityPublic serves the page through the public route without
	// navigation, mirroring the theme public behavior.
	PageVisibilityPublic PageVisibility = "public"
)

type PingRecord

type PingRecord struct {
	Client     string    `json:"client" gorm:"type:varchar(36);not null;index"`
	ClientInfo Client    `json:"client_info" gorm:"foreignKey:Client;references:UUID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	TaskID     uint      `json:"task_id" gorm:"not null;index"`
	Task       PingTask  `json:"task" gorm:"foreignKey:TaskID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
	Time       time.Time `json:"time" gorm:"index;not null"`
	Value      int       `json:"value" gorm:"type:int;not null"` // Ping 值,单位毫秒
}

type PingTask

type PingTask struct {
	ID        uint        `json:"id,omitempty" gorm:"primaryKey;autoIncrement"`
	Weight    int         `json:"weight" gorm:"type:int;not null;default:0;index"`
	Name      string      `json:"name" gorm:"type:varchar(255);not null;index"`
	Clients   StringArray `json:"clients" gorm:"type:longtext"`
	DefaultOn bool        `json:"default_on" gorm:"column:all_clients;not null;default:false"` // 新加入的服务器是否自动开启此监测;现有服务器不受此字段影响
	Type      string      `json:"type" gorm:"type:varchar(12);not null;default:'icmp'"`        // icmp tcp http
	Target    string      `json:"target" gorm:"type:varchar(255);not null"`                    // Ping 目标地址
	Interval  int         `json:"interval" gorm:"type:int;not null;default:60"`                // 间隔时间
}

PingTask 表示一次延迟监测任务配置。

func (PingTask) AppliesToClient

func (task PingTask) AppliesToClient(uuid string) bool

AppliesToClient 判断当前 PingTask 是否适用于指定服务器。

type Plugin

type Plugin struct {
	Name          any               `json:"name"`
	Short         string            `json:"short"` // directory name under data/plugin
	Description   any               `json:"description"`
	Author        any               `json:"author"`
	Version       string            `json:"version"`
	URL           string            `json:"url"`
	Icon          string            `json:"icon"`
	Sonar         string            `json:"sonar"`  // supported server version constraint, e.g. ">=0.0.1"
	Komari        string            `json:"komari"` // supported server version constraint fallback for legacy plugins
	Entry         string            `json:"entry"`  // entry script, defaults to "script.js"
	Permissions   PluginPermissions `json:"permissions"`
	Configuration Configuration     `json:"configuration"`   // declared config items, same shape as themes
	Pages         []PluginPage      `json:"pages,omitempty"` // injected admin pages
}

Plugin is the manifest of an installed plugin (komari-plugin.json).

Name, Description and Author accept either a plain string or an i18n map like {"zh_CN": "...", "en": "..."}, mirroring the theme manifest. The backend passes the value through and the frontend resolves it against the current locale.

func (Plugin) VersionConstraint

func (p Plugin) VersionConstraint() string

VersionConstraint returns the declared server version constraint, preferring "sonar" over legacy "komari".

type PluginConfiguration

type PluginConfiguration struct {
	Short string `json:"short" gorm:"primaryKey;unique;not null"`
	Data  string `json:"data" gorm:"type:longtext;default:'{}'"`
}

PluginConfiguration stores the saved configuration values of one plugin, mirroring ThemeConfiguration.

type PluginPage

type PluginPage struct {
	File       string         `json:"file"`
	Title      any            `json:"title"`
	Icon       string         `json:"icon"`
	Type       PageType       `json:"type,omitempty"`
	URL        string         `json:"url,omitempty"`
	Visibility PageVisibility `json:"visibility,omitempty"`
}

PluginPage declares a page provided by the plugin. An iframe page is served from the plugin directory (File); a redirect page navigates to an internal site path (URL). Visibility defaults to admin so existing packages keep their current behavior.

type PluginPermissions

type PluginPermissions struct {
	Node                bool  `json:"node"`                // Node.js compatibility modules (runtime setting, not approval-relevant)
	AllowSystemRPC      bool  `json:"allowSystemRPC"`      // server.call: call system RPC methods with admin authority
	AllowRoutes         bool  `json:"allowRoutes"`         // server.route: register HTTP routes on the host engine
	AllowHooks          bool  `json:"allowHooks"`          // server.hook: modify HTTP requests/responses and intercept WebSocket connections/frames
	AllowHTMLInject     bool  `json:"allowHTMLInject"`     // server.injectHTML: embed CSS/JS into every HTML response
	AllowExec           bool  `json:"allowExec"`           // child_process: execute child processes
	AllowListen         bool  `json:"allowListen"`         // net/http servers: listen on local ports
	AllowAllFileAccess  bool  `json:"allowAllFileAccess"`  // access files outside the plugin directory
	MaxHTTPBodyBytes    int64 `json:"maxHTTPBodyBytes"`    // runtime limit, not approval-relevant
	MaxChildOutputBytes int   `json:"maxChildOutputBytes"` // runtime limit, not approval-relevant
	TimeoutSeconds      int   `json:"timeout"`             // per-turn execution timeout in seconds, not approval-relevant
}

PluginPermissions declares the plugin capabilities that require admin approval. Every field defaults to its zero value: nothing is granted unless declared.

The following capabilities are always granted and never require approval: reading the plugin's own configuration (server.getConfig), registering plugin-owned RPC methods (server.registerRPC), and reading/writing files inside the plugin directory.

type Record

type Record struct {
	Client         string    `json:"client" gorm:"type:varchar(36);index"`
	Time           time.Time `json:"time" gorm:"index"`
	CPU            float32   `json:"cpu" gorm:"type:decimal(5,2)"` // e.g., 75.50%
	GPU            float32   `json:"gpu" gorm:"type:decimal(5,2)"`
	RAM            int64     `json:"ram" gorm:"type:bigint"`
	RAMTotal       int64     `json:"ram_total" gorm:"type:bigint"`
	Swap           int64     `json:"swap" gorm:"type:bigint"`
	SwapTotal      int64     `json:"swap_total" gorm:"type:bigint"`
	Load           float32   `json:"load" gorm:"type:decimal(5,2)"`
	Temp           float32   `json:"temp" gorm:"type:decimal(5,2)"`
	Disk           int64     `json:"disk" gorm:"type:bigint"`
	DiskTotal      int64     `json:"disk_total" gorm:"type:bigint"`
	NetIn          int64     `json:"net_in" gorm:"type:bigint"`
	NetOut         int64     `json:"net_out" gorm:"type:bigint"`
	NetTotalUp     int64     `json:"net_total_up" gorm:"type:bigint"`
	NetTotalDown   int64     `json:"net_total_down" gorm:"type:bigint"`
	TrafficUp      int64     `json:"traffic_up" gorm:"type:bigint"`
	TrafficDown    int64     `json:"traffic_down" gorm:"type:bigint"`
	Process        int       `json:"process"`
	Connections    int       `json:"connections"`
	ConnectionsUDP int       `json:"connections_udp"`
}

Record logs client metrics over time

type Session

type Session struct {
	UUID            string    `json:"uuid" gorm:"type:varchar(36)"`
	Session         string    `json:"session" gorm:"type:varchar(255);primaryKey;uniqueIndex:idx_sessions_session;not null"`
	UserAgent       string    `json:"user_agent" gorm:"type:text"`
	IP              string    `json:"ip" gorm:"type:varchar(100)"`
	LoginMethod     string    `json:"login_method" gorm:"type:varchar(50)"`
	LatestOnline    time.Time `json:"latest_online" gorm:"type:timestamp"`
	LatestUserAgent string    `json:"latest_user_agent" gorm:"type:text"`
	LatestIP        string    `json:"latest_ip" gorm:"type:varchar(100)"`
	Expires         time.Time `json:"expires" gorm:"not null"`
	CreatedAt       time.Time `json:"created_at"`
}

Session manages user sessions

type StringArray

type StringArray []string

StringArray represents a slice of strings stored as JSON in the database StringArray 存储为 JSON 的字符串切片类型

func (*StringArray) Scan

func (sa *StringArray) Scan(value any) error

func (StringArray) Value

func (sa StringArray) Value() (driver.Value, error)

type Theme

type Theme struct {
	Name          any           `json:"name"`          // 主题名称,支持字符串或多语言对象
	Short         string        `json:"short"`         // 短名称,用作文件夹名
	Description   any           `json:"description"`   // 主题描述,支持字符串或多语言对象
	Version       string        `json:"version"`       // 版本号
	Author        any           `json:"author"`        // 作者,支持字符串或多语言对象
	URL           string        `json:"url"`           // 主题URL
	Preview       string        `json:"preview"`       // 预览图片相对路径
	Configuration Configuration `json:"configuration"` // 声明配置项
}

Theme represents a komari theme information

type ThemeConfiguration

type ThemeConfiguration struct {
	Short string `json:"short" gorm:"primaryKey;unique;not null"`
	Data  string `json:"data" gorm:"type:longtext;default:'{}'"`
}

type TrafficReportNotification

type TrafficReportNotification struct {
	Client     string `` /* 138-byte string literal not displayed */
	ClientInfo Client `json:"client_info,omitempty" gorm:"foreignKey:Client;references:UUID"`
	Enable     bool   `json:"enable" gorm:"type:boolean;default:false"`
	Daily      bool   `json:"daily" gorm:"type:boolean;default:false"`   // 日报
	Weekly     bool   `json:"weekly" gorm:"type:boolean;default:false"`  // 周报
	Monthly    bool   `json:"monthly" gorm:"type:boolean;default:false"` // 月报
}

TrafficReportNotification 定义了流量定时报告的数据库模型

type User

type User struct {
	UUID      string    `json:"uuid,omitempty" gorm:"type:varchar(36);primaryKey"`
	Username  string    `json:"username" gorm:"type:varchar(50);unique;not null"`
	Passwd    string    `json:"passwd,omitempty" gorm:"type:varchar(255);not null"` // Hashed password
	SSOType   string    `json:"sso_type" gorm:"type:varchar(20)"`                   // e.g., "github", "google"
	SSOID     string    `json:"sso_id" gorm:"type:varchar(100)"`                    // OAuth provider's user ID
	TwoFactor string    `json:"two_factor,omitempty" gorm:"type:varchar(255)"`      // 2FA secret
	Sessions  []Session `json:"sessions,omitempty" gorm:"foreignKey:UUID;references:UUID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

User represents an authenticated user

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL