Documentation
¶
Index ¶
- Constants
- func DriveUploadMaxSizeKBHardCap() int
- func FileExtraAllowedFromEnv() []string
- func FileExtraBlockedFromEnv() []string
- func FileMaxSizeKBHardCap() int
- func FileUploadLimits() (maxSizeKB int, allowedExtensions []string, ok bool)
- func IsBuiltinBlockedFileExtension(ext string) bool
- func NormalizeFileExtension(raw string) string
- func ParseFileExtensionCSV(raw string) []string
- func SetBuiltinBlockedFileExtensionProbe(fn func(ext string) bool)
- func SetCardTemplateCatalogReadinessCheck(check func() error)
- func SetFileUploadLimitsProvider(fn func() (maxSizeKB int, allowedExtensions []string))
- func ValidateGroupWelcomeCombination(cfg GroupWelcomeConfig) (field string)
- func ValidateSpaceWelcomeCombination(cfg SpaceWelcomeConfig, isActiveSpace func(spaceID string) (bool, error)) (field string, err error)
- func ViolatesFileStickerSizeOrdering(o FileStickerSizeOrdering) bool
- func ViolatesThreadArchiveOrdering(o ThreadArchiveOrdering) bool
- type AppConfigResp
- type Common
- type Country
- type DriveUploadLimits
- type DriveUploadPolicy
- type FileStickerSizeOrdering
- type GroupWelcomeConfig
- type GroupWelcomeConfigStore
- func (s *GroupWelcomeConfigStore) Delete(ctx context.Context, groupNo string) (bool, error)
- func (s *GroupWelcomeConfigStore) Exists(ctx context.Context, groupNo string) (bool, error)
- func (s *GroupWelcomeConfigStore) Get(ctx context.Context, groupNo string) (*GroupWelcomeConfig, bool, error)
- func (s *GroupWelcomeConfigStore) ListEnabled(ctx context.Context) ([]GroupWelcomeConfig, error)
- func (s *GroupWelcomeConfigStore) Upsert(ctx context.Context, cfg GroupWelcomeConfig, now time.Time) error
- func (s *GroupWelcomeConfigStore) UpsertMerged(ctx context.Context, groupNo string, now time.Time, ...) (*GroupWelcomeConfig, error)
- type IService
- type Manager
- type ManagerEmailMFAState
- type SpaceWelcomeConfig
- type SpaceWelcomeConfigStore
- func (s *SpaceWelcomeConfigStore) Delete(ctx context.Context, spaceID string) (bool, error)
- func (s *SpaceWelcomeConfigStore) Exists(ctx context.Context, spaceID string) (bool, error)
- func (s *SpaceWelcomeConfigStore) Get(ctx context.Context, spaceID string) (*SpaceWelcomeSpaceConfig, bool, error)
- func (s *SpaceWelcomeConfigStore) ListEnabled(ctx context.Context) ([]SpaceWelcomeSpaceConfig, error)
- func (s *SpaceWelcomeConfigStore) Upsert(ctx context.Context, cfg SpaceWelcomeSpaceConfig, now time.Time) error
- func (s *SpaceWelcomeConfigStore) UpsertMerged(ctx context.Context, spaceID string, now time.Time, ...) (*SpaceWelcomeSpaceConfig, error)
- type SpaceWelcomeSpaceConfig
- type SystemSettings
- func (s *SystemSettings) AppBotAuthCacheTTLSeconds() int
- func (s *SystemSettings) BotCardDisplayEnabledDefault() bool
- func (s *SystemSettings) BotCardInteractionEnabledDefault() bool
- func (s *SystemSettings) BotCardReasoningEnabledDefault() bool
- func (s *SystemSettings) BotRateLimitBusinessBurst() int
- func (s *SystemSettings) BotRateLimitBusinessDryRun() bool
- func (s *SystemSettings) BotRateLimitBusinessEnabled() bool
- func (s *SystemSettings) BotRateLimitBusinessRPS() float64
- func (s *SystemSettings) BotRateLimitHeartbeatBurst() int
- func (s *SystemSettings) BotRateLimitHeartbeatDryRun() bool
- func (s *SystemSettings) BotRateLimitHeartbeatEnabled() bool
- func (s *SystemSettings) BotRateLimitHeartbeatRPS() float64
- func (s *SystemSettings) BotRateLimitRegisterBurst() int
- func (s *SystemSettings) BotRateLimitRegisterDryRun() bool
- func (s *SystemSettings) BotRateLimitRegisterEnabled() bool
- func (s *SystemSettings) BotRateLimitRegisterRPS() float64
- func (s *SystemSettings) DmloopEnabled() bool
- func (s *SystemSettings) DmpersonalEnabled() bool
- func (s *SystemSettings) DocsEnabled() bool
- func (s *SystemSettings) DocsSearchEnabled() bool
- func (s *SystemSettings) DriveEnabled() bool
- func (s *SystemSettings) DriveSearchEnabled() bool
- func (s *SystemSettings) DriveUploadLimits() DriveUploadLimits
- func (s *SystemSettings) DriveUploadMaxSizeKB() int
- func (s *SystemSettings) DriveUploadPolicy() DriveUploadPolicy
- func (s *SystemSettings) DriveUploadPolicyAvail() (DriveUploadPolicy, bool)
- func (s *SystemSettings) DriveUploadV2On() bool
- func (s *SystemSettings) FileExtraAllowedExtensions() []string
- func (s *SystemSettings) FileExtraBlockedExtensions() []string
- func (s *SystemSettings) FileMaxSizeKB() int
- func (s *SystemSettings) FileStickerSizeOrdering() FileStickerSizeOrdering
- func (s *SystemSettings) GroupWelcomeEnabled() bool
- func (s *SystemSettings) IncomingWebhookEnabled() bool
- func (s *SystemSettings) IncomingWebhookMaxPerCreator() int
- func (s *SystemSettings) IncomingWebhookMaxPerGroup() int
- func (s *SystemSettings) IncomingWebhookMaxPerThread() int
- func (s *SystemSettings) IncomingWebhookMaxTotalPerGroup() int
- func (s *SystemSettings) IncomingWebhookMemberCanBroadcast() bool
- func (s *SystemSettings) IncomingWebhookPerWebhookBurst() int
- func (s *SystemSettings) IncomingWebhookPerWebhookRPS() float64
- func (s *SystemSettings) Load() error
- func (s *SystemSettings) LocalLoginOff() bool
- func (s *SystemSettings) LogLocalLoginOffSafetyOverrideIfActive(localOff bool)
- func (s *SystemSettings) MailEnabled() bool
- func (s *SystemSettings) ManagerEmailMFAOn() bool
- func (s *SystemSettings) ManagerEmailMFAProbeGeneration() uint64
- func (s *SystemSettings) ManagerEmailMFAReady() bool
- func (s *SystemSettings) ManagerEmailMFAState() ManagerEmailMFAState
- func (s *SystemSettings) MessageReactionReadEnabled() bool
- func (s *SystemSettings) MessageReactionWriteEnabled() bool
- func (s *SystemSettings) OIDCInitialSpaceID() string
- func (s *SystemSettings) PreflightManagerEmailMFA(ctx context.Context) error
- func (s *SystemSettings) ProfileContactInfoOn() bool
- func (s *SystemSettings) ProjectEnabled() bool
- func (s *SystemSettings) ProjectEnabledOverride() (value bool, found bool)
- func (s *SystemSettings) RawLocalLoginOffFromSnapshot() bool
- func (s *SystemSettings) RecordManagerEmailMFAPreflight(generation uint64, ok bool) bool
- func (s *SystemSettings) RecordManagerEmailMFAPreflightIfMatches(generation uint64, probed smtpSettingsSnapshot) bool
- func (s *SystemSettings) RegisterEmailOn() bool
- func (s *SystemSettings) RegisterOff() bool
- func (s *SystemSettings) RegisterOnlyChina() bool
- func (s *SystemSettings) RegisterUsernameOn() bool
- func (s *SystemSettings) Reload() error
- func (s *SystemSettings) ScanLoginEnabled() bool
- func (s *SystemSettings) SettingBoolOK(category, key string) (value bool, configured bool)
- func (s *SystemSettings) SidebarRecentFilterGroupDays() int
- func (s *SystemSettings) SidebarRecentFilterPersonDays() int
- func (s *SystemSettings) SidebarRecentFilterThreadDays() int
- func (s *SystemSettings) SpaceDisableUserCreate() bool
- func (s *SystemSettings) SpaceWelcomeConfig() SpaceWelcomeConfig
- func (s *SystemSettings) StartAutoReload(ctx context.Context)
- func (s *SystemSettings) StickerCompressEnabled() bool
- func (s *SystemSettings) StickerCompressMaxConcurrency() int
- func (s *SystemSettings) StickerCompressMaxDimension() int
- func (s *SystemSettings) StickerCompressTargetKB() int
- func (s *SystemSettings) StickerCompressTimeoutMs() int
- func (s *SystemSettings) StickerCustomEnabled() bool
- func (s *SystemSettings) StickerHandleRequired() bool
- func (s *SystemSettings) StickerUploadAllowedFormats() []string
- func (s *SystemSettings) StickerUploadMaxDimension() int
- func (s *SystemSettings) StickerUploadMaxSizeKB() int
- func (s *SystemSettings) StickerUserMaxCount() int
- func (s *SystemSettings) SupportEmail() string
- func (s *SystemSettings) SupportEmailPwd() string
- func (s *SystemSettings) SupportEmailSmtp() string
- func (s *SystemSettings) ThreadArchiveOrdering() ThreadArchiveOrdering
- func (s *SystemSettings) ThreadAutoArchiveDays() int
- func (s *SystemSettings) ThreadAutoArchiveEnabled() bool
- func (s *SystemSettings) TrackingEnabled() bool
- func (s *SystemSettings) ValidateManagerEmailMFASMTP() error
- type ThreadArchiveOrdering
Constants ¶
const ( // GroupWelcomeMessageMaxRunes bounds the welcome body in Unicode code points, // enforced on the write path (protects the VARCHAR(2000) column). GroupWelcomeMessageMaxRunes = 2000 // GroupWelcomeActiveFromMaxLen bounds the active_from string to its storage // column width (VARCHAR(40)). Enforced on the write path independently of // enabled/parse: a disabled config skips the RFC3339 parse, and time.Parse // otherwise accepts arbitrarily long fractional seconds, so without this guard // an over-column value could reach the upsert and fail as a driver 500 (strict // sql_mode) or truncate silently (permissive). GroupWelcomeActiveFromMaxLen = 40 )
const ( // DefaultDriveUploadMaxSizeKB 是单文件上限的代码默认值(1 GiB)。 // drive.upload_max_size_kb 未配置时生效。这个键没有历史 env 兼容层 —— 它 // 是本任务全新引入的键,回退链只有 DB → code default 两层。 DefaultDriveUploadMaxSizeKB = 1024 * 1024 )
--------------------------------------------------------------------------- Drive 上传策略 —— 配置真源(task drive-upload-policy)。
本文件只负责「单个上传上限」这一格的读侧真源:DB 键 drive.upload_max_size_kb + 部署 env 天花板 OCTO_DRIVE_UPLOAD_MAX_SIZE_KB_HARD_CAP + 代码默认值,三层 回退与 clamp。分片参数与策略结构在 drive_upload_policy.go,appconfig 下发在 api.go,服务间下发在 modules/drivepolicy。
这是「配置真源」而不是「上传校验」:octo-server 不代理文件字节、不做上传 大小强制(那是 ② octo-drive 的职责),这里只保证下发值正确。
职责三层(照 file.max_size_kb 的既有形态):
开发 代码默认值 DefaultDriveUploadMaxSizeKB(1 GiB),未配置时兜底 运维 OCTO_DRIVE_UPLOAD_MAX_SIZE_KB_HARD_CAP 定天花板(改 configmap + 重启) 超管 drive.upload_max_size_kb 调实际值(管理台,≤60s 生效,超不过天花板)
天花板若是 env 而不是管理台:超管就能先抬天花板再抬实际值,这道闸等于不 存在。env 要重启 Pod,这个成本本身就是防线。
const ( // DefaultFileMaxSizeKB 是单文件上限的代码默认值,等于迁移前 modules/file // 的 MaxFileSize 常量(100MB)。这个键**没有 env 层**:迁移前它就是硬编码 // 常量,没有对应 env,所以回退链只有 DB → code default 两层。 DefaultFileMaxSizeKB = 100 * 1024 )
const SpaceWelcomeActiveFromMaxLen = 40
SpaceWelcomeActiveFromMaxLen bounds the active_from string to its storage column width (VARCHAR(40) in the config migration). Enforced on the write path independently of enabled/parse: a disabled config skips the RFC3339 parse entirely, and time.Parse otherwise accepts arbitrarily long fractional seconds, so without this guard an over-column value could reach the upsert and fail as a driver/store 500 (strict sql_mode) or truncate silently (permissive).
const SpaceWelcomeMessageMaxRunes = spaceWelcomeMessageMaxRunes
SpaceWelcomeMessageMaxRunes is the max welcome body length in Unicode code points, enforced on every write path (per-Space CRUD and the manager global config). Exported so modules/space can bound its column write without duplicating the constant.
const ( // StickerUploadMaxDimensionHardCap is the exported alias of the decoded-pixel // dimension hard cap (== stickerUploadMaxDimensionHardCap). modules/file // references it so the compressible-accept ceiling shares this single source // of truth rather than re-declaring a bare 1024 literal (review finding: a // hand-synced duplicate could silently drift and re-widen the bomb gate). StickerUploadMaxDimensionHardCap = stickerUploadMaxDimensionHardCap )
Variables ¶
This section is empty.
Functions ¶
func DriveUploadMaxSizeKBHardCap ¶ added in v1.22.0
func DriveUploadMaxSizeKBHardCap() int
DriveUploadMaxSizeKBHardCap 返回 drive 单文件上限的天花板(KB)。
这是**部署容量决策**,不是产品语义边界,所以跟着部署配置走而不是编译进二 进制:能传多大取决于对象存储后端、带宽与临时磁盘,每个部署不一样。非法 env(非数字 / ≤0 / 超防溢出上界)回落默认 10 GiB,不 panic、不暴露非法值。
func FileExtraAllowedFromEnv ¶ added in v1.17.0
func FileExtraAllowedFromEnv() []string
FileExtraAllowedFromEnv 解析 DM_FILE_EXTRA_ALLOWED。 供 SystemSettings 的回退层与 modules/file 的 nil-settings 回落路径共用。
func FileExtraBlockedFromEnv ¶ added in v1.17.0
func FileExtraBlockedFromEnv() []string
FileExtraBlockedFromEnv 解析 DM_FILE_EXTRA_BLOCKED。
func FileMaxSizeKBHardCap ¶ added in v1.17.0
func FileMaxSizeKBHardCap() int
FileMaxSizeKBHardCap 返回单文件上限的天花板(KB)。
这是**部署容量决策**,不是产品语义边界,所以它跟着部署配置走而不是编译进 二进制:能传多大取决于 ingress 的 body 限制、临时文件的磁盘、带宽和对象 存储后端,每个部署都不一样。对比 sticker 那组硬上限——「贴纸该多大」在任何 部署下都一样,那种才适合写死。
为什么是 env 而不是管理台:天花板若也能从管理台改,超管就能先抬天花板、 再抬实际值,这道闸等于不存在。env 要重启 Pod,这个成本本身就是防线。
职责因此分成三层:
开发 代码默认值(512MB),未配置时兜底 运维 OCTO_FILE_MAX_SIZE_KB_HARD_CAP 定天花板(改 configmap + 重启) 超管 file.max_size_kb 调实际值(管理台,≤60s 生效,超不过天花板)
非法值(非数字 / ≤0 / 超过防溢出上界)回落代码默认值,而不是被原样服务。
func FileUploadLimits ¶ added in v1.17.0
FileUploadLimits 返回当前生效的上传限制。ok=false 表示 provider 未注册 (modules/file 未链接进本次构建),调用方应当**整个字段不下发**,而不是 下发一个空数组 —— 空 allowed_extensions 会被客户端读成「什么都不能传」。
func IsBuiltinBlockedFileExtension ¶ added in v1.17.0
IsBuiltinBlockedFileExtension 报告扩展名是否在内置黑名单里(不可通过任何 配置撤销)。probe 未注册时返回 false —— 降级为「不额外拦截」,真正的安全 保证在 modules/file 的派生里,那一层不依赖本探针。
func NormalizeFileExtension ¶ added in v1.17.0
NormalizeFileExtension 清洗单个扩展名 token,非法输入返回 ""。
语义与迁移前 modules/file/const.go:loadExtensionsFromEnv 内联的 normalizeExt **逐字节一致**(去空格、转小写、补前导点、丢弃 "." / ".." / 含路径分隔符 / 补全后仍含 ".." 的畸形输入),因为 env 层必须保持既有部署的解析结果不变。 导出是为了让 modules/file 直接复用同一份实现,而不是镜像一份 —— 镜像会漂移。
func ParseFileExtensionCSV ¶ added in v1.17.0
ParseFileExtensionCSV 把逗号分隔的扩展名列表清洗成去重后的有序切片。 非法 token 静默丢弃(调用方按需记日志);返回值顺序为输入顺序,稳定可比较。
func SetBuiltinBlockedFileExtensionProbe ¶ added in v1.17.0
SetBuiltinBlockedFileExtensionProbe 由 modules/file 的 init() 调用一次。
func SetCardTemplateCatalogReadinessCheck ¶ added in v1.13.0
func SetCardTemplateCatalogReadinessCheck(check func() error)
SetCardTemplateCatalogReadinessCheck installs the process-local, IO-free catalog readiness callback. The composition root calls it before module construction; nil is reserved for test cleanup and pre-catalog binaries.
func SetFileUploadLimitsProvider ¶ added in v1.17.0
SetFileUploadLimitsProvider 由 modules/file 的 init() 调用一次。
func ValidateGroupWelcomeCombination ¶ added in v1.12.0
func ValidateGroupWelcomeCombination(cfg GroupWelcomeConfig) (field string)
ValidateGroupWelcomeCombination validates the tuple as a coherent combination.
- When disabled it always passes (a partial/empty config is fine while off).
- When enabled it requires a non-empty group_no, a parseable RFC3339 active_from, and a message non-empty (after trim) within GroupWelcomeMessageMaxRunes.
Returns the first offending field name ("" when valid). There is no group existence check here — the CRUD write path has already confirmed the path group is active via the authz gate.
func ValidateSpaceWelcomeCombination ¶ added in v1.11.0
func ValidateSpaceWelcomeCombination(cfg SpaceWelcomeConfig, isActiveSpace func(spaceID string) (bool, error)) (field string, err error)
ValidateSpaceWelcomeCombination validates the tuple as a coherent combination.
- When disabled it always passes: a partial or empty config is fine while the feature is off.
- When enabled it requires a non-empty space_id that isActiveSpace confirms exists and is not dissolved, a parseable RFC3339 active_from, and a message non-empty (after trim) within spaceWelcomeMessageMaxRunes.
The (field, err) contract lets the caller distinguish a validation failure (err == nil, field != "" naming the first offending key) from an infrastructure error (err != nil, e.g. the space lookup DB read failed). A nil isActiveSpace skips only the space existence check — used by callers that cannot reach the DB or want the pure static checks.
func ViolatesFileStickerSizeOrdering ¶ added in v1.17.0
func ViolatesFileStickerSizeOrdering(o FileStickerSizeOrdering) bool
ViolatesFileStickerSizeOrdering 报告该组合是否会让贴纸永远传不上去。
func ViolatesThreadArchiveOrdering ¶ added in v1.14.0
func ViolatesThreadArchiveOrdering(o ThreadArchiveOrdering) bool
ViolatesThreadArchiveOrdering reports whether a configuration would make the recent-tab thread window unobservable.
The invariant is ArchiveDays >= RecentDays, but only where both windows actually bite:
- archiving disabled, or ArchiveDays == 0 (threshold disabled): nothing is ever archived on a timer, so no window can be shadowed — always valid.
- RecentDays == 0: the recent-tab window is off; there is nothing to shadow — always valid.
Exported and pure so the guard can be unit-tested without an HTTP round-trip.
Types ¶
type AppConfigResp ¶
type AppConfigResp struct {
RSAPublicKey string
Version int
WelcomeMessage string // 登录欢迎语
NewUserJoinSystemGroup int // 新用户是否加入系统群聊
SearchByPhone int // 是否可通过手机号搜索
RegisterInviteOn int // 是否开启注册邀请
SendWelcomeMessageOn int // 是否发送登录欢迎语
InviteSystemAccountJoinGroupOn int // 是否允许邀请系统账号进入群聊
RegisterUserMustCompleteInfoOn int // 是否要求注册用户必须填写完整信息
ChannelPinnedMessageMaxCount int // 频道置顶消息最大数量
DestroyCoolingOffDays int // 注销冷静期天数(默认 7)
}
AppConfigResp returns safe configuration info, excluding sensitive fields such as SuperToken.
type Common ¶
Common Common
func (*Common) SystemSettings ¶ added in v1.3.0
func (cn *Common) SystemSettings() *SystemSettings
SystemSettings exposes the shared admin-tunable settings reader for callers that already hold a *Common. New consumers in other packages should prefer common.EnsureSystemSettings(ctx) directly.
type Country ¶
type Country struct {
Code string `json:"code"`
Icon string `json:"icon"`
Name string `json:"name"`
}
Country Country
type DriveUploadLimits ¶ added in v1.22.0
type DriveUploadLimits struct {
MaxSizeKB int `json:"max_size_kb"`
MultipartThresholdKB int `json:"multipart_threshold_kb"`
PartSizeKB int `json:"part_size_kb"`
MaxConcurrentParts int `json:"max_concurrent_parts"`
MaxConcurrentSessions int `json:"max_concurrent_sessions"`
}
DriveUploadLimits 是生效策略的 **Web 下发视图**:appconfig 下发的 5 个字段, 不含 policy_version 指纹。
单独一个类型(而不是复用 DriveUploadPolicy 再丢掉版本)是为了让「Web 只需要 5 个值」在类型上成立:构造它不触发内容哈希,也不会在**未鉴权**的 appconfig 热路径上做无谓的 sha256 + 字符串格式化(reviewer yujiawei,PR #930 P2)。指纹 只对内部服务间通道有价值(drive 侧按版本日志 / 观测)。
type DriveUploadPolicy ¶ added in v1.22.0
type DriveUploadPolicy struct {
MaxSizeKB int `json:"max_size_kb"`
MultipartThresholdKB int `json:"multipart_threshold_kb"`
PartSizeKB int `json:"part_size_kb"`
MaxConcurrentParts int `json:"max_concurrent_parts"`
MaxConcurrentSessions int `json:"max_concurrent_sessions"`
PolicyVersion string `json:"policy_version"`
}
DriveUploadPolicy 是「生效策略」的内容快照,字段名 / 单位与共享契约 §3.3(服务间接口)逐字一致。policy_version 是下面 6 个输入的**内容哈希** (见 driveUploadPolicyVersion),是「生效策略指纹」而不是递增序号:值不变则 版本不变,env 分片参数变化(需重启)也会体现。
type FileStickerSizeOrdering ¶ added in v1.17.0
FileStickerSizeOrdering 是参与组合校验的两个上限值(KB)。
func ApplyFileStickerSizeOverlay ¶ added in v1.17.0
func ApplyFileStickerSizeOverlay(cur FileStickerSizeOrdering, incoming map[string]string) FileStickerSizeOrdering
ApplyFileStickerSizeOverlay 把一批待写入的值叠加到当前组合上,得到「若本次 写入提交后」的 prospective 组合。key 形如 "file.max_size_kb"。 无法解析的值保持原值 —— 类型校验在调用方已经跑过。
叠加后**必须按各自 getter 的上界钳位**,否则守卫比较的两侧不同质:cur 来自 钳位过的 getter,incoming 却是原样值,于是它校验了一对运行时永远不会执行的 组合。天花板是常量 524288 时这只会过度拒绝(fail-closed,clamp 的结果恒高于 贴纸上限);天花板可配到贴纸上限之下后,它会**漏拒**:
OCTO_FILE_MAX_SIZE_KB_HARD_CAP=512,贴纸取默认 1024
超管写 file.max_size_kb=4096
改动前 prospective={4096,1024} → 合法 → 200 {"applied":true}
运行时钳位后 {512,1024} → 贴纸永远传不上去,且没有任何报错
贴纸侧只钳到贴纸自身的硬上限,**不钳全局上限** —— 钳了两侧就恒相等,守卫 永远不触发。
type GroupWelcomeConfig ¶ added in v1.12.0
type GroupWelcomeConfig struct {
GroupNo string
Enabled bool
ActiveFromRaw string // RFC3339 UTC string; "" when unset
Message string
UpdatedBy string
CreatedAt time.Time
UpdatedAt time.Time
}
GroupWelcomeConfig is one per-group welcome config row / the effective config consumed by the delivery path.
func (GroupWelcomeConfig) ParsedActiveFrom ¶ added in v1.12.0
func (c GroupWelcomeConfig) ParsedActiveFrom() (time.Time, bool)
ParsedActiveFrom parses ActiveFromRaw as RFC3339 and returns it in UTC. ok is false when the value is empty or unparseable — callers treat that as an invalid combination (fail closed) when the feature is enabled.
type GroupWelcomeConfigStore ¶ added in v1.12.0
type GroupWelcomeConfigStore struct {
// contains filtered or unexported fields
}
GroupWelcomeConfigStore is the DB access layer for per-group welcome config.
func NewGroupWelcomeConfigStore ¶ added in v1.12.0
func NewGroupWelcomeConfigStore(db *dbr.Session) *GroupWelcomeConfigStore
NewGroupWelcomeConfigStore builds a store over the given session.
func (*GroupWelcomeConfigStore) Delete ¶ added in v1.12.0
Delete hard-deletes the per-group config row. deleted=false when none existed (idempotent). After a delete the group reverts to off (no fallback).
func (*GroupWelcomeConfigStore) Exists ¶ added in v1.12.0
Exists reports whether a per-group row exists for groupNo (any enabled value).
func (*GroupWelcomeConfigStore) Get ¶ added in v1.12.0
func (s *GroupWelcomeConfigStore) Get(ctx context.Context, groupNo string) (*GroupWelcomeConfig, bool, error)
Get returns the per-group config row; found=false when absent (not an error).
func (*GroupWelcomeConfigStore) ListEnabled ¶ added in v1.12.0
func (s *GroupWelcomeConfigStore) ListEnabled(ctx context.Context) ([]GroupWelcomeConfig, error)
ListEnabled returns all enabled per-group configs, ordered by group_no, for the reconciler / worker to iterate the set of groups with an active welcome.
func (*GroupWelcomeConfigStore) Upsert ¶ added in v1.12.0
func (s *GroupWelcomeConfigStore) Upsert(ctx context.Context, cfg GroupWelcomeConfig, now time.Time) error
Upsert inserts or updates the per-group config in a single statement.
NOTE: this is a simple idempotent write for single-writer / test contexts. Production admin CRUD MUST use UpsertMerged, which serializes concurrent PUTs (insert-then-lock + deadlock retry) to prevent lost partial updates when two managers edit the same group at once.
func (*GroupWelcomeConfigStore) UpsertMerged ¶ added in v1.12.0
func (s *GroupWelcomeConfigStore) UpsertMerged( ctx context.Context, groupNo string, now time.Time, merge func(cur *GroupWelcomeConfig, found bool) (GroupWelcomeConfig, error), ) (*GroupWelcomeConfig, error)
UpsertMerged performs a read-modify-write of the per-group config inside a transaction, serialized so two managers PUTting the same group concurrently never lose each other's fields — whether editing an existing config OR both creating it for the first time. It uses the same insert-then-lock strategy as the Space store: an idempotent INSERT ... ON DUPLICATE KEY UPDATE ensures the row exists, then SELECT ... FOR UPDATE locks it before merge runs. Doing the INSERT before any gap-locking read avoids the first-create gap-lock deadlock; the single UNIQUE key makes concurrent same-key inserts a linear wait. A rare transient deadlock/lock-timeout is retried (see isRetryableTxErr, shared with the Space store).
merge receives the current row (found=false when this PUT just created the default row) and returns the config to persist; a non-nil merge error aborts the write (tx rolls back) and is returned verbatim (never retried). On success the persisted row, re-read inside the tx, is returned.
type IService ¶
type IService interface {
GetAppConfig() (*AppConfigResp, error)
// 获取短编号
GetShortno() (string, error)
SetShortnoUsed(shortno string, business string) error
}
IService IService
type ManagerEmailMFAState ¶ added in v1.17.0
type ManagerEmailMFAState uint8
ManagerEmailMFAState is deliberately tri-state. A nil snapshot means the database settings have never loaded successfully and must not be treated as the safe-looking "off" default by a manager login gate.
const ( ManagerEmailMFAOff ManagerEmailMFAOn )
type SpaceWelcomeConfig ¶ added in v1.11.0
SpaceWelcomeConfig is an atomic, point-in-time view of the four onboarding.space_welcome_* settings. All fields are read from the SAME SystemSettings snapshot in one access, so a caller can never straddle a background Reload() and combine values from two different snapshots. The event handler, send worker, reconciler and the manager write path all rely on this atomicity — reading the keys individually would risk an inconsistent combination.
Message is a single plain-text body sent to every recipient (no per-language split); it may contain line breaks (\n preserved verbatim; clients render type:1 text with newlines) but no markdown.
func ResolveEffectiveSpaceWelcome ¶ added in v1.12.0
func ResolveEffectiveSpaceWelcome(row *SpaceWelcomeSpaceConfig, found bool, global SpaceWelcomeConfig, spaceID string) SpaceWelcomeConfig
ResolveEffectiveSpaceWelcome computes the config in effect for spaceID:
- a per-Space row (if present) wins outright, EVEN when disabled — a present row lets an admin opt their Space out of a global campaign;
- otherwise the platform-global config applies iff it is enabled and its space_welcome_space_id names this Space;
- otherwise the feature is off for this Space.
The result reuses the SpaceWelcomeConfig shape so callers keep applying ValidateSpaceWelcomeCombination / ParsedActiveFrom unchanged.
func (SpaceWelcomeConfig) ParsedActiveFrom ¶ added in v1.11.0
func (c SpaceWelcomeConfig) ParsedActiveFrom() (time.Time, bool)
ParsedActiveFrom parses ActiveFromRaw as RFC3339 and returns it in UTC. ok is false when the value is empty or unparseable — callers treat that as an invalid combination (fail closed) when the feature is enabled.
type SpaceWelcomeConfigStore ¶ added in v1.12.0
type SpaceWelcomeConfigStore struct {
// contains filtered or unexported fields
}
SpaceWelcomeConfigStore is the DB access layer for per-Space welcome config.
func NewSpaceWelcomeConfigStore ¶ added in v1.12.0
func NewSpaceWelcomeConfigStore(db *dbr.Session) *SpaceWelcomeConfigStore
NewSpaceWelcomeConfigStore builds a store over the given session.
func (*SpaceWelcomeConfigStore) Delete ¶ added in v1.12.0
Delete hard-deletes the per-Space config row. deleted=false when none existed (idempotent). After a delete the Space reverts to the global fallback (or off).
func (*SpaceWelcomeConfigStore) Exists ¶ added in v1.12.0
Exists reports whether a per-Space row exists for spaceID (any enabled value). Used to decide whether the global fallback is overridden.
func (*SpaceWelcomeConfigStore) Get ¶ added in v1.12.0
func (s *SpaceWelcomeConfigStore) Get(ctx context.Context, spaceID string) (*SpaceWelcomeSpaceConfig, bool, error)
Get returns the per-Space config row; found=false when absent (not an error).
func (*SpaceWelcomeConfigStore) ListEnabled ¶ added in v1.12.0
func (s *SpaceWelcomeConfigStore) ListEnabled(ctx context.Context) ([]SpaceWelcomeSpaceConfig, error)
ListEnabled returns all enabled per-Space configs, ordered by space_id, for the reconciler / worker to iterate the set of Spaces with an active welcome.
func (*SpaceWelcomeConfigStore) Upsert ¶ added in v1.12.0
func (s *SpaceWelcomeConfigStore) Upsert(ctx context.Context, cfg SpaceWelcomeSpaceConfig, now time.Time) error
Upsert inserts or updates the per-Space config in a single statement. An empty ActiveFromRaw is stored as the empty string ("" = unset). now is the application-computed UTC value written to created_at (on insert) and updated_at (both).
NOTE: this is a simple idempotent write for single-writer / test contexts. Production admin CRUD MUST use UpsertMerged, which serializes concurrent PUTs (insert-then-lock + deadlock retry) to prevent lost partial updates when two admins edit the same Space at once; Upsert has no such protection.
func (*SpaceWelcomeConfigStore) UpsertMerged ¶ added in v1.12.0
func (s *SpaceWelcomeConfigStore) UpsertMerged( ctx context.Context, spaceID string, now time.Time, merge func(cur *SpaceWelcomeSpaceConfig, found bool) (SpaceWelcomeSpaceConfig, error), ) (*SpaceWelcomeSpaceConfig, error)
UpsertMerged performs a read-modify-write of the per-Space config inside a transaction, serialized so that two admins PUTting the same Space concurrently never lose each other's fields — whether they are editing an existing config OR both creating it for the first time.
It uses an insert-then-lock strategy: first an idempotent INSERT ... ON DUPLICATE KEY UPDATE ensures the row exists (no-op if it already does), THEN a SELECT ... FOR UPDATE locks that now-guaranteed row before merge runs. This is the fix for concurrent FIRST creates: a plain SELECT ... FOR UPDATE cannot lock a row that does not exist yet, so two creators would both merge onto defaults and the later write would clobber the earlier's disjoint field (or gap-lock deadlock under REPEATABLE READ). Doing the INSERT first — without a preceding gap-locking SELECT — gives the lock a real row to serialize on and avoids the gap-lock deadlock (the config table has a single UNIQUE key, so concurrent same-key inserts are a linear wait, not a cycle). A rare transient deadlock/lock-timeout is retried up to spaceWelcomeUpsertMaxAttempts.
merge receives the current row (found=false when this PUT just created the default row) and returns the config to persist. A non-nil error from merge aborts the write (tx rolls back) and is returned verbatim — callers use it to surface validation failures without writing, and it is never retried. On success the persisted row, re-read inside the tx, is returned. now is the app-computed UTC timestamp for created_at/updated_at.
type SpaceWelcomeSpaceConfig ¶ added in v1.12.0
type SpaceWelcomeSpaceConfig struct {
SpaceID string
Enabled bool
ActiveFromRaw string // RFC3339 UTC string; "" when unset
Message string
UpdatedBy string
CreatedAt time.Time
UpdatedAt time.Time
}
SpaceWelcomeSpaceConfig is one per-Space welcome config row.
type SystemSettings ¶ added in v1.3.0
SystemSettings is the read path for admin-tunable global config.
Lookup model:
- Snapshot is an immutable map[string]string ("category.key" → value), swapped atomically by Load / Reload. Generic readers go through the atomic.Pointer; the MFA readiness gate additionally takes a small publication lock so its snapshot and probe result stay paired.
- Empty DB value means "not configured" and falls back to the matching yaml field on *config.Config.
- Encrypted values are decrypted at snapshot-build time and cached in plaintext form in the map; the high-frequency read path never calls the cipher. Decryption failure logs an error and skips the entry, so the getter falls back to yaml rather than serving a corrupt value.
func EnsureSystemSettings ¶ added in v1.3.0
func EnsureSystemSettings(ctx *config.Context) *SystemSettings
EnsureSystemSettings returns the process-wide SystemSettings instance, constructing it on first call. Safe to call from any goroutine.
Failed initial Load is non-fatal: the background auto-reload (started here) retries every reloadTTL. Ordinary getters fall back to yaml while the snapshot is nil; security gates such as ScanLoginEnabled fail closed until a successful load publishes the first snapshot. A subsequent reload self-heals.
func NewSystemSettings ¶ added in v1.3.0
func NewSystemSettings(ctx *config.Context, db *systemSettingDB) *SystemSettings
NewSystemSettings builds a helper with an uninitialized snapshot. A nil snapshot distinguishes "the DB successfully returned no rows" from "the DB has never been read successfully". Callers must invoke Load() once at startup before serving traffic; Reload() is safe at any time.
func (*SystemSettings) AppBotAuthCacheTTLSeconds ¶ added in v1.7.0
func (s *SystemSettings) AppBotAuthCacheTTLSeconds() int
AppBotAuthCacheTTLSeconds is the safety-net TTL (seconds) written with each shared App Bot auth cache key. Read from system_setting (category "app_bot", key "auth_cache_ttl_seconds"); hot-reloaded with the rest of the snapshot, so an operator can retune it without a deploy. Out-of-range values fall back to the code default rather than being served verbatim (defence in depth).
func (*SystemSettings) BotCardDisplayEnabledDefault ¶ added in v1.14.0
func (s *SystemSettings) BotCardDisplayEnabledDefault() bool
BotCardDisplayEnabledDefault 等三个 getter 是 Bot 卡片能力的**服务端全局默认** (task bot-setting-store)。它们只回答「某个 Bot 没写过覆盖时该取什么」,不含 per-Bot 覆盖,也不含卡片总闸 cardmsg.BotEnabled() —— 完整解析链由 modules/robot 的 bot_setting 解析器组合,管理端的 effective_value 展示的也正是 本层的值(全局默认),而非某个具体 Bot 的有效值。
代码默认一律 true:总闸本身 fail-closed(OCTO_CARD_MESSAGE_ENABLED 未设即关), 安全默认由总闸承担;若这三项再各自默认 false,运维开了总闸还要逐 Bot 补开, 徒增困惑。
三者都委托给 SettingBoolOK 而不是 getBool,是因为 modules/robot 的解析器读的正是 SettingBoolOK:走两条路就等于同一列有两套词法。上一轮把 SettingBoolOK 放宽成 trim + 折叠大小写却没动这里,`botcard` 里一行 `False` 就会让管理台显示「开」而每个 Bot 解析成「关」—— 同一列对两个读者含义不同,正是本层要消灭的东西。委托而非复制: 词法只有一份,下次再改也不会只改一边。
func (*SystemSettings) BotCardInteractionEnabledDefault ¶ added in v1.14.0
func (s *SystemSettings) BotCardInteractionEnabledDefault() bool
func (*SystemSettings) BotCardReasoningEnabledDefault ¶ added in v1.14.0
func (s *SystemSettings) BotCardReasoningEnabledDefault() bool
func (*SystemSettings) BotRateLimitBusinessBurst ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitBusinessBurst() int
func (*SystemSettings) BotRateLimitBusinessDryRun ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitBusinessDryRun() bool
func (*SystemSettings) BotRateLimitBusinessEnabled ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitBusinessEnabled() bool
BotRateLimitBusinessEnabled 等三组 getter 的回退链均为 DB → env → code default。
func (*SystemSettings) BotRateLimitBusinessRPS ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitBusinessRPS() float64
func (*SystemSettings) BotRateLimitHeartbeatBurst ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitHeartbeatBurst() int
func (*SystemSettings) BotRateLimitHeartbeatDryRun ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitHeartbeatDryRun() bool
func (*SystemSettings) BotRateLimitHeartbeatEnabled ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitHeartbeatEnabled() bool
func (*SystemSettings) BotRateLimitHeartbeatRPS ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitHeartbeatRPS() float64
BotRateLimitHeartbeatRPS 在通用消毒之外再夹一道下界:见 botRateLimitMinHeartbeatRPS。 这条不是防手滑,是防「把保命通道配成断联成因」这个具体的失败模式。
func (*SystemSettings) BotRateLimitRegisterBurst ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitRegisterBurst() int
BotRateLimitRegisterBurst 在通用消毒之外再夹一道上界:`burst <= rps * 上限比值` (见 botRateLimitMaxRegisterFillRatio)。
这条不是防手滑,是防「收紧配额反而放大 keyspace」这个方向相反的失败模式: 令牌桶 key 的 TTL 是 `ceil(burst/rps * 2)`,而 register 的 key 由客户端提供的 token 决定基数,所以 live key 上界正比于 burst/rps。夹住比值即夹住上界。
夹紧后 rps 与 burst **不再独立**:调低 register_rps 会同时压低有效 burst。 这是刻意的——两者的比值是一个结构性量,不是两个自由参数。 有效值可在管理台的 Effective 列读到,不必靠猜。
func (*SystemSettings) BotRateLimitRegisterDryRun ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitRegisterDryRun() bool
func (*SystemSettings) BotRateLimitRegisterEnabled ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitRegisterEnabled() bool
func (*SystemSettings) BotRateLimitRegisterRPS ¶ added in v1.14.0
func (s *SystemSettings) BotRateLimitRegisterRPS() float64
BotRateLimitRegisterRPS 在通用消毒之外再夹一道下界:见 botRateLimitMinRegisterRPS。 与 BotRateLimitRegisterBurst 的比值上界成对,共同把令牌桶 key 的 TTL 钉成常数。
func (*SystemSettings) DmloopEnabled ¶ added in v1.10.0
func (s *SystemSettings) DmloopEnabled() bool
DmloopEnabled reports whether the Loop(回路)module entry should be shown to clients. Default false — the loop feature (backend service + fleet proxy + daemon runtimes) stays hidden until ops flips dmloop.enabled after those deps are deployed. Display policy only; /fleet auth lives in the backend.
func (*SystemSettings) DmpersonalEnabled ¶ added in v1.10.0
func (s *SystemSettings) DmpersonalEnabled() bool
DmpersonalEnabled reports whether the「我的/运行时」(personal) module entry should be shown. Kept separate from dmloop.enabled because 我的 will be redesigned to decouple from loop and may roll out on its own schedule.
func (*SystemSettings) DocsEnabled ¶ added in v1.8.1
func (s *SystemSettings) DocsEnabled() bool
DocsEnabled reports whether clients should surface the docs module (backed by the new octo-docs-backend service). This is a presentation toggle only: it gates client-side display of the docs entry and does not itself grant or enforce any server-side authorization. Default false so the module stays hidden until octo-docs-backend is live and the admin flips docs.enabled for a controlled rollout. Value source: system_setting docs.enabled (DB, hot-reloaded).
func (*SystemSettings) DocsSearchEnabled ¶ added in v1.13.0
func (s *SystemSettings) DocsSearchEnabled() bool
DocsSearchEnabled reports whether clients should surface cloud-doc full-text search. Decoupled from DocsEnabled: the search endpoint is provided independently by octo-docs-backend and may land later than the docs module itself. Display policy only — it neither grants nor enforces any server-side authorization, which lives in octo-docs-backend. Default false so the tab stays hidden until search is deployed and the index is populated and the admin flips docs.search_enabled for a controlled rollout. Value source: system_setting docs.search_enabled (DB, hot-reloaded).
func (*SystemSettings) DriveEnabled ¶ added in v1.13.0
func (s *SystemSettings) DriveEnabled() bool
DriveEnabled reports whether clients should surface the drive (网盘) module entry (backed by the standalone octo-drive service). Display policy only — it neither grants nor enforces any server-side authorization, which lives in octo-drive itself. Default false so the entry stays hidden until octo-drive is deployed and the admin flips drive.enabled for a controlled rollout. Value source: system_setting drive.enabled (DB, hot-reloaded).
func (*SystemSettings) DriveSearchEnabled ¶ added in v1.18.0
func (s *SystemSettings) DriveSearchEnabled() bool
DriveSearchEnabled reports whether clients should surface the "网盘" tab in the global-search modal. Decoupled from DriveEnabled: the search endpoint is provided independently by octo-drive-search and may land later than the drive module itself, or roll out independently under its own gray-release timeline. Display policy only — it neither grants nor enforces any server-side authorization, which lives in octo-drive-search (VisibleSpaces + VisibleDocs + baseFilters permission down-push). Default false so the tab stays hidden until search is deployed, the index is populated, and the admin flips drive.search_enabled for a controlled rollout. Value source: system_setting drive.search_enabled (DB, hot-reloaded).
func (*SystemSettings) DriveUploadLimits ¶ added in v1.22.0
func (s *SystemSettings) DriveUploadLimits() DriveUploadLimits
DriveUploadLimits 返回 Web 下发通道需要的 5 个字段(单次快照读),**不计算 policy_version** —— appconfig 不按版本缓存(06 4E / 01 §9-Q6),在未鉴权热路径 上做内容哈希没有客户端价值(reviewer yujiawei,PR #930 P2)。
值类型恒下发(06 冻结决策 1):快照从未加载时同样回落到默认值 + 天花板钳位; 「不可用」只在内部服务间通道上有意义,由 DriveUploadPolicyAvail 承担。
func (*SystemSettings) DriveUploadMaxSizeKB ¶ added in v1.22.0
func (s *SystemSettings) DriveUploadMaxSizeKB() int
DriveUploadMaxSizeKB 返回 drive 单文件上传上限(KB)。回退链只有 DB → code default 两层;越界处理与 sticker / file 那组键共用同一个钳位器。
快照从未加载时返回 min(默认, hardCap):这是 Web 下发通道要的「恒有一个值」, 不是「配置权威」的断言 —— 需要区分两者的调用方用 DriveUploadPolicyAvail。
func (*SystemSettings) DriveUploadPolicy ¶ added in v1.22.0
func (s *SystemSettings) DriveUploadPolicy() DriveUploadPolicy
DriveUploadPolicy 构造当前生效策略。
**单次快照读**:只依赖一个 DB 键 drive.upload_max_size_kb,全部字段出自 同一次 s.snapshot.Load() —— 不存在跨键二次 Load 拼出的撕裂组合(对比 FileStickerSizeOrdering 的两次 snapshot.Load())。分片参数与 hardCap 是静态 env,不是 DB 键。
快照从未成功加载时,返回由代码默认值拼出的策略。Web 下发通道的契约是「值 类型恒下发」(06 冻结决策 1),客户端自行按需回落,所以这里保持恒有值。需要 区分「快照不可用」的下游(内部服务间通道)改用 DriveUploadPolicyAvail。
func (*SystemSettings) DriveUploadPolicyAvail ¶ added in v1.22.0
func (s *SystemSettings) DriveUploadPolicyAvail() (DriveUploadPolicy, bool)
DriveUploadPolicyAvail 是 DriveUploadPolicy 的可用性感知版本:第二个返回值 ok 为 false 表示进程内 settings 快照**从未成功加载过**(DB 从未读通),此刻 返回的策略是代码默认值而非管理员配置。
这个区分对内部下发通道是 load-bearing 的:把「不可用配置」当成「合法策略」 以 200 + 正常 fingerprint 发给 octo-drive,会让 drive 侧据此抬升上限,破坏 fail-closed(设计 C2:本项目内部接口的错误契约含 503)。Web 通道不需要它 —— 那里恒下发值类型是刻意的。
一次快照读:ok 与策略 6 字段出自同一次 s.snapshot.Load()。
func (*SystemSettings) DriveUploadV2On ¶ added in v1.22.0
func (s *SystemSettings) DriveUploadV2On() bool
DriveUploadV2On reports whether clients should gray-enable the Drive chunked-upload (v2) front-end UI. Pure display / rollout policy: it controls only the ③/④ front-end multipart UI, NOT a server-side capability gate — the server gate is the request header X-Drive-Upload-Capabilities alone (contract-freeze 06 §1). Default false so the v2 UI stays hidden until ops flips drive.upload_v2_enabled for a controlled rollout. Value source: system_setting drive.upload_v2_enabled (DB, hot-reloaded). Downstream field name: appconfig drive_upload_v2_on.
func (*SystemSettings) FileExtraAllowedExtensions ¶ added in v1.17.0
func (s *SystemSettings) FileExtraAllowedExtensions() []string
FileExtraAllowedExtensions 返回**额外放开**的扩展名(每项含前导点、小写、 字典序)。语义是 env ∪ DB(D9):只增不减,管理台写入不会作废 env 里已放开 的格式。要收回某一项,把它写进 extra_blocked(黑名单优先级最高)。
返回值里会过滤掉内置黑名单项:正常写入路径已在写侧拦下它们,这里是给直改库 的旁路兜底,同时保证管理台 effective_value 不会显示一个「写着但不生效」的 扩展名 —— 那比不显示更误导。
本键是**追加**语义,空值 = 不追加 = baseline 全集,天然不会 dark-close (对比 StickerUploadAllowedFormats:那个键**替换**整个允许集,全部非法时必须 回退默认集才不至于把功能暗关)。
func (*SystemSettings) FileExtraBlockedExtensions ¶ added in v1.17.0
func (s *SystemSettings) FileExtraBlockedExtensions() []string
FileExtraBlockedExtensions 返回**额外封堵**的扩展名,语义是 env ∪ DB(D1)。 只增不减:DB 写入不会解封 env 里已封的项。返回值已去重并按字典序排序, 让 effective_value 回显稳定。
func (*SystemSettings) FileMaxSizeKB ¶ added in v1.17.0
func (s *SystemSettings) FileMaxSizeKB() int
FileMaxSizeKB 返回单文件上传上限(KB)。回退链只有 DB → code default 两层 (见 DefaultFileMaxSizeKB 的说明)。
越界处理与 sticker 那组键**共用同一个钳位器**:≤0 视为未配置、回落默认值; 超过硬上限则钳到硬上限,而不是回落默认值 —— 后者会让运维填 600000(想要 ~586MB)反而拿到 100MB,比编辑前还小、比键上写明的 512MB 还小,且写侧 Positive:true 跳过了范围检查,唯一的信号是 effective_value 悄悄读回 102400。 那正是本任务在 extra_allowed_extensions 上明确拒绝的「存下了但不生效」。
越界 Warn 由钳位器按 (key, value) 去重:本 getter 在 policyInputs() 里, 每次 currentPolicy() 都会走 —— 包括每个未认证的 /v1/common/appconfig 请求。
未配置的那一格刻意不走钳位器:天花板可以低于代码默认值 (OCTO_FILE_MAX_SIZE_KB_HARD_CAP < 100MB),把默认值喂进去会报 configured=102400,而 system_setting 表里一行都没有 —— 那是在诬告一次没有 发生过的变更,且每个 pod 都会打一条。回落值本身仍然要过天花板。
func (*SystemSettings) FileStickerSizeOrdering ¶ added in v1.17.0
func (s *SystemSettings) FileStickerSizeOrdering() FileStickerSizeOrdering
FileStickerSizeOrdering 读当前快照的组合值,供写侧守卫比较。
贴纸侧取的是 stickerUploadMaxSizeKBOwnBound()(只受贴纸自身硬上限约束), **不是**收敛后的 StickerUploadMaxSizeKB():后者已经 min 过全局上限,两侧 拿去比永远相等,守卫等于死代码。写侧要回答的问题是「运营配置的贴纸上限能 不能被兑现」,那要拿配置意图去比生效的全局上限。
注意这里是**两次**独立的 snapshot.Load()(两个 getter 各自 load 一次), 不是一次。中间落一次 Reload() 会拼出一个跨代组合。后果有界:影响的只是 一次写侧校验判定,读侧不受影响,与既有的 thread.auto_archive_days 守卫同形 态。要真正收口需要给 SystemSettings 加一个「一次快照读 N 个键」的原语, 那是共享配置机件的改动,留作独立任务。
func (*SystemSettings) GroupWelcomeEnabled ¶ added in v1.12.0
func (s *SystemSettings) GroupWelcomeEnabled() bool
GroupWelcomeEnabled is the platform master switch for the group new-member welcome (群入群欢迎语). Default false (dark launch): the feature ships off, and an operator flips onboarding.group_welcome_enabled to turn it on across every group. Flipping it back is an instant kill switch — the event path stops enqueuing and the send worker stops posting within the snapshot TTL — without touching any per-group config row. Read from the SAME snapshot as every other setting, so it hot-reloads and converges across replicas within reloadTTL.
Unlike the Space welcome's onboarding keys this is enablement ONLY: there is no platform-global content fallback, so a group's body always comes from its own row (see brief: no global fallback). The per-group config.Enabled still gates each group individually; this switch is the outer AND.
func (*SystemSettings) IncomingWebhookEnabled ¶ added in v1.6.0
func (s *SystemSettings) IncomingWebhookEnabled() bool
IncomingWebhookEnabled 是群入站 Webhook 功能的总开关。关闭后 push 端点返回 404、 管理写操作(create/update/delete/regenerate)被拒绝,仅保留 list 只读。 回退链:DB → env(DM_INCOMINGWEBHOOK_ENABLED) → 默认开启(true)。
func (*SystemSettings) IncomingWebhookMaxPerCreator ¶ added in v1.6.1
func (s *SystemSettings) IncomingWebhookMaxPerCreator() int
IncomingWebhookMaxPerCreator 单个普通成员/bot 在一个【投递作用域】(群本体或每个 子区)内可创建的 webhook 数量上限(群主/管理员豁免,仅受作用域级 max_per_group 约束)。DB → env → 默认 5。 读侧防御:≤0 回退默认(同 max_per_group,避免误配成"任何成员都建不了"的暗关)。
func (*SystemSettings) IncomingWebhookMaxPerGroup ¶ added in v1.6.0
func (s *SystemSettings) IncomingWebhookMaxPerGroup() int
IncomingWebhookMaxPerGroup 群本体作用域(thread_short_id=”)可创建的 webhook 数量上限。 子区作用域另用 IncomingWebhookMaxPerThread(未配置时回退到本值),两者独立计数、不共享 名额。DB → env → 默认 10。 读侧防御:≤0 回退默认(max_per_group=0 会让每次 create 都 ErrQuotaExceeded,是 总开关之外一种更难诊断的「暗关」)。
func (*SystemSettings) IncomingWebhookMaxPerThread ¶ added in v1.12.0
func (s *SystemSettings) IncomingWebhookMaxPerThread() int
IncomingWebhookMaxPerThread 单个【子区作用域】可创建的 webhook 数量上限,与群本体的 max_per_group 解耦,用于「群和子区分别精确设数量」。 DB(incomingwebhook.max_per_thread) → env(DM_INCOMINGWEBHOOK_MAX_PER_THREAD) → 回退到 IncomingWebhookMaxPerGroup()。即【未单独配置子区上限时,子区与群本体同额度】——与本 特性上线时「群/子区共用 max_per_group」的行为逐字节一致,配置向后兼容。 读侧防御:≤0 回退默认(同 max_per_group,避免误配成子区一个都建不了的「暗关」)。
func (*SystemSettings) IncomingWebhookMaxTotalPerGroup ¶ added in v1.12.0
func (s *SystemSettings) IncomingWebhookMaxTotalPerGroup() int
IncomingWebhookMaxTotalPerGroup 单个群【跨群本体 + 所有子区】的 webhook 聚合总数上限, 用于挡住「子区可无限创建 → 单群 webhook 总量 = 作用域上限 ×(子区数+1) 失控」。 DB(incomingwebhook.max_total_per_group) → env(DM_INCOMINGWEBHOOK_MAX_TOTAL_PER_GROUP) → 默认 0。 语义与作用域上限【不同】:0(或负)表示【不启用】聚合天花板——只受 max_per_group / max_per_thread 约束;仅当 > 0 时 insertWithQuota 才多做一次全群计数校验。因此读侧把 负值夹到 0(关闭)而非回退某默认值:0 是有意义的「关闭」哨兵,不是误配。
func (*SystemSettings) IncomingWebhookMemberCanBroadcast ¶ added in v1.7.0
func (s *SystemSettings) IncomingWebhookMemberCanBroadcast() bool
IncomingWebhookMemberCanBroadcast 控制【非管理员成员】创建的 webhook 是否可使用广播型 @(@所有人 / @所有 AI)。关闭后,成员建的 webhook 即便已置 allow_mention_* 能力位,其 广播也在 push 读路径被剥离(mention_ignored 回报);【管理员创建】的 webhook 不受影响。 因为是 push 读侧 AND(参见 incomingwebhook.buildMention),翻此开关可【即时收回】全部成员 广播、无需迁移存量列。回退链:DB → env(OCTO_INCOMINGWEBHOOK_MEMBER_CAN_BROADCAST) → 默认开启(true)。
func (*SystemSettings) IncomingWebhookPerWebhookBurst ¶ added in v1.6.0
func (s *SystemSettings) IncomingWebhookPerWebhookBurst() int
IncomingWebhookPerWebhookBurst 单个 webhook 令牌桶突发上限。DB → env → 默认 10。 读侧防御:≤0 回退默认(同 RPS,避免 `burst<=0` 短路静默关掉限流器)。
func (*SystemSettings) IncomingWebhookPerWebhookRPS ¶ added in v1.6.0
func (s *SystemSettings) IncomingWebhookPerWebhookRPS() float64
IncomingWebhookPerWebhookRPS 单个 webhook 令牌桶速率(rps)。DB → env → 默认 5。
读侧防御(D-289 同型,覆盖直接改库的旁路):rps 必须是正有限值;NaN/±Inf/≤0 一律 回退到 env/默认。否则 allowPerWebhook 的 `rps<=0` 短路会把限流器静默关掉,NaN 还会 让 Redis Lua 脚本报错而 fail-open——正是这个 getter 要兜住的。写侧也已拒绝 (settingTypeFloat + Positive,见 api_manager_system_setting.go),此处是纵深防御。
func (*SystemSettings) Load ¶ added in v1.3.0
func (s *SystemSettings) Load() error
Load reads every row from system_setting and atomically replaces the snapshot. It is the no-probe load used during startup and by write paths that already validated the prospective configuration synchronously.
func (*SystemSettings) LocalLoginOff ¶ added in v1.4.0
func (s *SystemSettings) LocalLoginOff() bool
LocalLoginOff returns whether local-account login entry points should be disabled. When true, frontend hides the local login UI and backend rejects requests to /v1/user/login, /v1/user/usernamelogin, /v1/user/emaillogin and their companion code-send endpoints. Password-recovery flows and third-party /SSO (GitHub, Gitee, OIDC) are not affected — this toggle is meant for deployments that have adopted SSO and want to force users through it.
Default false (no yaml fallback): plain self-hosted deployments without DB override keep the historical "local login enabled" behavior.
Safety override: even if the DB says local_off=1, this getter returns false when no third-party login (OIDC / GitHub / Gitee) is actually configured. Without the override an admin who flips the switch before wiring up an IdP would lock everyone — including themselves — out of the system. The override always picks "open" so the deployment stays accessible while ops fixes the missing SSO config. The hazard is surfaced via startup log (logLocalLoginOffSafetyOverride) so it isn't silently swallowed.
func (*SystemSettings) LogLocalLoginOffSafetyOverrideIfActive ¶ added in v1.4.0
func (s *SystemSettings) LogLocalLoginOffSafetyOverrideIfActive(localOff bool)
LogLocalLoginOffSafetyOverrideIfActive emits a single error-level log entry when local_off is intended to be on but no third-party login is configured — the exact state where LocalLoginOff() silently returns false to keep the deployment from locking itself. The log is the only signal ops have that the admin's intent is currently being overridden; without it the inconsistency is invisible until someone wonders why local login still works after flipping the switch.
Why localOff is a parameter, not read from snapshot here:
Callers know the intended value with stronger guarantees than the shared snapshot. The manager-write path can pass the just-validated request value (independent of whether Reload succeeded — PR #104 P2 from yujiawei). Startup passes the freshly-loaded snapshot value. Reading the snapshot directly inside this method would silently miss the warning when Reload fails right after a write, exactly when ops most needs the signal.
Callers: invoke once at server startup (Common.Route) after Load completes, and from the manager update handler after a write that touched login.local_off (passing the plan's value).
func (*SystemSettings) MailEnabled ¶ added in v1.16.0
func (s *SystemSettings) MailEnabled() bool
MailEnabled reports whether clients should surface the Agent Mail module. This is a presentation toggle only: Agent Mail authorization and access control remain enforced by octo-server and octo-mail. Default false so the entry is exposed only after an operator enables system_setting mail.enabled.
func (*SystemSettings) ManagerEmailMFAOn ¶ added in v1.17.0
func (s *SystemSettings) ManagerEmailMFAOn() bool
ManagerEmailMFAOn is the convenient boolean view for schema/appconfig rendering. Security-sensitive handlers must use ManagerEmailMFAState so an unavailable snapshot cannot collapse into false.
func (*SystemSettings) ManagerEmailMFAProbeGeneration ¶ added in v1.17.0
func (s *SystemSettings) ManagerEmailMFAProbeGeneration() uint64
ManagerEmailMFAProbeGeneration returns the generation of the effective MFA/SMTP snapshot. Callers that perform a probe outside this type must pass the captured value back to RecordManagerEmailMFAPreflight.
func (*SystemSettings) ManagerEmailMFAReady ¶ added in v1.17.0
func (s *SystemSettings) ManagerEmailMFAReady() bool
ManagerEmailMFAReady is the login gate's fail-closed view. It requires an enabled policy, a complete effective configuration, and a successful real SMTP preflight for that exact snapshot.
func (*SystemSettings) ManagerEmailMFAState ¶ added in v1.17.0
func (s *SystemSettings) ManagerEmailMFAState() ManagerEmailMFAState
ManagerEmailMFAState returns the security state used only by management console login. A successfully loaded snapshot with no row means the feature's documented default-off state; an uninitialized snapshot is unavailable and therefore fail-closed.
func (*SystemSettings) MessageReactionReadEnabled ¶ added in v1.12.0
func (s *SystemSettings) MessageReactionReadEnabled() bool
MessageReactionReadEnabled reports whether ordinary Web/iOS/Android clients should display message reactions. Read defaults on so existing reactions stay visible unless an operator explicitly disables message_reaction.read.
func (*SystemSettings) MessageReactionWriteEnabled ¶ added in v1.12.0
func (s *SystemSettings) MessageReactionWriteEnabled() bool
MessageReactionWriteEnabled reports whether ordinary Web/iOS/Android clients should expose add/cancel controls. Write defaults off for a staged rollout and can be enabled independently through message_reaction.write. These capability getters are presentation policy; server-side authorization stays independent.
func (*SystemSettings) OIDCInitialSpaceID ¶ added in v1.18.0
func (s *SystemSettings) OIDCInitialSpaceID() string
OIDCInitialSpaceID returns the space_id that an account created through the OIDC module is automatically joined to, or "" when the feature is off.
DB-only, no env fallback: unlike the register/login toggles this key has never had a yaml or env source, and adding one would give an operator two places to look when SSO users land outside every Space. The admin console (POST /v1/manager/common/system_setting) is the single source of truth, and its write path validates that the Space exists and is active.
The value is trimmed here rather than at the call sites: a space_id pasted out of the admin console routinely carries trailing whitespace, and an untrimmed value would silently miss on every lookup while reading as configured in the GET response. Empty (missing row, or a row explicitly blanked to turn the feature off) means the caller must not join anything.
func (*SystemSettings) PreflightManagerEmailMFA ¶ added in v1.17.0
func (s *SystemSettings) PreflightManagerEmailMFA(ctx context.Context) error
PreflightManagerEmailMFA sends a real probe through the same SMTP path used for OTP mail. It never changes the policy value and never panics; startup callers log the returned error and leave the login gate fail-closed.
func (*SystemSettings) ProfileContactInfoOn ¶ added in v1.21.0
func (s *SystemSettings) ProfileContactInfoOn() bool
ProfileContactInfoOn enables contact fields on authorized human profiles. Missing, empty or invalid settings keep the feature off. Both appconfig and the profile handler read this shared snapshot, so disabling it also stops peer contact disclosure without waiting for clients to refresh their config.
func (*SystemSettings) ProjectEnabled ¶ added in v1.19.0
func (s *SystemSettings) ProjectEnabled() bool
ProjectEnabled reports whether the Project collaboration module is on.
Unlike DocsEnabled and its siblings this is NOT a presentation-only toggle: it is the SAME switch modules/project enforces its write paths with (requireWriteEnabled). One source of truth is the point. Two switches — an env var for the server and a system_setting for the client — can disagree, and the disagreement is the worst possible shape: the client shows the Project entry and every write behind it returns 403.
Resolution order is DB → env → false, the same chain SpaceDisableUserCreate uses:
- a system_setting row wins, so an operator can flip the feature from the admin console with no restart (60s multi-instance convergence);
- with no row, the historical OCTO_PROJECT_CREATE_ENABLED still decides, so an existing deployment keeps behaving exactly as it does today;
- default false — fail-closed, as P0 shipped it.
What it does NOT do is relax invariant I2. Turning it off stops NEW projects and new project groups from being created; every existing project group keeps enforcing membership. That asymmetry is deliberate — the design brief is explicit that a rollback may stop production of project groups but must never loosen the constraint on the ones that exist.
func (*SystemSettings) ProjectEnabledOverride ¶ added in v1.19.0
func (s *SystemSettings) ProjectEnabledOverride() (value bool, found bool)
ProjectEnabledOverride reports the system_setting value and whether a row exists at all.
The distinction matters to modules/project, which resolved the env half once at construction and must keep doing so: with no row, the value it already holds decides, and this method's found=false says exactly that. Folding the two into a single bool would make "no row" indistinguishable from "row says false", which is how a feature that is ON via env silently turns OFF the first time someone opens the admin console.
func (*SystemSettings) RawLocalLoginOffFromSnapshot ¶ added in v1.4.0
func (s *SystemSettings) RawLocalLoginOffFromSnapshot() bool
RawLocalLoginOffFromSnapshot returns the snapshot's raw DB value for login.local_off without applying the SSO-safety override. Used by callers that need to feed LogLocalLoginOffSafetyOverrideIfActive at startup (the snapshot has just been loaded, so freshness isn't a concern). Exposed publicly because the field-level `getBool` is package-private and the only external need is this one logging path.
func (*SystemSettings) RecordManagerEmailMFAPreflight ¶ added in v1.17.0
func (s *SystemSettings) RecordManagerEmailMFAPreflight(generation uint64, ok bool) bool
RecordManagerEmailMFAPreflight lets a system-setting write path publish the result of a probe performed against the prospective (not-yet-reloaded) SMTP values. It refuses to publish a result captured for an older snapshot. It is intentionally tiny: callers still own the actual probe and this method never changes the MFA policy or snapshot.
func (*SystemSettings) RecordManagerEmailMFAPreflightIfMatches ¶ added in v1.17.0
func (s *SystemSettings) RecordManagerEmailMFAPreflightIfMatches(generation uint64, probed smtpSettingsSnapshot) bool
RecordManagerEmailMFAPreflightIfMatches publishes a successful write-path preflight only when the loaded snapshot still contains the exact SMTP values that were probed. The generation check rejects a newer snapshot; the value comparison also rejects a same-request reload that picked up a concurrent partial SMTP update whose final combination was never probed.
func (*SystemSettings) RegisterEmailOn ¶ added in v1.3.0
func (s *SystemSettings) RegisterEmailOn() bool
RegisterEmailOn returns whether email-based registration / login is enabled.
func (*SystemSettings) RegisterOff ¶ added in v1.3.0
func (s *SystemSettings) RegisterOff() bool
RegisterOff returns whether registration is globally disabled. DB value wins over cfg.Register.Off when set.
func (*SystemSettings) RegisterOnlyChina ¶ added in v1.3.0
func (s *SystemSettings) RegisterOnlyChina() bool
RegisterOnlyChina returns whether only China-region phone numbers may register.
func (*SystemSettings) RegisterUsernameOn ¶ added in v1.3.0
func (s *SystemSettings) RegisterUsernameOn() bool
RegisterUsernameOn returns whether username-based registration is enabled.
func (*SystemSettings) Reload ¶ added in v1.3.0
func (s *SystemSettings) Reload() error
Reload refreshes the snapshot and, when manager MFA/SMTP values changed, schedules one generation-bound SMTP preflight. This covers direct DB changes followed by Reload as well as instances that observe a peer change through the automatic reload loop. The manager settings write path uses Load instead because it already probes the merged prospective values before committing the transaction.
func (*SystemSettings) ScanLoginEnabled ¶ added in v1.14.0
func (s *SystemSettings) ScanLoginEnabled() bool
ScanLoginEnabled returns whether QR-code login is enabled deployment-wide.
Default false permits a server-first rollout without breaking clients that do not yet send poll_secret on redemption. Operators must explicitly enable scan login only after every client in the flow supports the hardened contract. Before the first successful settings load the snapshot is nil and this gate also fails closed; later reload failures retain the last successful snapshot.
func (*SystemSettings) SettingBoolOK ¶ added in v1.14.0
func (s *SystemSettings) SettingBoolOK(category, key string) (value bool, configured bool)
SettingBoolOK reports the configured bool for (category, key) and whether the key is configured at all.
getBool collapses "unset" and "explicitly false" into the same `false`, which is fine for a two-tier (DB → yaml) key but wrong for a caller that layers its own override on top of this one: a per-bot resolver must be able to tell "the deployment default says false" from "the deployment has no opinion, fall through to the code default". Hence the second return.
An unparseable literal reports configured=false so the caller falls through rather than inheriting a silent false — same fail-forward posture getBool takes with its fallback.
The literal is trimmed and matched case-insensitively, which getBool's parseSettingBool is not (round-3 evaluation P2-3). The reason is the fallback direction, not taste: this tier's callers layer their own code default on top, and for every key that uses it today (the bot card switches) that default is `true`. So an operator typing `False`, `FALSE ` or `\tfalse` into a system_setting row does not get "no opinion, keep the code default" in some harmless sense — they get **the capability they meant to disable left on**, with no error anywhere. Tolerant lexing removes the class.
Deliberately the same *vocabulary* as parseSettingBool (1/0/true/false), only lexed more forgivingly. Accepting on/off/yes/no here would make one column mean different things to two readers of the same table — the divergence pattern this module is meant to avoid, not a convenience.
**This tier is best-effort, not enforcement.** EnsureSystemSettings tolerates a failed startup Load() and leaves an empty snapshot for the auto-reload to repair, and an empty snapshot is indistinguishable here from "key not configured" — so a replica whose startup load blipped reports configured=false and its caller falls through to the code default for up to one reload TTL. A caller that layers a fail-closed control on top (see modules/robot's bot_setting resolver) fails closed only in ITS own tier; do not read that posture as covering this one. An operator who needs a capability genuinely disabled should set it at the layer that enforces, not only here.
func (*SystemSettings) SidebarRecentFilterGroupDays ¶ added in v1.6.0
func (s *SystemSettings) SidebarRecentFilterGroupDays() int
SidebarRecentFilterGroupDays returns the recent-tab activity window for group conversations, in days. 0 disables the window (all groups returned). Defaults to defaultSidebarRecentFilterGroupDays (3) — today's hard-coded behaviour.
func (*SystemSettings) SidebarRecentFilterPersonDays ¶ added in v1.6.0
func (s *SystemSettings) SidebarRecentFilterPersonDays() int
SidebarRecentFilterPersonDays returns the recent-tab activity window for DM conversations, in days. Defaults to 0, which keeps today's "DMs are always shown regardless of age" behaviour; the per-type default makes the historical hard-coded `!isDM` exemption data-driven.
func (*SystemSettings) SidebarRecentFilterThreadDays ¶ added in v1.6.0
func (s *SystemSettings) SidebarRecentFilterThreadDays() int
SidebarRecentFilterThreadDays returns the recent-tab activity window for thread (community topic) conversations, in days. 0 disables the window.
func (*SystemSettings) SpaceDisableUserCreate ¶ added in v1.5.0
func (s *SystemSettings) SpaceDisableUserCreate() bool
SpaceDisableUserCreate reports whether the user-facing「创建空间」入口应被 关闭。完整 fallback 链(按优先级):
- DB 行存在且 value 非空 → 走 getBool 解析(1/true/TRUE → true; 0/false/FALSE → false; 未知字面量 → false)。**不再回退到 env** —— 与 其他 bool 设置一致,未知字面量等同 "admin 不希望关闭"。
- DB 行不存在,或 value="" → env DM_SPACE_DISABLE_USER_CREATE
- 都缺失 → false (保持开放)
注:manager 写接口对 bool 值已做规范化(只接受 0/1/true/false 及大小写 变体),正常路径不会出现未知字面量;此规则覆盖的是有人绕过 API 直接改 DB 的边缘场景。
DB 是单一真源:admin 在管理台显式 toggle 立刻生效(Reload 内存快照), 多实例 60s 内收敛。env 仅作历史部署兼容入口;新部署应直接走 system_setting。
与 modules/space/api.go:IsUserCreateDisabled 保持等价语义 —— 后者仍是 env-only 的低层解析器,留给没有 ctx 的调用方与 yaml 模式;实际请求路径走本 方法(modules/space/api.go:createSpace)。
实现细节:DB 路径委托给 getBool 以与其他 bool 设置共享解析规则,避免双写 字面量集合(reviewer H1)。"DB 行是否存在"由独立 lookup 决定,从而区分 "DB 缺行 → env" 与 "DB 值=0 → 强制 false 压制 env" 两个语义。
func (*SystemSettings) SpaceWelcomeConfig ¶ added in v1.11.0
func (s *SystemSettings) SpaceWelcomeConfig() SpaceWelcomeConfig
SpaceWelcomeConfig returns the current tuple, all read from one snapshot.
func (*SystemSettings) StartAutoReload ¶ added in v1.3.0
func (s *SystemSettings) StartAutoReload(ctx context.Context)
StartAutoReload kicks off a goroutine that re-loads the snapshot every reloadTTL until ctx is canceled. 当前系统每 60 秒会执行一次自动 reload, 发现配置变化后更新本地快照。Intended to be called once at startup (with a long-lived context). Errors are logged but do not stop the loop.
Production callers pass context.Background() — the goroutine therefore runs for the lifetime of the process and shuts down with it. The ctx.Done() arm exists to make this swappable: if a server-shutdown context is ever plumbed through, no code change is needed here. The defer ticker.Stop() is reached only on that future cancellation; with context.Background() it is unreachable but kept so the function stays correct under either invocation.
func (*SystemSettings) StickerCompressEnabled ¶ added in v1.9.0
func (s *SystemSettings) StickerCompressEnabled() bool
StickerCompressEnabled reports whether server-side compression of static sticker images (jpg/png) is turned on. Default false — the feature is opt-in, greyed out until an operator flips this bit.
func (*SystemSettings) StickerCompressMaxConcurrency ¶ added in v1.9.0
func (s *SystemSettings) StickerCompressMaxConcurrency() int
StickerCompressMaxConcurrency returns the process-wide cap on concurrent sticker compressions. Read-side clamped to [1, stickerCompressMaxConcurrencyHardCap]; out-of-range falls back to 4.
func (*SystemSettings) StickerCompressMaxDimension ¶ added in v1.9.0
func (s *SystemSettings) StickerCompressMaxDimension() int
StickerCompressMaxDimension returns the target single-edge length the compressor downscales static jpg/png INTO (sticker-downscale-store / sticker-oversized-default). It is the SHRINK target the compressor's imaging.Fit fits into, decoupled from the upload dimension gate.
Read-side clamped to [1, stickerUploadMaxDimensionHardCap] (the 1024 decoded-pixel hard cap — the compressible-accept ceiling and the shrink target share that bound); unset / ≤0 / non-numeric falls back to the 512 default, which makes ">512 static jpg/png shrinks to 512" the built-in behavior once compression is enabled. NOT tied to upload_max_dimension: the dimension gate admits compressible formats up to the hard cap (see modules/file effectiveGateDim) and this value only decides how far they are shrunk before store.
func (*SystemSettings) StickerCompressTargetKB ¶ added in v1.9.0
func (s *SystemSettings) StickerCompressTargetKB() int
StickerCompressTargetKB returns the post-compression target size in KB. Read-side clamped to [1, stickerCompressTargetKBHardCap]; out-of-range falls back to the 1024 KB default.
func (*SystemSettings) StickerCompressTimeoutMs ¶ added in v1.9.0
func (s *SystemSettings) StickerCompressTimeoutMs() int
StickerCompressTimeoutMs returns the per-compression timeout in milliseconds. Read-side clamped to [1, stickerCompressTimeoutMsHardCap]; out-of-range falls back to 2000ms.
func (*SystemSettings) StickerCustomEnabled ¶ added in v1.8.0
func (s *SystemSettings) StickerCustomEnabled() bool
StickerCustomEnabled reports whether clients should show the custom-sticker management entry. This is a presentation toggle only; server-side CRUD authorization remains governed by the /v1/sticker/user route middleware and handler checks. Default false supports a controlled client rollout.
func (*SystemSettings) StickerHandleRequired ¶ added in v1.8.0
func (s *SystemSettings) StickerHandleRequired() bool
StickerHandleRequired reports whether custom-sticker registration must reject a missing upload handle (POST /v1/sticker/user). This is the enforcement POLICY, deliberately independent of the signing CAPABILITY (OCTO_MASTER_KEY): it lives in system_setting (DB, hot-reloaded) so it can be toggled from the admin console and converge across replicas within the snapshot TTL — a gradual, reversible rollout without a redeploy/restart. Default false (backward compatible: missing handles are allowed through during the compat window and only recorded). See modules/sticker classifyStickerPath and the appconfig sticker_handle_required bit.
func (*SystemSettings) StickerUploadAllowedFormats ¶ added in v1.9.0
func (s *SystemSettings) StickerUploadAllowedFormats() []string
StickerUploadAllowedFormats returns the sanitized set of allowed extensions (each including the leading dot, lowercased). It is intersected with the built-in raster allowlist (stickerUploadRasterAllowlist) so a mis-config can only narrow — never widen to non-raster (mp4/pdf/svg/...). If the config exists but the intersection is empty (all tokens illegal), the FULL default set is returned instead of an empty slice so a bad config cannot "dark-close" the feature; deployments narrow explicitly by writing a valid CSV.
Order of returned slice is deterministic for stability of callers that log or index it; tests sort before comparing regardless.
func (*SystemSettings) StickerUploadMaxDimension ¶ added in v1.9.0
func (s *SystemSettings) StickerUploadMaxDimension() int
StickerUploadMaxDimension returns the decoded-pixel single-edge cap. Read-side clamped to [1, stickerUploadMaxDimensionHardCap]; out-of-range falls back to the historical 512-px default.
func (*SystemSettings) StickerUploadMaxSizeKB ¶ added in v1.9.0
func (s *SystemSettings) StickerUploadMaxSizeKB() int
StickerUploadMaxSizeKB returns the per-file sticker upload cap in KB.
两道上界,缺一不可:
贴纸自身的产品硬上限 stickerUploadMaxSizeKBHardCap(5120,编译期常量) 当前生效的全局单文件上限 FileMaxSizeKB()(部署天花板 + 管理台值)
第二道是必须的,因为上传校验里**全局大小门在贴纸门之前** (modules/file/api.go),所以真正生效的贴纸上限本来就是 min(两者)。 不在这里收敛,这个事实就只有闸门知道:appconfig 会向客户端广播一个服务端 并不接受的值(客户端按它预校验、白传一次、拿到「文件过大」而不是贴纸文案), 管理台 effective_value 也会显示一个「写着但不生效」的数字 —— 正是本任务在 extra_allowed_extensions 上明确拒绝的失败形态。
天花板还是编译期常量 524288 时这一道是不可达的(贴纸最高 5120,clamp 永远 落不到它之下);OCTO_FILE_MAX_SIZE_KB_HARD_CAP 让天花板可以低于贴纸上限, 这条路径才打开。写侧的 D6 守卫按定义只在**发生写入**时运行,因此看不见 「空表 + 低天花板」这一格:读侧收敛是唯一能覆盖它的地方。
func (*SystemSettings) StickerUserMaxCount ¶ added in v1.8.0
func (s *SystemSettings) StickerUserMaxCount() int
StickerUserMaxCount is the maximum number of custom stickers a single user may keep. Read-side defence: a non-positive value (only reachable via a direct DB edit — the admin write path enforces Positive) falls back to the default rather than silently locking the user out of adding any sticker.
func (*SystemSettings) SupportEmail ¶ added in v1.3.0
func (s *SystemSettings) SupportEmail() string
SupportEmail returns the From address used by the SMTP sender.
func (*SystemSettings) SupportEmailPwd ¶ added in v1.3.0
func (s *SystemSettings) SupportEmailPwd() string
SupportEmailPwd returns the (decrypted) SMTP password. If the stored ciphertext fails to decrypt at Load time, the snapshot omits the key and this getter returns the yaml fallback.
func (*SystemSettings) SupportEmailSmtp ¶ added in v1.3.0
func (s *SystemSettings) SupportEmailSmtp() string
SupportEmailSmtp returns the SMTP host:port endpoint.
func (*SystemSettings) ThreadArchiveOrdering ¶ added in v1.14.0
func (s *SystemSettings) ThreadArchiveOrdering() ThreadArchiveOrdering
ThreadArchiveOrdering snapshots the currently-effective ordering inputs so a partial admin write can be validated against merge(current, incoming).
func (*SystemSettings) ThreadAutoArchiveDays ¶ added in v1.14.0
func (s *SystemSettings) ThreadAutoArchiveDays() int
ThreadAutoArchiveDays returns the inactivity threshold, in days, after which a quiet 子区 is archived. 0 disables the time threshold while leaving the worker enabled — the env semantics this key inherits (RunOnce short-circuits on Threshold<=0), preserved deliberately so existing DM_THREAD_AUTO_ARCHIVE_DAYS=0 deployments keep their meaning.
func (*SystemSettings) ThreadAutoArchiveEnabled ¶ added in v1.14.0
func (s *SystemSettings) ThreadAutoArchiveEnabled() bool
ThreadAutoArchiveEnabled reports whether the 子区 auto-archive worker should sweep. Resolution chain: system_setting row → env DM_THREAD_AUTO_ARCHIVE_ENABLED → code default (false).
The env layer is what makes this migration a no-op on rollout: no row is written to system_setting, so every deployment keeps resolving to exactly the value its env already produces. An admin write later overrides it, and the worker picks that up within one tick.
func (*SystemSettings) TrackingEnabled ¶ added in v1.15.0
func (s *SystemSettings) TrackingEnabled() bool
TrackingEnabled reports whether the frontend event-tracking layer (octo-dap) should collect. Default false — the tracker ships dark (fail-closed): octo-web only starts collecting when appconfig delivers tracking_enabled truthy, so ops keeps this off until the octo-dap collector is deployed and the TRACK_API_URL egress is verified in-cluster. Display/behaviour policy only; the collector enforces its own auth. Value source: system_setting tracking.enabled (DB, hot-reloaded — flip in the admin console, 60s multi-instance converge, no restart). Delivered via GET /v1/common/appconfig as tracking_enabled.
func (*SystemSettings) ValidateManagerEmailMFASMTP ¶ added in v1.17.0
func (s *SystemSettings) ValidateManagerEmailMFASMTP() error
ValidateManagerEmailMFASMTP checks the effective SMTP values without doing network I/O. Callers that are about to enable the policy must follow it with PreflightManagerEmailMFA so the actual delivery path is exercised too.
type ThreadArchiveOrdering ¶ added in v1.14.0
ThreadArchiveOrdering is the merged view the two-stage-decay guard validates: the global archive window versus the recent-tab thread window.
func ApplyThreadArchiveOrderingOverlay ¶ added in v1.14.0
func ApplyThreadArchiveOrderingOverlay(cur ThreadArchiveOrdering, incoming map[string]string) ThreadArchiveOrdering
ApplyThreadArchiveOrderingOverlay merges an incoming admin batch onto the current snapshot, producing the state that will be in effect once the batch commits. Keys absent from `incoming` keep their current value.
The subtle part is the empty payload. For settingTypeInt an empty value is the documented "reset to default" (the getter treats an empty snapshot entry as not-configured), and normaliseBool accepts "" for bools with the same meaning. Carrying the CURRENT value forward for those would under-detect: clearing thread.auto_archive_days while it sits above the recent window resets it to env/code default and can land below the window — precisely the state the guard exists to reject. So "" resolves through the same env → code-default chain the getters will use after the write.
Exported and pure so the merge can be unit-tested without an HTTP round-trip.
Source Files
¶
- 1module.go
- api.go
- api_manager.go
- api_manager_system_setting.go
- api_manager_system_setting_file.go
- db.go
- db_app_config.go
- db_shortno.go
- db_system_setting.go
- drive_upload_policy.go
- emoji.go
- group_welcome_config_store.go
- health.go
- key_encryption.go
- service.go
- space_welcome_config_store.go
- system_setting_metrics.go
- system_setting_schema.go
- system_settings.go
- system_settings_drive_upload.go
- system_settings_file_upload.go