|
@@ -94,14 +94,14 @@ func DownloadOSSFile(ctx context.Context, c *app.RequestContext) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// DownLoadZipFile 根据请求id从oss拉取并打包下载建图所需要的文件
|
|
|
|
|
|
+// DownloadMapZipFile 根据请求id从oss拉取并打包下载建图所需要的文件
|
|
// @router /map/downloadmapzipfile [GET]
|
|
// @router /map/downloadmapzipfile [GET]
|
|
-func DownLoadMapZipFile(ctx context.Context, c *app.RequestContext) {
|
|
|
|
|
|
+func DownloadMapZipFile(ctx context.Context, c *app.RequestContext) {
|
|
id := c.Query("id")
|
|
id := c.Query("id")
|
|
fmt.Println(id)
|
|
fmt.Println(id)
|
|
|
|
|
|
// 根据id生成用于地图更新的压缩包
|
|
// 根据id生成用于地图更新的压缩包
|
|
- filePath, tmpDir, err := generateZipById(id)
|
|
|
|
|
|
+ filePath, tmpDir, err := generateMapZipById(id)
|
|
if err != nil {
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
|
c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
|
}
|
|
}
|
|
@@ -137,9 +137,9 @@ func DownLoadMapZipFile(ctx context.Context, c *app.RequestContext) {
|
|
defer os.RemoveAll(tmpDir)
|
|
defer os.RemoveAll(tmpDir)
|
|
}
|
|
}
|
|
|
|
|
|
-// DownLoadMapBagFile 根据请求id从oss拉取并下载解析后的map.bag文件
|
|
|
|
|
|
+// DownloadMapBagFile 根据请求id从oss拉取并下载解析后的map.bag文件
|
|
// @router /map/downloadmapbagfile [GET]
|
|
// @router /map/downloadmapbagfile [GET]
|
|
-func DownLoadMapBagFile(ctx context.Context, c *app.RequestContext) {
|
|
|
|
|
|
+func DownloadMapBagFile(ctx context.Context, c *app.RequestContext) {
|
|
id := c.Query("id")
|
|
id := c.Query("id")
|
|
fmt.Println("id: ", id)
|
|
fmt.Println("id: ", id)
|
|
|
|
|
|
@@ -177,12 +177,12 @@ func DownLoadMapBagFile(ctx context.Context, c *app.RequestContext) {
|
|
}
|
|
}
|
|
|
|
|
|
// 根据id生成用于地图更新的压缩包
|
|
// 根据id生成用于地图更新的压缩包
|
|
-func generateZipById(id string) (file string, tmpDir string, err error) {
|
|
|
|
|
|
+func generateMapZipById(id string) (file string, tmpDir string, err error) {
|
|
// 根据id获取对应的oss文件列表
|
|
// 根据id获取对应的oss文件列表
|
|
allFileList, err := util.GetExactedMapFileById(id)
|
|
allFileList, err := util.GetExactedMapFileById(id)
|
|
|
|
|
|
// 过滤特定后缀的文件列表
|
|
// 过滤特定后缀的文件列表
|
|
- mapBuFileList := util.FilterBySuffixes(allFileList, config.MapBufFiltersuffixes...)
|
|
|
|
|
|
+ mapBufFileList := util.FilterBySuffixes(allFileList, config.MapBufFiltersuffixes...)
|
|
//fmt.Println("Filtered Strings:", fileList)
|
|
//fmt.Println("Filtered Strings:", fileList)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -242,7 +242,7 @@ func generateZipById(id string) (file string, tmpDir string, err error) {
|
|
c_log.GlobalLogger.Info("下载文件到bag_folder文件夹 - 成功")
|
|
c_log.GlobalLogger.Info("下载文件到bag_folder文件夹 - 成功")
|
|
|
|
|
|
// 从oss下载文件到 mapBuf 文件夹
|
|
// 从oss下载文件到 mapBuf 文件夹
|
|
- for _, file := range mapBuFileList {
|
|
|
|
|
|
+ for _, file := range mapBufFileList {
|
|
err = config.OssBucket.GetObjectToFile(file, filepath.Join(mapBufDir, filepath.Base(file)))
|
|
err = config.OssBucket.GetObjectToFile(file, filepath.Join(mapBufDir, filepath.Base(file)))
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("Error downloading mapBuf file:", err)
|
|
fmt.Println("Error downloading mapBuf file:", err)
|
|
@@ -276,7 +276,7 @@ func generateZipById(id string) (file string, tmpDir string, err error) {
|
|
defer zipWriter.Close()
|
|
defer zipWriter.Close()
|
|
|
|
|
|
// 压缩文件夹
|
|
// 压缩文件夹
|
|
- if err := addDirToZip(baseDir, zipWriter); err != nil {
|
|
|
|
|
|
+ if err := util.AddDirToZip(baseDir, zipWriter); err != nil {
|
|
fmt.Println("Error adding directory to ZIP:", err)
|
|
fmt.Println("Error adding directory to ZIP:", err)
|
|
return "", "", err
|
|
return "", "", err
|
|
}
|
|
}
|
|
@@ -299,47 +299,3 @@ func calculateTotalFileSize(fileList []string) int {
|
|
}
|
|
}
|
|
return totalSize
|
|
return totalSize
|
|
}
|
|
}
|
|
-
|
|
|
|
-// 压缩文件夹
|
|
|
|
-func addDirToZip(dirPath string, zipWriter *zip.Writer) error {
|
|
|
|
- filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if info.IsDir() {
|
|
|
|
- return nil
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- file, err := os.Open(path)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- defer file.Close()
|
|
|
|
-
|
|
|
|
- // 处理路径,确保保留相对路径结构
|
|
|
|
- relPath, err := filepath.Rel(dirPath, path)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- header, err := zip.FileInfoHeader(info)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- header.Name = filepath.ToSlash(relPath)
|
|
|
|
-
|
|
|
|
- writer, err := zipWriter.CreateHeader(header)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if _, err := io.Copy(writer, file); err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return nil
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- return nil
|
|
|
|
-}
|
|
|