(appID uint, version, appType string)
| 232 | } |
| 233 | |
| 234 | func (a AppService) GetAppDetail(appID uint, version, appType string) (response.AppDetailDTO, error) { |
| 235 | var ( |
| 236 | appDetailDTO response.AppDetailDTO |
| 237 | opts []repo.DBOption |
| 238 | ) |
| 239 | opts = append(opts, appDetailRepo.WithAppId(appID), appDetailRepo.WithVersion(version)) |
| 240 | detail, err := appDetailRepo.GetFirst(opts...) |
| 241 | if err != nil { |
| 242 | return appDetailDTO, err |
| 243 | } |
| 244 | appDetailDTO.AppDetail = detail |
| 245 | appDetailDTO.Enable = true |
| 246 | |
| 247 | if appType == "runtime" { |
| 248 | app, err := appRepo.GetFirst(repo.WithByID(appID)) |
| 249 | if err != nil { |
| 250 | return appDetailDTO, err |
| 251 | } |
| 252 | fileOp := files.NewFileOp() |
| 253 | |
| 254 | versionPath := filepath.Join(app.GetAppResourcePath(), detail.Version) |
| 255 | if !fileOp.Stat(versionPath) || detail.Update { |
| 256 | if err = downloadApp(app, detail, nil, nil); err != nil && !fileOp.Stat(versionPath) { |
| 257 | return appDetailDTO, err |
| 258 | } |
| 259 | } |
| 260 | switch app.Type { |
| 261 | case constant.RuntimePHP: |
| 262 | paramsPath := filepath.Join(versionPath, "data.yml") |
| 263 | if !fileOp.Stat(paramsPath) { |
| 264 | return appDetailDTO, buserr.WithDetail("ErrFileNotExist", paramsPath, nil) |
| 265 | } |
| 266 | param, err := fileOp.GetContent(paramsPath) |
| 267 | if err != nil { |
| 268 | return appDetailDTO, err |
| 269 | } |
| 270 | paramMap := make(map[string]interface{}) |
| 271 | if err = yaml.Unmarshal(param, ¶mMap); err != nil { |
| 272 | return appDetailDTO, err |
| 273 | } |
| 274 | appDetailDTO.Params = paramMap["additionalProperties"] |
| 275 | composePath := filepath.Join(versionPath, "docker-compose.yml") |
| 276 | if !fileOp.Stat(composePath) { |
| 277 | return appDetailDTO, buserr.WithDetail("ErrFileNotExist", composePath, nil) |
| 278 | } |
| 279 | compose, err := fileOp.GetContent(composePath) |
| 280 | if err != nil { |
| 281 | return appDetailDTO, err |
| 282 | } |
| 283 | composeMap := make(map[string]interface{}) |
| 284 | if err := yaml.Unmarshal(compose, &composeMap); err != nil { |
| 285 | return appDetailDTO, err |
| 286 | } |
| 287 | if service, ok := composeMap["services"]; ok { |
| 288 | servicesMap := service.(map[string]interface{}) |
| 289 | for k := range servicesMap { |
| 290 | appDetailDTO.Image = k |
| 291 | } |
nothing calls this directly
no test coverage detected