refactor: 更新项目引用路径从perfect-panel/ppanel-server到perfect-panel/server
feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/client"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/tool"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type CreateSubscribeApplicationLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewCreateSubscribeApplicationLogic Create subscribe application
|
||||
func NewCreateSubscribeApplicationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSubscribeApplicationLogic {
|
||||
return &CreateSubscribeApplicationLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateSubscribeApplicationLogic) CreateSubscribeApplication(req *types.CreateSubscribeApplicationRequest) (resp *types.SubscribeApplication, err error) {
|
||||
var link client.DownloadLink
|
||||
tool.DeepCopy(&link, req.DownloadLink)
|
||||
linkData, err := link.Marshal()
|
||||
if err != nil {
|
||||
l.Errorf("Failed to marshal download link: %v", err)
|
||||
return nil, errors.Wrap(xerr.NewErrCode(xerr.ERROR), " Failed to marshal download link")
|
||||
}
|
||||
data := &client.SubscribeApplication{
|
||||
Name: req.Name,
|
||||
Icon: req.Icon,
|
||||
Description: req.Description,
|
||||
Scheme: req.Scheme,
|
||||
UserAgent: req.UserAgent,
|
||||
IsDefault: req.IsDefault,
|
||||
SubscribeTemplate: req.SubscribeTemplate,
|
||||
OutputFormat: req.OutputFormat,
|
||||
DownloadLink: string(linkData),
|
||||
}
|
||||
|
||||
err = l.svcCtx.ClientModel.Insert(l.ctx, data)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to create subscribe application: %v", err)
|
||||
return nil, errors.Wrap(xerr.NewErrCode(xerr.DatabaseInsertError), "Failed to create subscribe application")
|
||||
}
|
||||
|
||||
resp = &types.SubscribeApplication{}
|
||||
tool.DeepCopy(resp, data)
|
||||
resp.DownloadLink = req.DownloadLink
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type DeleteSubscribeApplicationLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewDeleteSubscribeApplicationLogic Delete subscribe application
|
||||
func NewDeleteSubscribeApplicationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteSubscribeApplicationLogic {
|
||||
return &DeleteSubscribeApplicationLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteSubscribeApplicationLogic) DeleteSubscribeApplication(req *types.DeleteSubscribeApplicationRequest) error {
|
||||
err := l.svcCtx.ClientModel.Delete(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to delete subscribe application with ID %d: %v", req.Id, err)
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetSubscribeApplicationListLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewGetSubscribeApplicationListLogic Get subscribe application list
|
||||
func NewGetSubscribeApplicationListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubscribeApplicationListLogic {
|
||||
return &GetSubscribeApplicationListLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSubscribeApplicationListLogic) GetSubscribeApplicationList(req *types.GetSubscribeApplicationListRequest) (resp *types.GetSubscribeApplicationListResponse, err error) {
|
||||
data, err := l.svcCtx.ClientModel.List(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to get subscribe application list: %v", err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Failed to get subscribe application list")
|
||||
}
|
||||
var list []types.SubscribeApplication
|
||||
for _, item := range data {
|
||||
var temp types.DownloadLink
|
||||
if item.DownloadLink != "" {
|
||||
_ = json.Unmarshal([]byte(item.DownloadLink), &temp)
|
||||
}
|
||||
list = append(list, types.SubscribeApplication{
|
||||
Id: item.Id,
|
||||
Name: item.Name,
|
||||
Description: item.Description,
|
||||
Icon: item.Icon,
|
||||
Scheme: item.Scheme,
|
||||
UserAgent: item.UserAgent,
|
||||
IsDefault: item.IsDefault,
|
||||
SubscribeTemplate: item.SubscribeTemplate,
|
||||
OutputFormat: item.OutputFormat,
|
||||
DownloadLink: temp,
|
||||
CreatedAt: item.CreatedAt.UnixMilli(),
|
||||
UpdatedAt: item.UpdatedAt.UnixMilli(),
|
||||
})
|
||||
}
|
||||
resp = &types.GetSubscribeApplicationListResponse{
|
||||
Total: int64(len(list)),
|
||||
List: list,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/adapter"
|
||||
"github.com/perfect-panel/server/internal/model/node"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type PreviewSubscribeTemplateLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Preview Template
|
||||
func NewPreviewSubscribeTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreviewSubscribeTemplateLogic {
|
||||
return &PreviewSubscribeTemplateLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PreviewSubscribeTemplateLogic) PreviewSubscribeTemplate(req *types.PreviewSubscribeTemplateRequest) (resp *types.PreviewSubscribeTemplateResponse, err error) {
|
||||
enable := true
|
||||
_, servers, err := l.svcCtx.NodeModel.FilterNodeList(l.ctx, &node.FilterNodeParams{
|
||||
Page: 1,
|
||||
Size: 1000,
|
||||
Preload: true,
|
||||
Enabled: &enable,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("[PreviewSubscribeTemplateLogic] FindAllServer error: %v", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "FindAllServer error: %v", err.Error())
|
||||
}
|
||||
|
||||
data, err := l.svcCtx.ClientModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorf("[PreviewSubscribeTemplateLogic] FindOne error: %v", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "FindOneClient error: %v", err.Error())
|
||||
}
|
||||
|
||||
sub := adapter.NewAdapter(data.SubscribeTemplate, adapter.WithServers(servers),
|
||||
adapter.WithSiteName("PerfectPanel"),
|
||||
adapter.WithSubscribeName("Test Subscribe"),
|
||||
adapter.WithOutputFormat(data.OutputFormat),
|
||||
adapter.WithUserInfo(adapter.User{
|
||||
Password: "test-password",
|
||||
ExpiredAt: time.Now().AddDate(1, 0, 0),
|
||||
Download: 0,
|
||||
Upload: 0,
|
||||
Traffic: 1000,
|
||||
SubscribeURL: "https://example.com/subscribe",
|
||||
}))
|
||||
// Get client config
|
||||
a, err := sub.Client()
|
||||
if err != nil {
|
||||
l.Errorf("[PreviewSubscribeTemplateLogic] Client error: %v", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg(err.Error()), "Client error: %v", err.Error())
|
||||
}
|
||||
bytes, err := a.Build()
|
||||
if err != nil {
|
||||
l.Errorf("[PreviewSubscribeTemplateLogic] Build error: %v", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg(err.Error()), "Build error: %v", err.Error())
|
||||
}
|
||||
return &types.PreviewSubscribeTemplateResponse{
|
||||
Template: string(bytes),
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/client"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/tool"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type UpdateSubscribeApplicationLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewUpdateSubscribeApplicationLogic Update subscribe application
|
||||
func NewUpdateSubscribeApplicationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSubscribeApplicationLogic {
|
||||
return &UpdateSubscribeApplicationLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateSubscribeApplicationLogic) UpdateSubscribeApplication(req *types.UpdateSubscribeApplicationRequest) (resp *types.SubscribeApplication, err error) {
|
||||
data, err := l.svcCtx.ClientModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to find subscribe application with ID %d: %v", req.Id, err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Failed to find subscribe application with ID %d", req.Id)
|
||||
}
|
||||
var link client.DownloadLink
|
||||
tool.DeepCopy(&link, req.DownloadLink)
|
||||
linkData, err := link.Marshal()
|
||||
if err != nil {
|
||||
l.Errorf("Failed to marshal download link: %v", err)
|
||||
return nil, errors.Wrap(xerr.NewErrCode(xerr.ERROR), " Failed to marshal download link")
|
||||
}
|
||||
|
||||
data.Name = req.Name
|
||||
data.Icon = req.Icon
|
||||
data.Description = req.Description
|
||||
data.Scheme = req.Scheme
|
||||
data.UserAgent = req.UserAgent
|
||||
data.IsDefault = req.IsDefault
|
||||
data.SubscribeTemplate = req.SubscribeTemplate
|
||||
data.OutputFormat = req.OutputFormat
|
||||
data.DownloadLink = string(linkData)
|
||||
err = l.svcCtx.ClientModel.Update(l.ctx, data)
|
||||
if err != nil {
|
||||
l.Errorf("Failed to update subscribe application with ID %d: %v", req.Id, err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "Failed to update subscribe application with ID %d", req.Id)
|
||||
}
|
||||
resp = &types.SubscribeApplication{}
|
||||
tool.DeepCopy(&resp, data)
|
||||
resp.DownloadLink = req.DownloadLink
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user