mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 08:46:55 +08:00
1 parent
07eb44c037
commit
341ad7cd7e
4 files changed
+72
-27
No files matched your search
@@ -52,7 +52,15 @@ func (e *Editor) AddAttachment(name string, data []byte) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
id := strconv.Itoa(maximum + 1)
|
||||
attachments, err := base.reader.Attachments()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
used := make(map[string]bool, len(attachments))
|
||||
for _, attachment := range attachments {
|
||||
used[attachment.ID] = true
|
||||
}
|
||||
id, maximum := nextAttachmentID(used, maximum)
|
||||
file := e.packageName("Attachments/Attachment_" + id)
|
||||
attrs := ofdAttrs{}
|
||||
attrs.add("ID", id)
|
||||
@@ -121,10 +129,24 @@ func (e *Editor) AddAttachment(name string, data []byte) (string, error) {
|
||||
if err := e.commitAnnotationParts(base, parts); err != nil {
|
||||
return "", err
|
||||
}
|
||||
e.maxID, e.source.idsReady = maximum+1, true
|
||||
e.maxID, e.source.idsReady = maximum, true
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// nextAttachmentID 分配以字母开头且不与已有附件重复的标识
|
||||
// 入参: used 已用附件标识, maximum 当前编号上限
|
||||
// 返回: string 附件标识, int 更新后的编号上限
|
||||
func nextAttachmentID(used map[string]bool, maximum int) (string, int) {
|
||||
for {
|
||||
maximum++
|
||||
id := "a" + strconv.Itoa(maximum)
|
||||
if !used[id] {
|
||||
used[id] = true
|
||||
return id, maximum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RenameAttachment 修改附件显示名称,保留格式、内容及扩展字段,相同名称不产生撤销记录
|
||||
// 入参: id 附件标识, name 显示名称
|
||||
// 返回: error 名称或附件结构错误
|
||||
|
||||
Reference in new issue
Block a user