@Summary upload file @Produce application/json @Accept application/json @Tags file @Security ApiKeyAuth @Param path formData string false "file path" @Param file formData file true "file" @Success 200 {string} string "ok" @Router /file/upload [get]
(ctx echo.Context)
| 454 | // @Success 200 {string} string "ok" |
| 455 | // @Router /file/upload [get] |
| 456 | func GetFileUpload(ctx echo.Context) error { |
| 457 | relative := ctx.QueryParam("relativePath") |
| 458 | fileName := ctx.QueryParam("filename") |
| 459 | chunkNumber := ctx.QueryParam("chunkNumber") |
| 460 | totalChunks, _ := strconv.Atoi(utils.DefaultQuery(ctx, "totalChunks", "0")) |
| 461 | path := ctx.QueryParam("path") |
| 462 | dirPath := "" |
| 463 | hash := file.GetHashByContent([]byte(fileName)) |
| 464 | if file.Exists(path + "/" + relative) { |
| 465 | return ctx.JSON(http.StatusConflict, model.Result{Success: http.StatusConflict, Message: common_err.GetMsg(common_err.FILE_ALREADY_EXISTS)}) |
| 466 | } |
| 467 | tempDir := filepath.Join(path, ".temp", hash+strconv.Itoa(totalChunks)) + "/" |
| 468 | if fileName != relative { |
| 469 | dirPath = strings.TrimSuffix(relative, fileName) |
| 470 | tempDir += dirPath |
| 471 | file.MkDir(path + "/" + dirPath) |
| 472 | } |
| 473 | tempDir += chunkNumber |
| 474 | if !file.CheckNotExist(tempDir) { |
| 475 | return ctx.JSON(200, model.Result{Success: 200, Message: common_err.GetMsg(common_err.FILE_ALREADY_EXISTS)}) |
| 476 | } |
| 477 | |
| 478 | return ctx.JSON(204, model.Result{Success: 204, Message: common_err.GetMsg(common_err.SUCCESS)}) |
| 479 | } |
| 480 | |
| 481 | // @Summary upload file |
| 482 | // @Produce application/json |
nothing calls this directly
no test coverage detected