mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-26 17:49:15 +01:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user