MCPcopy Index your code
hub / github.com/TruthHun/DocHub / DocumentProcess

Function DocumentProcess

models/Utils.go:20–209  ·  view source on GitHub ↗

文档处理

(uid int, form FormUpload)

Source from the content-addressed store, hash-verified

18
19// 文档处理
20func DocumentProcess(uid int, form FormUpload) (err error) {
21 // 1. 计算文档 md5
22 // 2. 判断文档是否合法
23 // 3. 存入 document_store
24 // 4. 存入 document
25 // 5. 存入 document_info
26 // 6. 文档分类数量增加 category 表
27 // 7. 总文档数增加
28 // 8. 用户积分和文档数量增加
29 // 9. 积分记录
30
31 sys, _ := NewSys().Get()
32 score := 0 // 文档已被上传的话,获得的积分为0
33
34 var doc = &Document{
35 Title: form.Title,
36 Filename: form.Filename,
37 Keywords: form.Tags,
38 Description: form.Intro,
39 }
40
41 o := orm.NewOrm()
42 o.Begin()
43 defer func() {
44 if err != nil {
45 o.Rollback()
46 os.Remove(form.TmpFile)
47 } else {
48 o.Commit()
49 if helper.Debug {
50 beego.Debug("============")
51 beego.Debug("form: %+v", form)
52 beego.Debug("doc: %+v", doc)
53 beego.Debug("============")
54 }
55 if score > 0 {
56 go DocumentConvert(form.TmpFile, form.Md5, sys.PreviewPage)
57 }
58 go func() {
59 if errIndex := NewElasticSearchClient().BuildIndexById(doc.Id); err != nil {
60 helper.Logger.Error("重建索引失败:%v", errIndex.Error())
61 }
62 }()
63 }
64 }()
65
66 var (
67 errForbidden = errors.New("您上传的文档已被管理员禁止上传")
68 errRetry = errors.New("文档上传失败,请重新上传")
69 errRepeatedDoc = errors.New("您要分享的文档已存在,请勿再次分享")
70 )
71
72 var file *os.File
73 file, err = os.Open(form.TmpFile)
74 if err == nil {
75 defer file.Close()
76 form.Md5 = helper.ComputeFileMD5(file)
77 }

Callers

nothing calls this directly

Calls 13

NewSysFunction · 0.85
DocumentConvertFunction · 0.85
NewElasticSearchClientFunction · 0.85
GetTableDocumentStoreFunction · 0.85
GetTableCategoryFunction · 0.85
GetTableSysFunction · 0.85
GetTableUserInfoFunction · 0.85
BuildIndexByIdMethod · 0.80
IsExistByMd5Method · 0.80
IsIllegalMethod · 0.80
OneMethod · 0.80
InsertMethod · 0.80

Tested by

no test coverage detected