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 压缩任务属性
type DecompressProps struct {
Src string `json:"src"`
Dst string `json:"dst"`
Src string `json:"src"`
Dst string `json:"dst"`
Encoding string `json:"encoding"`
}
// Props 获取任务属性
@ -82,7 +83,7 @@ func (job *DecompressTask) Do() {
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 {
job.SetErrorMsg("解压缩失败", err)
return
@ -91,12 +92,13 @@ func (job *DecompressTask) Do() {
}
// NewDecompressTask 新建压缩任务
func NewDecompressTask(user *model.User, src, dst string) (Job, error) {
func NewDecompressTask(user *model.User, src, dst, encoding string) (Job, error) {
newTask := &DecompressTask{
User: user,
TaskProps: DecompressProps{
Src: src,
Dst: dst,
Src: src,
Dst: dst,
Encoding: encoding,
},
}

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

@ -55,8 +55,9 @@ type ItemCompressService struct {
// ItemDecompressService 文件解压缩任务服务
type ItemDecompressService struct {
Src string `json:"src"`
Dst string `json:"dst" binding:"required,min=1,max=65535"`
Src string `json:"src"`
Dst string `json:"dst" binding:"required,min=1,max=65535"`
Encoding string `json:"encoding"`
}
// 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 {
return serializer.Err(serializer.CodeNotSet, "任务创建失败", err)
}

Loading…
Cancel
Save