mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: Application details have been enhanced with tags. (#7777)
Refs https://github.com/1Panel-dev/1Panel/issues/7774
This commit is contained in:
parent
aaaa5980b5
commit
57bfc38eb8
@ -23,9 +23,9 @@ type AppUpdateRes struct {
|
|||||||
|
|
||||||
type AppDTO struct {
|
type AppDTO struct {
|
||||||
model.App
|
model.App
|
||||||
Installed bool `json:"installed"`
|
Installed bool `json:"installed"`
|
||||||
Versions []string `json:"versions"`
|
Versions []string `json:"versions"`
|
||||||
Tags []model.Tag `json:"tags"`
|
Tags []TagDTO `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppItem struct {
|
type AppItem struct {
|
||||||
|
@ -49,7 +49,7 @@ func (i *App) GetDescription(ctx *gin.Context) string {
|
|||||||
var translations = make(map[string]string)
|
var translations = make(map[string]string)
|
||||||
_ = json.Unmarshal([]byte(i.Description), &translations)
|
_ = json.Unmarshal([]byte(i.Description), &translations)
|
||||||
lang := strings.ToLower(common.GetLang(ctx))
|
lang := strings.ToLower(common.GetLang(ctx))
|
||||||
if desc, ok := translations[lang]; ok {
|
if desc, ok := translations[lang]; ok && desc != "" {
|
||||||
return desc
|
return desc
|
||||||
}
|
}
|
||||||
if lang == "zh" {
|
if lang == "zh" {
|
||||||
|
@ -104,39 +104,11 @@ func (a AppService) PageApp(ctx *gin.Context, req request.AppSearch) (interface{
|
|||||||
}
|
}
|
||||||
appDTO.Description = ap.GetDescription(ctx)
|
appDTO.Description = ap.GetDescription(ctx)
|
||||||
appDTOs = append(appDTOs, appDTO)
|
appDTOs = append(appDTOs, appDTO)
|
||||||
appTags, err := appTagRepo.GetByAppId(ap.ID)
|
tags, err := getAppTags(ap.ID, lang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
return nil, err
|
||||||
}
|
|
||||||
var tagIds []uint
|
|
||||||
for _, at := range appTags {
|
|
||||||
tagIds = append(tagIds, at.TagId)
|
|
||||||
}
|
|
||||||
tags, err := tagRepo.GetByIds(tagIds)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, t := range tags {
|
|
||||||
if t.Name != "" {
|
|
||||||
tagDTO := response.TagDTO{
|
|
||||||
ID: t.ID,
|
|
||||||
Key: t.Key,
|
|
||||||
Name: t.Name,
|
|
||||||
}
|
|
||||||
appDTO.Tags = append(appDTO.Tags, tagDTO)
|
|
||||||
} else {
|
|
||||||
var translations = make(map[string]string)
|
|
||||||
_ = json.Unmarshal([]byte(t.Translations), &translations)
|
|
||||||
if name, ok := translations[lang]; ok {
|
|
||||||
tagDTO := response.TagDTO{
|
|
||||||
ID: t.ID,
|
|
||||||
Key: t.Key,
|
|
||||||
Name: name,
|
|
||||||
}
|
|
||||||
appDTO.Tags = append(appDTO.Tags, tagDTO)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
appDTO.Tags = tags
|
||||||
installs, _ := appInstallRepo.ListBy(appInstallRepo.WithAppId(ap.ID))
|
installs, _ := appInstallRepo.ListBy(appInstallRepo.WithAppId(ap.ID))
|
||||||
appDTO.Installed = len(installs) > 0
|
appDTO.Installed = len(installs) > 0
|
||||||
}
|
}
|
||||||
@ -185,7 +157,11 @@ func (a AppService) GetApp(ctx *gin.Context, key string) (*response.AppDTO, erro
|
|||||||
versionsRaw = append(versionsRaw, detail.Version)
|
versionsRaw = append(versionsRaw, detail.Version)
|
||||||
}
|
}
|
||||||
appDTO.Versions = common.GetSortedVersions(versionsRaw)
|
appDTO.Versions = common.GetSortedVersions(versionsRaw)
|
||||||
|
tags, err := getAppTags(app.ID, strings.ToLower(common.GetLang(ctx)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
appDTO.Tags = tags
|
||||||
return &appDTO, nil
|
return &appDTO, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1607,3 +1607,41 @@ func RequestDownloadCallBack(downloadCallBackUrl string) {
|
|||||||
}
|
}
|
||||||
_, _, _ = httpUtil.HandleGet(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
|
_, _, _ = httpUtil.HandleGet(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAppTags(appID uint, lang string) ([]response.TagDTO, error) {
|
||||||
|
appTags, err := appTagRepo.GetByAppId(appID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var tagIds []uint
|
||||||
|
for _, at := range appTags {
|
||||||
|
tagIds = append(tagIds, at.TagId)
|
||||||
|
}
|
||||||
|
tags, err := tagRepo.GetByIds(tagIds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var res []response.TagDTO
|
||||||
|
for _, t := range tags {
|
||||||
|
if t.Name != "" {
|
||||||
|
tagDTO := response.TagDTO{
|
||||||
|
ID: t.ID,
|
||||||
|
Key: t.Key,
|
||||||
|
Name: t.Name,
|
||||||
|
}
|
||||||
|
res = append(res, tagDTO)
|
||||||
|
} else {
|
||||||
|
var translations = make(map[string]string)
|
||||||
|
_ = json.Unmarshal([]byte(t.Translations), &translations)
|
||||||
|
if name, ok := translations[lang]; ok {
|
||||||
|
tagDTO := response.TagDTO{
|
||||||
|
ID: t.ID,
|
||||||
|
Key: t.Key,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
res = append(res, tagDTO)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user