@Summary copy or move file @Produce application/json @Accept application/json @Tags file @Security ApiKeyAuth @Param body body model.FileOperate true "type:move,copy" @Success 200 {string} string "ok" @Router /file/operate [post]
(ctx echo.Context)
| 642 | // @Success 200 {string} string "ok" |
| 643 | // @Router /file/operate [post] |
| 644 | func PostOperateFileOrDir(ctx echo.Context) error { |
| 645 | list := model.FileOperate{} |
| 646 | ctx.Bind(&list) |
| 647 | |
| 648 | if len(list.Item) == 0 { |
| 649 | return ctx.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) |
| 650 | } |
| 651 | if list.To == list.Item[0].From[:strings.LastIndex(list.Item[0].From, "/")] { |
| 652 | return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SOURCE_DES_SAME, Message: common_err.GetMsg(common_err.SOURCE_DES_SAME)}) |
| 653 | } |
| 654 | |
| 655 | var total int64 = 0 |
| 656 | for i := 0; i < len(list.Item); i++ { |
| 657 | |
| 658 | size, err := file.GetFileOrDirSize(list.Item[i].From) |
| 659 | if err != nil { |
| 660 | continue |
| 661 | } |
| 662 | list.Item[i].Size = size |
| 663 | total += size |
| 664 | if list.Type == "move" { |
| 665 | mounted := service.IsMounted(list.Item[i].From) |
| 666 | if mounted { |
| 667 | return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.MOUNTED_DIRECTIORIES, Message: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES), Data: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES)}) |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | list.TotalSize = total |
| 673 | list.ProcessedSize = 0 |
| 674 | |
| 675 | uid := uuid.NewString() |
| 676 | service.FileQueue.Store(uid, list) |
| 677 | service.OpStrArr = append(service.OpStrArr, uid) |
| 678 | if len(service.OpStrArr) == 1 { |
| 679 | go service.ExecOpFile() |
| 680 | go service.CheckFileStatus() |
| 681 | |
| 682 | go service.MyService.Notify().SendFileOperateNotify(false) |
| 683 | |
| 684 | } |
| 685 | |
| 686 | return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)}) |
| 687 | } |
| 688 | |
| 689 | // @Summary delete file |
| 690 | // @Produce application/json |
nothing calls this directly
no test coverage detected