Files
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

82 lines
2.9 KiB
Go

package utils
import (
"os"
"strconv"
)
const (
defaultMaxFileSizeMB = 50
// maxFileSizeMBCeiling is the supported single-file transfer ceiling. A
// deployment still needs the same value configured in nginx, docreader and
// the browser runtime; the application refuses larger values consistently.
maxFileSizeMBCeiling = 20 * 1024
defaultMaxSkillBundleSizeMB = 256
// maxSkillBundleSizeMBCeiling matches the install-time uncompressed
// archive cap: a download larger than that cannot become a valid skill.
maxSkillBundleSizeMBCeiling = 512
)
// GetMaxFileSize returns the maximum file upload size in bytes.
// Default is 50MB, can be configured via MAX_FILE_SIZE_MB environment variable.
//
// MAX_FILE_SIZE_MB is intentionally a deploy-time-only knob (NOT a
// runtime system_setting). The effective upload limit is gated by
// three other layers that all read this env at startup and cache the
// value:
// - frontend nginx client_max_body_size (envsubst into nginx.conf)
// - docreader gRPC max_send/recv_message_length
// - frontend client-side check via window.__RUNTIME_CONFIG__
//
// Surfacing a SystemAdmin UI knob whose effect is silently capped by
// any of the above would mislead operators ("I raised it to 200MB but
// nginx still returns 413"). Until all four layers can be reconfigured
// in lockstep without container restarts, every call site must read
// the env directly via this helper.
func GetMaxFileSize() int64 {
return GetMaxFileSizeMB() * 1024 * 1024
}
// GetMaxFileSizeMB returns the maximum file upload size in MB. Same
// caveat as GetMaxFileSize — handlers should prefer SystemSettingService.GetInt.
func GetMaxFileSizeMB() int64 {
value := envSizeMB("MAX_FILE_SIZE_MB", defaultMaxFileSizeMB)
if value > maxFileSizeMBCeiling {
return maxFileSizeMBCeiling
}
return value
}
// GetMaxSkillBundleSize is the compressed zip / source-download cap for
// skills. Knowledge uploads stay on GetMaxFileSize: packages such as
// ppt-master exceed 50MB, but raising the document limit would also
// inflate docreader gRPC messages. A GitHub zipball is the whole
// repository archive, not the SKILL.md subtree, so a huge monorepo can
// still be refused here even when the skill itself is small.
func GetMaxSkillBundleSize() int64 {
return GetMaxSkillBundleSizeMB() * 1024 * 1024
}
// GetMaxSkillBundleSizeMB returns the skill zip cap in MB.
// MAX_SKILL_BUNDLE_SIZE_MB defaults to 256, is never below MAX_FILE_SIZE_MB,
// and is capped at 512.
func GetMaxSkillBundleSizeMB() int64 {
skillMB := envSizeMB("MAX_SKILL_BUNDLE_SIZE_MB", defaultMaxSkillBundleSizeMB)
if fileMB := GetMaxFileSizeMB(); skillMB < fileMB {
skillMB = fileMB
}
if skillMB > maxSkillBundleSizeMBCeiling {
return maxSkillBundleSizeMBCeiling
}
return skillMB
}
func envSizeMB(key string, fallback int64) int64 {
if sizeStr := os.Getenv(key); sizeStr != "" {
if size, err := strconv.ParseInt(sizeStr, 10, 64); err == nil && size > 0 {
return size
}
}
return fallback
}