@@ -3,6 +3,7 @@ package service
33import (
44 "encoding/json"
55 "fmt"
6+ "io"
67 "net/http"
78 "os"
89 "path"
@@ -29,6 +30,7 @@ type IUpgradeService interface {
2930 Rollback (req dto.OperateByID ) error
3031 LoadNotes (req dto.Upgrade ) (string , error )
3132 SearchUpgrade () (* dto.UpgradeInfo , error )
33+ LoadRelease () ([]dto.ReleasesNotes , error )
3234}
3335
3436func NewIUpgradeService () IUpgradeService {
@@ -208,6 +210,66 @@ func (u *UpgradeService) Rollback(req dto.OperateByID) error {
208210 return nil
209211}
210212
213+ type noteHelper struct {
214+ Docs []noteDetailHelper `json:"docs"`
215+ }
216+ type noteDetailHelper struct {
217+ Location string `json:"location"`
218+ Text string `json:"text"`
219+ Title string `json:"title"`
220+ }
221+
222+ func (u * UpgradeService ) LoadRelease () ([]dto.ReleasesNotes , error ) {
223+ var notes []dto.ReleasesNotes
224+ resp , err := req_helper .HandleGet ("https://1panel.cn/docs/v2/search/search_index.json" )
225+ if err != nil {
226+ return notes , err
227+ }
228+ body , err := io .ReadAll (resp .Body )
229+ if err != nil {
230+ return notes , err
231+ }
232+ defer resp .Body .Close ()
233+ var nodeItem noteHelper
234+ if err := json .Unmarshal (body , & nodeItem ); err != nil {
235+ return notes , err
236+ }
237+ for _ , item := range nodeItem .Docs {
238+ if ! strings .HasPrefix (item .Location , "changelog/#v" ) {
239+ continue
240+ }
241+ itemNote := analyzeDoc (item .Title , item .Text )
242+ if len (itemNote .CreatedAt ) != 0 {
243+ notes = append (notes , analyzeDoc (item .Title , item .Text ))
244+ }
245+ }
246+
247+ return notes , nil
248+ }
249+
250+ func analyzeDoc (version , content string ) dto.ReleasesNotes {
251+ var item dto.ReleasesNotes
252+ parts := strings .Split (content , "<p>" )
253+ if len (parts ) < 3 {
254+ return item
255+ }
256+ item .CreatedAt = strings .ReplaceAll (strings .TrimSpace (parts [1 ]), "</p>" , "" )
257+ for i := 1 ; i < len (parts ); i ++ {
258+ if strings .Contains (parts [i ], "问题修复" ) {
259+ item .FixCount = strings .Count (parts [i ], "<li>" )
260+ }
261+ if strings .Contains (parts [i ], "新增功能" ) {
262+ item .NewCount = strings .Count (parts [i ], "<li>" )
263+ }
264+ if strings .Contains (parts [i ], "功能优化" ) {
265+ item .OptimizationCount = strings .Count (parts [i ], "<li>" )
266+ }
267+ }
268+ item .Content = strings .Replace (content , fmt .Sprintf ("<p>%s</p>" , item .CreatedAt ), "" , 1 )
269+ item .Version = version
270+ return item
271+ }
272+
211273func (u * UpgradeService ) handleBackup (originalDir string ) error {
212274 if err := files .CopyItem (false , true , "/usr/local/bin/1panel-core" , originalDir ); err != nil {
213275 return err
0 commit comments