mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
feat(附件管理): 完善附件管理功能
This commit is contained in:
1 parent
418a2fa0a7
commit
38004171cf
10 files changed
+254
-42
No files matched your search
+24
-1
@@ -14,7 +14,11 @@
|
||||
|
||||
package ofdgo
|
||||
|
||||
import "encoding/xml"
|
||||
import (
|
||||
"encoding/xml"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Document 文档结构
|
||||
type Document struct {
|
||||
@@ -226,6 +230,25 @@ func (doc *Document) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// FileName 获取另存文件名,优先使用带扩展名的显示名称,剔除目录及文件名非法字符
|
||||
// 返回: string 文件名
|
||||
func (a Attachment) FileName() string {
|
||||
name := path.Base(strings.ReplaceAll(a.Name, "\\", "/"))
|
||||
file := path.Base(strings.ReplaceAll(a.FileLoc, "\\", "/"))
|
||||
if name == "." || name == "/" || path.Ext(name) == "" && path.Ext(file) != "" {
|
||||
name = file
|
||||
}
|
||||
if name == "." || name == "/" {
|
||||
name = "attachment"
|
||||
}
|
||||
return strings.Map(func(r rune) rune {
|
||||
if r < 32 || strings.ContainsRune(`<>:"/\|?*`, r) {
|
||||
return '_'
|
||||
}
|
||||
return r
|
||||
}, name)
|
||||
}
|
||||
|
||||
// UnmarshalXML 解析附件并应用默认值
|
||||
// 入参: d XML解码器, start 起始节点
|
||||
// 返回: error 错误信息
|
||||
|
||||
Reference in new issue
Block a user