返回 DeepSeek-Reasonix
attachments.go
根目录 / internal / config / attachments.go
1 package config
2
3 // DefaultAttachmentStreamBytes bounds disk consumption by one streamed file.
4 const DefaultAttachmentStreamBytes int64 = 1 << 30
5
6 // AttachmentsConfig contains user-only limits for ordinary file uploads.
7 type AttachmentsConfig struct {
8 MaxStreamBytes *int64 `toml:"max_stream_bytes,omitempty"`
9 }
10
11 // AttachmentLimit records the effective byte ceiling and its configuration owner.
12 type AttachmentLimit struct {
13 Bytes int64
14 Source string
15 }
16
17 // AttachmentStreamLimit defaults to 1 GiB; an explicit user zero is unlimited.
18 func (c *Config) AttachmentStreamLimit() AttachmentLimit {
19 if c == nil || c.Attachments.MaxStreamBytes == nil || *c.Attachments.MaxStreamBytes < 0 {
20 return AttachmentLimit{Bytes: DefaultAttachmentStreamBytes, Source: "default"}
21 }
22 return AttachmentLimit{Bytes: *c.Attachments.MaxStreamBytes, Source: "user"}
23 }
24
25 // LoadAttachmentStreamLimit strictly reads the user's selected config without
26 // project declarations, credentials, migrations, or recovery to wider defaults.
27 func LoadAttachmentStreamLimit() (AttachmentLimit, error) {
28 cfg, err := loadForEditStrict(userConfigLoadPath(), false, false)
29 if err != nil {
30 return AttachmentLimit{}, err
31 }
32 return cfg.AttachmentStreamLimit(), nil
33 }
34
34 lines GO