- 将文档上传分为两个阶段:插入数据库记录和调用 Python API - 修改了 Doc 模型的 InsertDocumentData 方法,返回插入记录的 ID 和状态 - 在控制器中处理了插入数据库失败的情况 - 保留了 TODO 注释,以便后续继续开发
33 lines
849 B
Go
33 lines
849 B
Go
package web
|
|
|
|
import (
|
|
"catface/app/global/consts"
|
|
"catface/app/global/variable"
|
|
"catface/app/model"
|
|
"catface/app/utils/response"
|
|
"path/filepath"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Docs struct {
|
|
}
|
|
|
|
func (d *Docs) Upload(context *gin.Context) {
|
|
// STAGE 1. 插入 MySQL 记录。
|
|
var doc_id int64
|
|
ok := false
|
|
if doc_id, ok = model.CreateDocFactory("").InsertDocumentData(context); !ok {
|
|
response.Fail(context, consts.CurdCreatFailCode, consts.CurdCreatFailMsg, "上传文档错误")
|
|
}
|
|
|
|
// STAGE 2. 调用 python API
|
|
path := context.GetString(consts.ValidatorPrefix + "path")
|
|
filePath := filepath.Join(variable.ConfigYml.GetString("FileUploadSetting.UploadFileSavePath"), variable.ConfigYml.GetString("FileUploadSetting.DocsRootPath"), path)
|
|
|
|
// TODO
|
|
_ = filePath
|
|
_ = doc_id
|
|
response.Success(context, consts.CurdStatusOkMsg, "")
|
|
}
|