mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-08 02:20:24 +08:00
IP库增加制品管理/统计中相关区域名称可以显示别名
This commit is contained in:
@@ -40,7 +40,7 @@ func (this *FileChunkService) CreateFileChunk(ctx context.Context, req *pb.Creat
|
||||
// FindAllFileChunkIds 获取的一个文件的所有片段IDs
|
||||
func (this *FileChunkService) FindAllFileChunkIds(ctx context.Context, req *pb.FindAllFileChunkIdsRequest) (*pb.FindAllFileChunkIdsResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx, rpcutils.UserTypeNode, rpcutils.UserTypeAdmin, rpcutils.UserTypeUser)
|
||||
_, _, err := this.ValidateNodeId(ctx, rpcutils.UserTypeNode, rpcutils.UserTypeDNS, rpcutils.UserTypeAdmin, rpcutils.UserTypeUser)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (this *FileChunkService) FindAllFileChunkIds(ctx context.Context, req *pb.F
|
||||
// DownloadFileChunk 下载文件片段
|
||||
func (this *FileChunkService) DownloadFileChunk(ctx context.Context, req *pb.DownloadFileChunkRequest) (*pb.DownloadFileChunkResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateNodeId(ctx, rpcutils.UserTypeNode, rpcutils.UserTypeAdmin, rpcutils.UserTypeUser)
|
||||
_, _, err := this.ValidateNodeId(ctx, rpcutils.UserTypeNode, rpcutils.UserTypeDNS, rpcutils.UserTypeAdmin, rpcutils.UserTypeUser)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
164
internal/rpc/services/service_ip_library_artifact.go
Normal file
164
internal/rpc/services/service_ip_library_artifact.go
Normal file
@@ -0,0 +1,164 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// IPLibraryArtifactService IP库制品
|
||||
type IPLibraryArtifactService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// CreateIPLibraryArtifact 创建制品
|
||||
func (this *IPLibraryArtifactService) CreateIPLibraryArtifact(ctx context.Context, req *pb.CreateIPLibraryArtifactRequest) (*pb.CreateIPLibraryArtifactResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
var meta = &iplibrary.Meta{}
|
||||
err = json.Unmarshal(req.MetaJSON, meta)
|
||||
if err != nil {
|
||||
return nil, errors.New("decode meta failed: " + err.Error())
|
||||
}
|
||||
|
||||
artifactId, err := models.SharedIPLibraryArtifactDAO.CreateArtifact(tx, req.Name, req.FileId, 0, meta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CreateIPLibraryArtifactResponse{IpLibraryArtifactId: artifactId}, nil
|
||||
}
|
||||
|
||||
// UpdateIPLibraryArtifactIsPublic 使用/取消使用制品
|
||||
func (this *IPLibraryArtifactService) UpdateIPLibraryArtifactIsPublic(ctx context.Context, req *pb.UpdateIPLibraryArtifactIsPublicRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
err = models.SharedIPLibraryArtifactDAO.UpdateArtifactPublic(tx, req.IpLibraryArtifactId, req.IsPublic)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// FindAllIPLibraryArtifacts 查询所有制品
|
||||
func (this *IPLibraryArtifactService) FindAllIPLibraryArtifacts(ctx context.Context, req *pb.FindAllIPLibraryArtifactsRequest) (*pb.FindAllIPLibraryArtifactsResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
artifacts, err := models.SharedIPLibraryArtifactDAO.FindAllArtifacts(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pbArtifacts = []*pb.IPLibraryArtifact{}
|
||||
for _, artifact := range artifacts {
|
||||
pbArtifacts = append(pbArtifacts, &pb.IPLibraryArtifact{
|
||||
Id: int64(artifact.Id),
|
||||
Name: artifact.Name,
|
||||
FileId: int64(artifact.FileId),
|
||||
CreatedAt: int64(artifact.CreatedAt),
|
||||
MetaJSON: artifact.Meta,
|
||||
IsPublic: artifact.IsPublic,
|
||||
Code: artifact.Code,
|
||||
})
|
||||
}
|
||||
return &pb.FindAllIPLibraryArtifactsResponse{
|
||||
IpLibraryArtifacts: pbArtifacts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindIPLibraryArtifact 查找当前正在使用的制品
|
||||
func (this *IPLibraryArtifactService) FindIPLibraryArtifact(ctx context.Context, req *pb.FindIPLibraryArtifactRequest) (*pb.FindIPLibraryArtifactResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
artifact, err := models.SharedIPLibraryArtifactDAO.FindEnabledIPLibraryArtifact(tx, req.IpLibraryArtifactId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if artifact == nil {
|
||||
return &pb.FindIPLibraryArtifactResponse{
|
||||
IpLibraryArtifact: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &pb.FindIPLibraryArtifactResponse{
|
||||
IpLibraryArtifact: &pb.IPLibraryArtifact{
|
||||
Id: int64(artifact.Id),
|
||||
FileId: int64(artifact.FileId),
|
||||
CreatedAt: int64(artifact.CreatedAt),
|
||||
MetaJSON: artifact.Meta,
|
||||
IsPublic: artifact.IsPublic,
|
||||
Code: artifact.Code,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindPublicIPLibraryArtifact 查找当前正在使用的制品
|
||||
func (this *IPLibraryArtifactService) FindPublicIPLibraryArtifact(ctx context.Context, req *pb.FindPublicIPLibraryArtifactRequest) (*pb.FindPublicIPLibraryArtifactResponse, error) {
|
||||
_, _, err := this.ValidateNodeId(ctx, rpcutils.UserTypeNode, rpcutils.UserTypeDNS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
artifact, err := models.SharedIPLibraryArtifactDAO.FindPublicArtifact(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if artifact == nil {
|
||||
return &pb.FindPublicIPLibraryArtifactResponse{
|
||||
IpLibraryArtifact: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &pb.FindPublicIPLibraryArtifactResponse{
|
||||
IpLibraryArtifact: &pb.IPLibraryArtifact{
|
||||
Id: int64(artifact.Id),
|
||||
FileId: int64(artifact.FileId),
|
||||
CreatedAt: int64(artifact.CreatedAt),
|
||||
MetaJSON: artifact.Meta,
|
||||
IsPublic: artifact.IsPublic,
|
||||
Code: artifact.Code,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteIPLibraryArtifact 删除制品
|
||||
func (this *IPLibraryArtifactService) DeleteIPLibraryArtifact(ctx context.Context, req *pb.DeleteIPLibraryArtifactRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
err = models.SharedIPLibraryArtifactDAO.DisableIPLibraryArtifact(tx, req.IpLibraryArtifactId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (this *RegionProvinceService) FindAllRegionProvincesWithRegionCountryId(ctx
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := []*pb.RegionProvince{}
|
||||
var result = []*pb.RegionProvince{}
|
||||
for _, province := range provinces {
|
||||
result = append(result, &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
|
||||
@@ -32,7 +32,7 @@ func (this *ServerRegionCityMonthlyStatService) FindTopServerRegionCityMonthlySt
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionCityMonthlyStatsResponse_Stat{}
|
||||
var pbStats = []*pb.FindTopServerRegionCityMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionCityMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
@@ -63,15 +63,15 @@ func (this *ServerRegionCityMonthlyStatService) FindTopServerRegionCityMonthlySt
|
||||
}
|
||||
pbStat.RegionCountry = &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Name: country.DisplayName(),
|
||||
}
|
||||
pbStat.RegionProvince = &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Name: province.DisplayName(),
|
||||
}
|
||||
pbStat.RegionCity = &pb.RegionCity{
|
||||
Id: int64(city.Id),
|
||||
Name: city.Name,
|
||||
Name: city.DisplayName(),
|
||||
}
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (this *ServerRegionCountryMonthlyStatService) FindTopServerRegionCountryMon
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionCountryMonthlyStatsResponse_Stat{}
|
||||
var pbStats = []*pb.FindTopServerRegionCountryMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionCountryMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
@@ -47,7 +47,7 @@ func (this *ServerRegionCountryMonthlyStatService) FindTopServerRegionCountryMon
|
||||
}
|
||||
pbStat.RegionCountry = &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Name: country.DisplayName(),
|
||||
}
|
||||
|
||||
pbStats = append(pbStats, pbStat)
|
||||
|
||||
@@ -32,7 +32,7 @@ func (this *ServerRegionProviderMonthlyStatService) FindTopServerRegionProviderM
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionProviderMonthlyStatsResponse_Stat{}
|
||||
var pbStats = []*pb.FindTopServerRegionProviderMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionProviderMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
@@ -46,7 +46,7 @@ func (this *ServerRegionProviderMonthlyStatService) FindTopServerRegionProviderM
|
||||
}
|
||||
pbStat.RegionProvider = &pb.RegionProvider{
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
Name: provider.DisplayName(),
|
||||
}
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (this *ServerRegionProvinceMonthlyStatService) FindTopServerRegionProvinceM
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionProvinceMonthlyStatsResponse_Stat{}
|
||||
var pbStats = []*pb.FindTopServerRegionProvinceMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionProvinceMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
@@ -53,11 +53,11 @@ func (this *ServerRegionProvinceMonthlyStatService) FindTopServerRegionProvinceM
|
||||
}
|
||||
pbStat.RegionCountry = &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
Name: country.DisplayName(),
|
||||
}
|
||||
pbStat.RegionProvince = &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
Name: province.DisplayName(),
|
||||
}
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user