feat: select encoding for decompressing zip file

pull/1232/head
HFO4 3 years ago
parent cb51046305
commit 86876a1c11

@ -20,8 +20,9 @@ type DecompressTask struct {
// DecompressProps 压缩任务属性 // DecompressProps 压缩任务属性
type DecompressProps struct { type DecompressProps struct {
Src string `json:"src"` Src string `json:"src"`
Dst string `json:"dst"` Dst string `json:"dst"`
Encoding string `json:"encoding"`
} }
// Props 获取任务属性 // Props 获取任务属性
@ -82,7 +83,7 @@ func (job *DecompressTask) Do() {
job.TaskModel.SetProgress(DecompressingProgress) job.TaskModel.SetProgress(DecompressingProgress)
err = fs.Decompress(context.Background(), job.TaskProps.Src, job.TaskProps.Dst, "") err = fs.Decompress(context.Background(), job.TaskProps.Src, job.TaskProps.Dst, job.TaskProps.Encoding)
if err != nil { if err != nil {
job.SetErrorMsg("解压缩失败", err) job.SetErrorMsg("解压缩失败", err)
return return
@ -91,12 +92,13 @@ func (job *DecompressTask) Do() {
} }
// NewDecompressTask 新建压缩任务 // NewDecompressTask 新建压缩任务
func NewDecompressTask(user *model.User, src, dst string) (Job, error) { func NewDecompressTask(user *model.User, src, dst, encoding string) (Job, error) {
newTask := &DecompressTask{ newTask := &DecompressTask{
User: user, User: user,
TaskProps: DecompressProps{ TaskProps: DecompressProps{
Src: src, Src: src,
Dst: dst, Dst: dst,
Encoding: encoding,
}, },
} }

@ -99,7 +99,7 @@ func TestNewDecompressTask(t *testing.T) {
mock.ExpectBegin() mock.ExpectBegin()
mock.ExpectExec("INSERT(.+)").WillReturnResult(sqlmock.NewResult(1, 1)) mock.ExpectExec("INSERT(.+)").WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit() mock.ExpectCommit()
job, err := NewDecompressTask(&model.User{}, "/", "/") job, err := NewDecompressTask(&model.User{}, "/", "/", "utf-8")
asserts.NoError(mock.ExpectationsWereMet()) asserts.NoError(mock.ExpectationsWereMet())
asserts.NotNil(job) asserts.NotNil(job)
asserts.NoError(err) asserts.NoError(err)
@ -110,7 +110,7 @@ func TestNewDecompressTask(t *testing.T) {
mock.ExpectBegin() mock.ExpectBegin()
mock.ExpectExec("INSERT(.+)").WillReturnError(errors.New("error")) mock.ExpectExec("INSERT(.+)").WillReturnError(errors.New("error"))
mock.ExpectRollback() mock.ExpectRollback()
job, err := NewDecompressTask(&model.User{}, "/", "/") job, err := NewDecompressTask(&model.User{}, "/", "/", "utf-8")
asserts.NoError(mock.ExpectationsWereMet()) asserts.NoError(mock.ExpectationsWereMet())
asserts.Nil(job) asserts.Nil(job)
asserts.Error(err) asserts.Error(err)

@ -55,8 +55,9 @@ type ItemCompressService struct {
// ItemDecompressService 文件解压缩任务服务 // ItemDecompressService 文件解压缩任务服务
type ItemDecompressService struct { type ItemDecompressService struct {
Src string `json:"src"` Src string `json:"src"`
Dst string `json:"dst" binding:"required,min=1,max=65535"` Dst string `json:"dst" binding:"required,min=1,max=65535"`
Encoding string `json:"encoding"`
} }
// ItemPropertyService 获取对象属性服务 // ItemPropertyService 获取对象属性服务
@ -143,7 +144,7 @@ func (service *ItemDecompressService) CreateDecompressTask(c *gin.Context) seria
} }
// 创建任务 // 创建任务
job, err := task.NewDecompressTask(fs.User, service.Src, service.Dst) job, err := task.NewDecompressTask(fs.User, service.Src, service.Dst, service.Encoding)
if err != nil { if err != nil {
return serializer.Err(serializer.CodeNotSet, "任务创建失败", err) return serializer.Err(serializer.CodeNotSet, "任务创建失败", err)
} }

Loading…
Cancel
Save