Files
dify-plus/admin/server/utils/app_version_infer.go
T
npc0-hue df9bed2950 fear: admin添加app应用版本管理
system-features添加
2026-02-09 09:11:58 +08:00

46 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package utils
import "strings"
// InferPlatformArch 根据安装包文件名推断 platform 与 arch
// 返回 platform (darwin|win32|linux), arch (x64|arm64)
// Windows 安装包通常为一个 exe 同时支持 arm/amd64,统一存为 win32+x64,客户端请求 win32 时返回该包
func InferPlatformArch(filename string) (platform, arch string) {
name := strings.ToLower(filename)
// .dmg → macOS
if strings.HasSuffix(name, ".dmg") {
platform = "darwin"
if strings.Contains(name, "arm64") || strings.Contains(name, "aarch64") {
arch = "arm64"
} else if strings.Contains(name, "x64") || strings.Contains(name, "amd64") || strings.Contains(name, "x86_64") {
arch = "x64"
} else {
arch = "arm64" // 默认 Apple Silicon
}
return
}
// .exe → Windows,不区分架构,统一 x64
if strings.HasSuffix(name, ".exe") {
platform = "win32"
arch = "x64"
return
}
// .deb → Linux
if strings.HasSuffix(name, ".deb") {
platform = "linux"
if strings.Contains(name, "arm64") || strings.Contains(name, "aarch64") {
arch = "arm64"
} else {
arch = "x64" // amd64
}
return
}
// .AppImage → Linux,一般为 x64(已转小写故 .appimage
if strings.HasSuffix(name, ".appimage") {
platform = "linux"
arch = "x64"
return
}
return "", ""
}