Files
crawlab/core/controllers/sync.go
Marvin Zhang 23cad00d92 refactor: streamline controller methods and enhance parameter handling
- Refactored multiple controller methods to accept structured parameters for improved clarity and maintainability.
- Consolidated error handling and response generation across various endpoints.
- Updated function signatures to eliminate unnecessary context parameters and enhance type safety.
- Improved consistency in response formatting and error handling across controllers.
- Enhanced file handling methods to support multipart file uploads and directory operations more effectively.
2025-03-13 17:37:30 +08:00

37 lines
1018 B
Go

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) {
workspacePath := utils.GetWorkspace()
dirPath := filepath.Join(workspacePath, params.Id, params.Path)
files, err := utils.ScanDirectory(dirPath)
if err != nil {
return GetErrorResponse[map[string]entity.FsFileInfo](err)
}
return GetDataResponse(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) {
workspacePath := utils.GetWorkspace()
filePath := filepath.Join(workspacePath, params.Id, params.Path)
c.File(filePath)
return nil
}