refactor: migrate router and controller methods to use Fizz package

- Updated router groups to utilize the new crawlab-team/fizz package for improved routing capabilities.
- Refactored controller methods to accept Fizz router groups, enhancing consistency and maintainability.
- Simplified route registration by incorporating OpenAPI metadata directly into group definitions.
- Improved error handling and response generation in sync controller methods for better clarity.
- Enhanced overall code structure by standardizing route definitions and improving parameter handling.
This commit is contained in:
Marvin Zhang
2025-03-17 12:50:50 +08:00
parent 06ad8fc7b0
commit 4dace3ce8e
3 changed files with 57 additions and 73 deletions

View File

@@ -3,34 +3,23 @@ package controllers
import (
"path/filepath"
"github.com/crawlab-team/crawlab/core/entity"
"github.com/crawlab-team/crawlab/core/utils"
"github.com/gin-gonic/gin"
)
type GetSyncScanParams struct {
Id string `path:"id" validate:"required"`
Path string `query:"path"`
}
func GetSyncScan(_ *gin.Context, params *GetSyncScanParams) (response *Response[map[string]entity.FsFileInfo], err error) {
func GetSyncScan(c *gin.Context) {
workspacePath := utils.GetWorkspace()
dirPath := filepath.Join(workspacePath, params.Id, params.Path)
dirPath := filepath.Join(workspacePath, c.Param("id"), c.Param("path"))
files, err := utils.ScanDirectory(dirPath)
if err != nil {
return GetErrorResponse[map[string]entity.FsFileInfo](err)
HandleErrorInternalServerError(c, err)
return
}
return GetDataResponse(files)
HandleSuccessWithData(c, files)
}
type GetSyncDownloadParams struct {
Id string `path:"id" validate:"required"`
Path string `query:"path" validate:"required"`
}
func GetSyncDownload(c *gin.Context, params *GetSyncDownloadParams) (err error) {
func GetSyncDownload(c *gin.Context) {
workspacePath := utils.GetWorkspace()
filePath := filepath.Join(workspacePath, params.Id, params.Path)
filePath := filepath.Join(workspacePath, c.Param("id"), c.Param("path"))
c.File(filePath)
return nil
}