mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
528240026d
- make format 现在与 code-check 使用同一格式化器(golangci-lint fmt),消除 goimports -local 与 gofumpt 的格式拉锯 - .golangci.yml 关闭默认 50/3 截断,完整上报所有问题(只增强不弱化) - 全库 gofumpt 规范化(203 files, 纯格式无行为变更)
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package stats maintains incremental upload statistics and aggregations.
|
|
package stats
|
|
|
|
import (
|
|
"Wavelet/plugins/domain/upload/util"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
catImage = "图片"
|
|
catVideo = "视频"
|
|
catAudio = "音频"
|
|
catDocument = "文档"
|
|
catArchive = "压缩包"
|
|
catOther = "其他"
|
|
)
|
|
|
|
// GetFileCategory classifies a file by mime type and extension.
|
|
func GetFileCategory(mimeType, ext string) string {
|
|
mimeType = strings.ToLower(mimeType)
|
|
ext = strings.ToLower(ext)
|
|
|
|
if strings.HasPrefix(mimeType, "image/") || util.IsImageExtension(ext) {
|
|
return catImage
|
|
}
|
|
if strings.HasPrefix(mimeType, "video/") {
|
|
return catVideo
|
|
}
|
|
if strings.HasPrefix(mimeType, "audio/") {
|
|
return catAudio
|
|
}
|
|
if util.IsArchiveExtension(ext) || strings.Contains(mimeType, "zip") || strings.Contains(mimeType, "tar") || strings.Contains(mimeType, "gzip") {
|
|
return catArchive
|
|
}
|
|
if util.IsDocumentExtension(ext) || strings.HasPrefix(mimeType, "text/") || mimeType == "application/pdf" {
|
|
return catDocument
|
|
}
|
|
return catOther
|
|
}
|