Skip to content

Commit 6d4d53e

Browse files
authored
feat: Add historical release notes display (#10002)
Refs #9662
1 parent 6b81ae1 commit 6d4d53e

File tree

17 files changed

+246
-9
lines changed

17 files changed

+246
-9
lines changed

core/app/api/v2/upgrade.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,29 @@ func (b *BaseApi) GetUpgradeInfo(c *gin.Context) {
2121
helper.SuccessWithData(c, info)
2222
}
2323

24+
// @Tags System Setting
25+
// @Summary Load upgrade notes
26+
// @Success 200 {array} dto.ReleasesNotes
27+
// @Security ApiKeyAuth
28+
// @Security Timestamp
29+
// @Router /core/settings/upgrade/releases [get]
30+
func (b *BaseApi) LoadRelease(c *gin.Context) {
31+
notes, err := upgradeService.LoadRelease()
32+
if err != nil {
33+
helper.InternalServer(c, err)
34+
return
35+
}
36+
helper.SuccessWithData(c, notes)
37+
}
38+
2439
// @Tags System Setting
2540
// @Summary Load release notes by version
2641
// @Accept json
2742
// @Param request body dto.Upgrade true "request"
2843
// @Success 200 {string} notes
2944
// @Security ApiKeyAuth
3045
// @Security Timestamp
31-
// @Router /core/settings/upgrade [get]
46+
// @Router /core/settings/upgrade/notes [post]
3247
func (b *BaseApi) GetNotesByVersion(c *gin.Context) {
3348
var req dto.Upgrade
3449
if err := helper.CheckBindAndValidate(&req, c); err != nil {

core/app/dto/setting.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ type Upgrade struct {
145145
Version string `json:"version" validate:"required"`
146146
}
147147

148+
type ReleasesNotes struct {
149+
Version string `json:"version"`
150+
CreatedAt string `json:"createdAt"`
151+
Content string `json:"content"`
152+
NewCount int `json:"newCount"`
153+
OptimizationCount int `json:"optimizationCount"`
154+
FixCount int `json:"fixCount"`
155+
}
156+
148157
type ProxyUpdate struct {
149158
ProxyUrl string `json:"proxyUrl"`
150159
ProxyType string `json:"proxyType"`

core/app/service/upgrade.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package service
33
import (
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

3436
func 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+
211273
func (u *UpgradeService) handleBackup(originalDir string) error {
212274
if err := files.CopyItem(false, true, "/usr/local/bin/1panel-core", originalDir); err != nil {
213275
return err

core/router/ro_setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) {
3838

3939
settingRouter.POST("/upgrade", baseApi.Upgrade)
4040
settingRouter.POST("/upgrade/notes", baseApi.GetNotesByVersion)
41+
settingRouter.GET("/upgrade/releases", baseApi.LoadRelease)
4142
settingRouter.GET("/upgrade", baseApi.GetUpgradeInfo)
4243
settingRouter.POST("/api/config/generate/key", baseApi.GenerateApiKey)
4344
settingRouter.POST("/api/config/update", baseApi.UpdateApiConfig)

frontend/src/api/interface/setting.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ export namespace Setting {
241241
isBound: boolean;
242242
name: string;
243243
}
244+
export interface ReleasesNotes {
245+
Version: string;
246+
CreatedAt: string;
247+
Content: string;
248+
NewCount: number;
249+
OptimizationCount: number;
250+
FixCount: number;
251+
}
244252

245253
export interface LicenseBind {
246254
nodeID: number;

frontend/src/api/modules/setting.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export const loadUpgradeInfo = () => {
170170
export const loadReleaseNotes = (version: string) => {
171171
return http.post<string>(`/core/settings/upgrade/notes`, { version: version });
172172
};
173+
export const listReleases = () => {
174+
return http.get<Array<Setting.ReleasesNotes>>(`/core/settings/upgrade/releases`);
175+
};
173176
export const upgrade = (version: string) => {
174177
return http.post(`/core/settings/upgrade`, { version: version });
175178
};

frontend/src/assets/iconfont/iconfont.css

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@font-face {
22
font-family: "iconfont"; /* Project id 4776196 */
3-
src: url('iconfont.woff2?t=1752473267421') format('woff2'),
4-
url('iconfont.woff?t=1752473267421') format('woff'),
5-
url('iconfont.ttf?t=1752473267421') format('truetype'),
6-
url('iconfont.svg?t=1752473267421#iconfont') format('svg');
3+
src: url('iconfont.woff2?t=1755181498446') format('woff2'),
4+
url('iconfont.woff?t=1755181498446') format('woff'),
5+
url('iconfont.ttf?t=1755181498446') format('truetype'),
6+
url('iconfont.svg?t=1755181498446#iconfont') format('svg');
77
}
88

99
.iconfont {
@@ -14,6 +14,14 @@
1414
-moz-osx-font-smoothing: grayscale;
1515
}
1616

17+
.p-featureshitu:before {
18+
content: "\e63e";
19+
}
20+
21+
.p-youhuawendang:before {
22+
content: "\e7c4";
23+
}
24+
1725
.p-cluster-3:before {
1826
content: "\e706";
1927
}

frontend/src/assets/iconfont/iconfont.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/assets/iconfont/iconfont.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
"css_prefix_text": "p-",
66
"description": "",
77
"glyphs": [
8+
{
9+
"icon_id": "18536446",
10+
"name": "feature视图",
11+
"font_class": "featureshitu",
12+
"unicode": "e63e",
13+
"unicode_decimal": 58942
14+
},
15+
{
16+
"icon_id": "18133027",
17+
"name": "优化文档",
18+
"font_class": "youhuawendang",
19+
"unicode": "e7c4",
20+
"unicode_decimal": 59332
21+
},
822
{
923
"icon_id": "88609",
1024
"name": "cluster-3",

frontend/src/assets/iconfont/iconfont.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)