MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / handleLocalApp

Function handleLocalApp

agent/app/service/app_utils.go:1446–1505  ·  view source on GitHub ↗
(appDir string)

Source from the content-addressed store, hash-verified

1444}
1445
1446func handleLocalApp(appDir string) (app *model.App, err error) {
1447 fileOp := files.NewFileOp()
1448 configYamlPath := path.Join(appDir, "data.yml")
1449 if !fileOp.Stat(configYamlPath) {
1450 err = buserr.WithName("ErrFileNotFound", "data.yml")
1451 return
1452 }
1453 iconPath := path.Join(appDir, "logo.png")
1454 if !fileOp.Stat(iconPath) {
1455 err = buserr.WithName("ErrFileNotFound", "logo.png")
1456 return
1457 }
1458 configYamlByte, err := fileOp.GetContent(configYamlPath)
1459 if err != nil {
1460 err = buserr.WithMap("ErrFileParseApp", map[string]interface{}{"name": "data.yml", "err": err.Error()}, err)
1461 return
1462 }
1463 localAppDefine := dto.LocalAppAppDefine{}
1464 if err = yaml.Unmarshal(configYamlByte, &localAppDefine); err != nil {
1465 err = buserr.WithMap("ErrFileParseApp", map[string]interface{}{"name": "data.yml", "err": err.Error()}, err)
1466 return
1467 }
1468 appDefine := localAppDefine.AppProperty
1469 app = &model.App{}
1470 app.Name = appDefine.Name
1471 app.TagsKey = append(appDefine.Tags, "Local")
1472 app.Type = appDefine.Type
1473 app.CrossVersionUpdate = appDefine.CrossVersionUpdate
1474 app.Limit = appDefine.Limit
1475 app.Recommend = appDefine.Recommend
1476 app.Website = appDefine.Website
1477 app.Github = appDefine.Github
1478 app.Document = appDefine.Document
1479 if appDefine.ShortDescZh != "" {
1480 appDefine.Description.Zh = appDefine.ShortDescZh
1481 }
1482 if appDefine.ShortDescEn != "" {
1483 appDefine.Description.En = appDefine.ShortDescEn
1484 }
1485 desc, _ := json.Marshal(appDefine.Description)
1486 app.Description = string(desc)
1487 app.Key = "local" + appDefine.Key
1488 app.Architectures = strings.Join(appDefine.Architectures, ",")
1489 app.GpuSupport = appDefine.GpuSupport
1490 app.MemoryRequired = appDefine.MemoryRequired
1491
1492 app.Resource = constant.AppResourceLocal
1493 app.Status = constant.AppNormal
1494 app.Recommend = 9999
1495 readMeByte, err := fileOp.GetContent(path.Join(appDir, "README.md"))
1496 if err == nil {
1497 app.ReadMe = string(readMeByte)
1498 }
1499 iconByte, _ := fileOp.GetContent(iconPath)
1500 if iconByte != nil {
1501 iconStr := base64.StdEncoding.EncodeToString(iconByte)
1502 app.Icon = iconStr
1503 }

Callers 1

SyncAppListFromLocalMethod · 0.85

Calls 3

StatMethod · 0.95
GetContentMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected