作者 yangfu

fix: 封面

@@ -65,7 +65,7 @@ func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniAr @@ -65,7 +65,7 @@ func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniAr
65 Id: backupList[i].Id, 65 Id: backupList[i].Id,
66 Title: "", 66 Title: "",
67 Content: "", 67 Content: "",
68 - Images: []string{}, 68 + Images: backupList[i].GetImages(),
69 Videos: []types.Video{}, 69 Videos: []types.Video{},
70 CreatedAt: backupList[i].CreatedAt, 70 CreatedAt: backupList[i].CreatedAt,
71 Location: types.Location{ 71 Location: types.Location{
@@ -52,14 +52,10 @@ func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSea @@ -52,14 +52,10 @@ func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSea
52 } 52 }
53 53
54 func NewArticle(article *domain.Article) types.ArticleSearchMe { 54 func NewArticle(article *domain.Article) types.ArticleSearchMe {
55 - images := []string{}  
56 - for _, val2 := range article.Images {  
57 - images = append(images, val2.Url)  
58 - }  
59 articleSearchMe := types.ArticleSearchMe{ 55 articleSearchMe := types.ArticleSearchMe{
60 Id: article.Id, 56 Id: article.Id,
61 Title: article.Title, 57 Title: article.Title,
62 - Images: images, 58 + Images: article.GetImages(),
63 CreatedAt: article.CreatedAt, 59 CreatedAt: article.CreatedAt,
64 CountLove: article.CountLove, 60 CountLove: article.CountLove,
65 CountComment: article.CountComment, 61 CountComment: article.CountComment,
@@ -71,7 +71,7 @@ func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.Mini @@ -71,7 +71,7 @@ func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.Mini
71 Template: draftList[i].Template, 71 Template: draftList[i].Template,
72 //Section: draftList[i].Content, 72 //Section: draftList[i].Content,
73 Title: draftList[i].Title, 73 Title: draftList[i].Title,
74 - Images: images, 74 + Images: draftList[i].GetImages(),
75 CreatedAt: draftList[i].CreatedAt, 75 CreatedAt: draftList[i].CreatedAt,
76 MatchUrl: draftList[i].MatchUrl, 76 MatchUrl: draftList[i].MatchUrl,
77 Paragraphs: paragraphs, 77 Paragraphs: paragraphs,
@@ -73,7 +73,7 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch @@ -73,7 +73,7 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
73 AuthorId: val.AuthorId, 73 AuthorId: val.AuthorId,
74 Author: author.Name, 74 Author: author.Name,
75 Avatar: author.Avatar, 75 Avatar: author.Avatar,
76 - Images: []string{}, 76 + Images: val.GetImages(),
77 CreatedAt: val.CreatedAt, 77 CreatedAt: val.CreatedAt,
78 MeReadFlag: 0, 78 MeReadFlag: 0,
79 Cover: val.GetCover(), 79 Cover: val.GetCover(),
@@ -82,9 +82,6 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch @@ -82,9 +82,6 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
82 if _, ok := readFlag[val.Id]; ok { 82 if _, ok := readFlag[val.Id]; ok {
83 item.MeReadFlag = 1 83 item.MeReadFlag = 1
84 } 84 }
85 - for _, img := range val.Images {  
86 - item.Images = append(item.Images, img.Url)  
87 - }  
88 resp.List[i] = item 85 resp.List[i] = item
89 } 86 }
90 87
@@ -67,7 +67,7 @@ func (l *SystemSearchArticleDraftLogic) SystemSearchArticleDraft(req *types.Syst @@ -67,7 +67,7 @@ func (l *SystemSearchArticleDraftLogic) SystemSearchArticleDraft(req *types.Syst
67 resp.List = append(resp.List, types.SystemArticleDraftSearch{ 67 resp.List = append(resp.List, types.SystemArticleDraftSearch{
68 Id: item.Id, 68 Id: item.Id,
69 Title: item.Title, 69 Title: item.Title,
70 - Images: images, 70 + Images: item.GetImages(),
71 Operator: item.Operator.Name, 71 Operator: item.Operator.Name,
72 AuthorId: item.AuthorId, 72 AuthorId: item.AuthorId,
73 Author: author, 73 Author: author,
@@ -54,11 +54,6 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS @@ -54,11 +54,6 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
54 //获取标签 54 //获取标签
55 _, tags, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions()) 55 _, tags, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions())
56 lo.ForEach(articles, func(item *domain.Article, index int) { 56 lo.ForEach(articles, func(item *domain.Article, index int) {
57 - //图片  
58 - images := make([]string, 0)  
59 - lo.ForEach(item.Images, func(img domain.Image, n int) {  
60 - images = append(images, img.Url)  
61 - })  
62 //发布人 57 //发布人
63 author := item.Author.Name 58 author := item.Author.Name
64 for _, user := range users { 59 for _, user := range users {
@@ -80,7 +75,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS @@ -80,7 +75,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
80 Title: item.Title, 75 Title: item.Title,
81 AuthorId: item.AuthorId, 76 AuthorId: item.AuthorId,
82 Author: author, 77 Author: author,
83 - Images: images, 78 + Images: item.GetImages(),
84 CreatedAt: item.CreatedAt, 79 CreatedAt: item.CreatedAt,
85 UpdatedAt: item.UpdatedAt, 80 UpdatedAt: item.UpdatedAt,
86 CountLove: item.CountLove, 81 CountLove: item.CountLove,
@@ -62,7 +62,7 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * @@ -62,7 +62,7 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *
62 Title: item.Title, 62 Title: item.Title,
63 Summary: item.Summary, 63 Summary: item.Summary,
64 Time: item.CreatedAt, 64 Time: item.CreatedAt,
65 - Images: make([]string, 0), 65 + Images: item.GetImages(),
66 ReadFlag: false, 66 ReadFlag: false,
67 Cover: item.GetCover(), 67 Cover: item.GetCover(),
68 } 68 }
@@ -73,9 +73,6 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * @@ -73,9 +73,6 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp *
73 Avatar: lo.ToPtr(author.Avatar), 73 Avatar: lo.ToPtr(author.Avatar),
74 } 74 }
75 } 75 }
76 - for _, img := range item.Images {  
77 - newsItem.Images = append(newsItem.Images, img.Url)  
78 - }  
79 if _, ok := readArticlesMap[item.Id]; ok { 76 if _, ok := readArticlesMap[item.Id]; ok {
80 newsItem.ReadFlag = true 77 newsItem.ReadFlag = true
81 } 78 }
@@ -186,6 +186,18 @@ func (m *Article) GetCover() string { @@ -186,6 +186,18 @@ func (m *Article) GetCover() string {
186 return "" 186 return ""
187 } 187 }
188 188
  189 +func (m *Article) GetImages() []string {
  190 + cover := m.GetCover()
  191 + var result = make([]string, 0)
  192 + for _, img := range m.Images {
  193 + result = append(result, img.Url)
  194 + }
  195 + if len(result) == 0 && len(cover) > 0 {
  196 + result = append(result, cover)
  197 + }
  198 + return result
  199 +}
  200 +
189 func (m *Article) GetCoverWithSections(list []*ArticleSection) string { 201 func (m *Article) GetCoverWithSections(list []*ArticleSection) string {
190 if len(m.Cover) > 0 { 202 if len(m.Cover) > 0 {
191 return m.Cover 203 return m.Cover
@@ -212,3 +212,15 @@ func (m *ArticleBackup) GetCover() string { @@ -212,3 +212,15 @@ func (m *ArticleBackup) GetCover() string {
212 } 212 }
213 return "" 213 return ""
214 } 214 }
  215 +
  216 +func (m *ArticleBackup) GetImages() []string {
  217 + cover := m.GetCover()
  218 + var result = make([]string, 0)
  219 + for _, img := range m.Images {
  220 + result = append(result, img.Url)
  221 + }
  222 + if len(result) == 0 && len(cover) > 0 {
  223 + result = append(result, cover)
  224 + }
  225 + return result
  226 +}
@@ -47,3 +47,15 @@ func (m *ArticleDraft) GetCover() string { @@ -47,3 +47,15 @@ func (m *ArticleDraft) GetCover() string {
47 } 47 }
48 return "" 48 return ""
49 } 49 }
  50 +
  51 +func (m *ArticleDraft) GetImages() []string {
  52 + cover := m.GetCover()
  53 + var result = make([]string, 0)
  54 + for _, img := range m.Images {
  55 + result = append(result, img.Url)
  56 + }
  57 + if len(result) == 0 && len(cover) > 0 {
  58 + result = append(result, cover)
  59 + }
  60 + return result
  61 +}
@@ -46,6 +46,18 @@ func (m *ArticleDraftOperation) Identify() interface{} { @@ -46,6 +46,18 @@ func (m *ArticleDraftOperation) Identify() interface{} {
46 return m.Id 46 return m.Id
47 } 47 }
48 48
  49 +func (m *ArticleDraftOperation) GetImages() []string {
  50 + cover := m.GetCover()
  51 + var result = make([]string, 0)
  52 + for _, img := range m.Images {
  53 + result = append(result, img.Url)
  54 + }
  55 + if len(result) == 0 && len(cover) > 0 {
  56 + result = append(result, cover)
  57 + }
  58 + return result
  59 +}
  60 +
49 func (m *ArticleDraftOperation) GetCover() string { 61 func (m *ArticleDraftOperation) GetCover() string {
50 if len(m.Images) > 0 { 62 if len(m.Images) > 0 {
51 return m.Images[0].Url 63 return m.Images[0].Url