Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
type AddCityCustomCodeAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *AddCityCustomCodeAction) RunPost(params struct {
|
||||
CityId int64
|
||||
Code string
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.RegionCity_LogAddRegionCityCode, params.CityId, params.Code)
|
||||
|
||||
cityResp, err := this.RPC().RegionCityRPC().FindRegionCity(this.AdminContext(), &pb.FindRegionCityRequest{RegionCityId: params.CityId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var city = cityResp.RegionCity
|
||||
if city == nil {
|
||||
this.NotFound("regionCity", params.CityId)
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Code) > 0 && !lists.ContainsString(city.CustomCodes, params.Code) {
|
||||
city.CustomCodes = append(city.CustomCodes, params.Code)
|
||||
_, err = this.RPC().RegionCityRPC().UpdateRegionCityCustom(this.AdminContext(), &pb.UpdateRegionCityCustomRequest{
|
||||
RegionCityId: params.CityId,
|
||||
CustomName: city.CustomName,
|
||||
CustomCodes: city.CustomCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
type AddCountryCustomCodeAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *AddCountryCustomCodeAction) RunPost(params struct {
|
||||
CountryId int64
|
||||
Code string
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.RegionCountry_LogAddRegionCountryCode, params.CountryId, params.Code)
|
||||
|
||||
countryResp, err := this.RPC().RegionCountryRPC().FindRegionCountry(this.AdminContext(), &pb.FindRegionCountryRequest{RegionCountryId: params.CountryId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var country = countryResp.RegionCountry
|
||||
if country == nil {
|
||||
this.NotFound("regionCountry", params.CountryId)
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Code) > 0 && !lists.ContainsString(country.CustomCodes, params.Code) {
|
||||
country.CustomCodes = append(country.CustomCodes, params.Code)
|
||||
_, err = this.RPC().RegionCountryRPC().UpdateRegionCountryCustom(this.AdminContext(), &pb.UpdateRegionCountryCustomRequest{
|
||||
RegionCountryId: params.CountryId,
|
||||
CustomName: country.CustomName,
|
||||
CustomCodes: country.CustomCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
type AddProviderCustomCodeAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *AddProviderCustomCodeAction) RunPost(params struct {
|
||||
ProviderId int64
|
||||
Code string
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.RegionProvider_LogAddRegionProviderCode, params.ProviderId, params.Code)
|
||||
|
||||
providerResp, err := this.RPC().RegionProviderRPC().FindRegionProvider(this.AdminContext(), &pb.FindRegionProviderRequest{RegionProviderId: params.ProviderId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var provider = providerResp.RegionProvider
|
||||
if provider == nil {
|
||||
this.NotFound("regionProvider", params.ProviderId)
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Code) > 0 && !lists.ContainsString(provider.CustomCodes, params.Code) {
|
||||
provider.CustomCodes = append(provider.CustomCodes, params.Code)
|
||||
_, err = this.RPC().RegionProviderRPC().UpdateRegionProviderCustom(this.AdminContext(), &pb.UpdateRegionProviderCustomRequest{
|
||||
RegionProviderId: params.ProviderId,
|
||||
CustomName: provider.CustomName,
|
||||
CustomCodes: provider.CustomCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
type AddProvinceCustomCodeAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *AddProvinceCustomCodeAction) RunPost(params struct {
|
||||
ProvinceId int64
|
||||
Code string
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.RegionProvince_LogAddRegionProvinceCode, params.ProvinceId, params.Code)
|
||||
|
||||
provinceResp, err := this.RPC().RegionProvinceRPC().FindRegionProvince(this.AdminContext(), &pb.FindRegionProvinceRequest{RegionProvinceId: params.ProvinceId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var province = provinceResp.RegionProvince
|
||||
if province == nil {
|
||||
this.NotFound("regionProvince", params.ProvinceId)
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Code) > 0 && !lists.ContainsString(province.CustomCodes, params.Code) {
|
||||
province.CustomCodes = append(province.CustomCodes, params.Code)
|
||||
_, err = this.RPC().RegionProvinceRPC().UpdateRegionProvinceCustom(this.AdminContext(), &pb.UpdateRegionProvinceCustomRequest{
|
||||
RegionProvinceId: params.ProvinceId,
|
||||
CustomName: province.CustomName,
|
||||
CustomCodes: province.CustomCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
type AddTownCustomCodeAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *AddTownCustomCodeAction) RunPost(params struct {
|
||||
TownId int64
|
||||
Code string
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.RegionTown_LogAddRegionTownCode, params.TownId, params.Code)
|
||||
|
||||
townResp, err := this.RPC().RegionTownRPC().FindRegionTown(this.AdminContext(), &pb.FindRegionTownRequest{RegionTownId: params.TownId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var town = townResp.RegionTown
|
||||
if town == nil {
|
||||
this.NotFound("regionTown", params.TownId)
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Code) > 0 && !lists.ContainsString(town.CustomCodes, params.Code) {
|
||||
town.CustomCodes = append(town.CustomCodes, params.Code)
|
||||
_, err = this.RPC().RegionTownRPC().UpdateRegionTownCustom(this.AdminContext(), &pb.UpdateRegionTownCustomRequest{
|
||||
RegionTownId: params.TownId,
|
||||
CustomName: town.CustomName,
|
||||
CustomCodes: town.CustomCodes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CitiesAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CitiesAction) RunPost(params struct {
|
||||
LibraryFileId int64
|
||||
Size int
|
||||
}) {
|
||||
missingCitiesResp, err := this.RPC().IPLibraryFileRPC().CheckCitiesWithIPLibraryFileId(this.AdminContext(), &pb.CheckCitiesWithIPLibraryFileIdRequest{
|
||||
IpLibraryFileId: params.LibraryFileId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var missingCityMaps = []maps.Map{}
|
||||
for _, missingCity := range missingCitiesResp.MissingCities {
|
||||
var similarCityMaps = []maps.Map{}
|
||||
for _, city := range missingCity.SimilarCities {
|
||||
similarCityMaps = append(similarCityMaps, maps.Map{
|
||||
"id": city.Id,
|
||||
"displayName": city.DisplayName,
|
||||
})
|
||||
}
|
||||
|
||||
missingCityMaps = append(missingCityMaps, maps.Map{
|
||||
"countryName": missingCity.CountryName,
|
||||
"provinceName": missingCity.ProvinceName,
|
||||
"cityName": missingCity.CityName,
|
||||
"similarCities": similarCityMaps,
|
||||
})
|
||||
|
||||
if params.Size > 0 && len(missingCityMaps) >= params.Size {
|
||||
break
|
||||
}
|
||||
}
|
||||
this.Data["missingCities"] = missingCityMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CountriesAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CountriesAction) RunPost(params struct {
|
||||
LibraryFileId int64
|
||||
}) {
|
||||
missingCountriesResp, err := this.RPC().IPLibraryFileRPC().CheckCountriesWithIPLibraryFileId(this.AdminContext(), &pb.CheckCountriesWithIPLibraryFileIdRequest{
|
||||
IpLibraryFileId: params.LibraryFileId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var missingCountryMaps = []maps.Map{}
|
||||
for _, missingCountry := range missingCountriesResp.MissingCountries {
|
||||
var similarCountryMaps = []maps.Map{}
|
||||
for _, country := range missingCountry.SimilarCountries {
|
||||
similarCountryMaps = append(similarCountryMaps, maps.Map{
|
||||
"id": country.Id,
|
||||
"displayName": country.DisplayName,
|
||||
})
|
||||
}
|
||||
|
||||
missingCountryMaps = append(missingCountryMaps, maps.Map{
|
||||
"countryName": missingCountry.CountryName,
|
||||
"similarCountries": similarCountryMaps,
|
||||
})
|
||||
}
|
||||
this.Data["missingCountries"] = missingCountryMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type FinishAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *FinishAction) RunPost(params struct {
|
||||
LibraryFileId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.IPLibrary_LogFinishIPLibrary, params.LibraryFileId)
|
||||
|
||||
// set finished
|
||||
_, err := this.RPC().IPLibraryFileRPC().UpdateIPLibraryFileFinished(this.AdminContext(), &pb.UpdateIPLibraryFileFinishedRequest{IpLibraryFileId: params.LibraryFileId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// generate
|
||||
_, err = this.RPC().IPLibraryFileRPC().GenerateIPLibraryFile(this.AdminContext(), &pb.GenerateIPLibraryFileRequest{IpLibraryFileId: params.LibraryFileId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type GenerateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *GenerateAction) RunPost(params struct {
|
||||
LibraryFileId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.IPLibraryFile_LogGenerateIPLibraryFile, params.LibraryFileId)
|
||||
|
||||
_, err := this.RPC().IPLibraryFileRPC().GenerateIPLibraryFile(this.AdminContext(), &pb.GenerateIPLibraryFileRequest{IpLibraryFileId: params.LibraryFileId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type ProvidersAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ProvidersAction) RunPost(params struct {
|
||||
LibraryFileId int64
|
||||
}) {
|
||||
missingProvidersResp, err := this.RPC().IPLibraryFileRPC().CheckProvidersWithIPLibraryFileId(this.AdminContext(), &pb.CheckProvidersWithIPLibraryFileIdRequest{
|
||||
IpLibraryFileId: params.LibraryFileId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var missingProviderMaps = []maps.Map{}
|
||||
for _, missingProvider := range missingProvidersResp.MissingProviders {
|
||||
var similarProviderMaps = []maps.Map{}
|
||||
for _, provider := range missingProvider.SimilarProviders {
|
||||
similarProviderMaps = append(similarProviderMaps, maps.Map{
|
||||
"id": provider.Id,
|
||||
"displayName": provider.DisplayName,
|
||||
})
|
||||
}
|
||||
|
||||
missingProviderMaps = append(missingProviderMaps, maps.Map{
|
||||
"providerName": missingProvider.ProviderName,
|
||||
"similarProviders": similarProviderMaps,
|
||||
})
|
||||
}
|
||||
this.Data["missingProviders"] = missingProviderMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type ProvincesAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ProvincesAction) RunPost(params struct {
|
||||
LibraryFileId int64
|
||||
}) {
|
||||
missingProvincesResp, err := this.RPC().IPLibraryFileRPC().CheckProvincesWithIPLibraryFileId(this.AdminContext(), &pb.CheckProvincesWithIPLibraryFileIdRequest{
|
||||
IpLibraryFileId: params.LibraryFileId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var missingProvinceMaps = []maps.Map{}
|
||||
for _, missingProvince := range missingProvincesResp.MissingProvinces {
|
||||
var similarProvinceMaps = []maps.Map{}
|
||||
for _, province := range missingProvince.SimilarProvinces {
|
||||
similarProvinceMaps = append(similarProvinceMaps, maps.Map{
|
||||
"id": province.Id,
|
||||
"displayName": province.DisplayName,
|
||||
})
|
||||
}
|
||||
|
||||
missingProvinceMaps = append(missingProvinceMaps, maps.Map{
|
||||
"countryName": missingProvince.CountryName,
|
||||
"provinceName": missingProvince.ProvinceName,
|
||||
"similarProvinces": similarProvinceMaps,
|
||||
})
|
||||
}
|
||||
this.Data["missingProvinces"] = missingProvinceMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
|
||||
)
|
||||
|
||||
type TestFormatAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TestFormatAction) RunPost(params struct {
|
||||
Template string
|
||||
Text string
|
||||
}) {
|
||||
if len(params.Text) == 0 {
|
||||
this.Fail("请先输入测试数据")
|
||||
}
|
||||
|
||||
template, err := iplibrary.NewTemplate(params.Template)
|
||||
if err != nil {
|
||||
this.Fail("数据格式模板解析错误:" + err.Error())
|
||||
}
|
||||
|
||||
var emptyValues = []string{"0", "无"} // TODO
|
||||
|
||||
values, ok := template.Extract(params.Text, emptyValues)
|
||||
if !ok {
|
||||
this.Fail("无法分析数据,填写的测试数据和模板不符合")
|
||||
}
|
||||
this.Data["values"] = values
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type TownsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TownsAction) RunPost(params struct {
|
||||
LibraryFileId int64
|
||||
Size int
|
||||
}) {
|
||||
missingTownsResp, err := this.RPC().IPLibraryFileRPC().CheckTownsWithIPLibraryFileId(this.AdminContext(), &pb.CheckTownsWithIPLibraryFileIdRequest{
|
||||
IpLibraryFileId: params.LibraryFileId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var missingTownMaps = []maps.Map{}
|
||||
for _, missingTown := range missingTownsResp.MissingTowns {
|
||||
var similarTownMaps = []maps.Map{}
|
||||
for _, town := range missingTown.SimilarTowns {
|
||||
similarTownMaps = append(similarTownMaps, maps.Map{
|
||||
"id": town.Id,
|
||||
"displayName": town.DisplayName,
|
||||
})
|
||||
}
|
||||
|
||||
missingTownMaps = append(missingTownMaps, maps.Map{
|
||||
"countryName": missingTown.CountryName,
|
||||
"provinceName": missingTown.ProvinceName,
|
||||
"cityName": missingTown.CityName,
|
||||
"townName": missingTown.TownName,
|
||||
"similarTowns": similarTownMaps,
|
||||
})
|
||||
|
||||
if params.Size > 0 && len(missingTownMaps) >= params.Size {
|
||||
break
|
||||
}
|
||||
}
|
||||
this.Data["missingTowns"] = missingTownMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package creating
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"io"
|
||||
)
|
||||
|
||||
type UploadAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UploadAction) RunPost(params struct {
|
||||
Name string
|
||||
Template string
|
||||
EmptyValues []string
|
||||
Password string
|
||||
File *actions.File
|
||||
}) {
|
||||
if len(params.Name) == 0 {
|
||||
this.Fail("请输入IP库名称")
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Template) == 0 {
|
||||
this.Fail("请输入数据格式模板")
|
||||
return
|
||||
}
|
||||
|
||||
template, err := iplibrary.NewTemplate(params.Template)
|
||||
if err != nil {
|
||||
this.Fail("模板格式错误:" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if params.File == nil {
|
||||
this.Fail("请上传文件")
|
||||
}
|
||||
|
||||
var emptyValues = []string{"0", "无"}
|
||||
|
||||
if len(params.EmptyValues) > 0 {
|
||||
for _, emptyValue := range params.EmptyValues {
|
||||
if !lists.ContainsString(emptyValues, emptyValue) {
|
||||
emptyValues = append(emptyValues, emptyValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileResp, err := this.RPC().FileRPC().CreateFile(this.AdminContext(), &pb.CreateFileRequest{
|
||||
Filename: params.File.Filename,
|
||||
Size: params.File.Size,
|
||||
IsPublic: false,
|
||||
MimeType: params.File.ContentType,
|
||||
Type: "ipLibraryFile",
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var fileId = fileResp.FileId
|
||||
|
||||
fp, err := params.File.OriginFile.Open()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
_ = fp.Close()
|
||||
}()
|
||||
|
||||
var buf = make([]byte, 128*1024)
|
||||
var dataBuf = []byte{}
|
||||
|
||||
var countries = []string{}
|
||||
var provinces = [][2]string{}
|
||||
var cities = [][3]string{}
|
||||
var towns = [][4]string{}
|
||||
var providers = []string{}
|
||||
|
||||
var countryMap = map[string]bool{} // countryName => bool
|
||||
var provinceMap = map[string]bool{} // countryName_provinceName => bool
|
||||
var cityMap = map[string]bool{} // countryName_provinceName_cityName => bool
|
||||
var townMap = map[string]bool{} // countryName_provinceName_cityName_townName => bool
|
||||
var providerMap = map[string]bool{} // providerName => bool
|
||||
|
||||
for {
|
||||
n, err := fp.Read(buf)
|
||||
if n > 0 {
|
||||
var data = buf[:n]
|
||||
|
||||
// upload
|
||||
_, uploadErr := this.RPC().FileChunkRPC().CreateFileChunk(this.AdminContext(), &pb.CreateFileChunkRequest{
|
||||
FileId: fileId,
|
||||
Data: data,
|
||||
})
|
||||
if uploadErr != nil {
|
||||
this.Fail("文件上传失败:" + uploadErr.Error())
|
||||
}
|
||||
|
||||
// parse
|
||||
dataBuf = append(dataBuf, data...)
|
||||
left, valuesList, failLine, parseIsOk, err := this.parse(template, dataBuf, emptyValues)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if !parseIsOk {
|
||||
this.Fail("在 '" + failLine + "' 这行分析失败,请对比数据模板,检查数据格式")
|
||||
return
|
||||
}
|
||||
for _, value := range valuesList {
|
||||
var countryName = value["country"]
|
||||
var provinceName = value["province"]
|
||||
var cityName = value["city"]
|
||||
var townName = value["town"]
|
||||
var providerName = value["provider"]
|
||||
|
||||
// country
|
||||
if len(countryName) > 0 {
|
||||
_, ok := countryMap[countryName]
|
||||
if !ok {
|
||||
countries = append(countries, countryName)
|
||||
countryMap[countryName] = true
|
||||
}
|
||||
|
||||
// province
|
||||
if len(provinceName) > 0 {
|
||||
var key = countryName + "_" + provinceName
|
||||
_, ok = provinceMap[key]
|
||||
if !ok {
|
||||
provinceMap[key] = true
|
||||
provinces = append(provinces, [2]string{countryName, provinceName})
|
||||
}
|
||||
|
||||
// city
|
||||
if len(cityName) > 0 {
|
||||
key += "_" + cityName
|
||||
_, ok = cityMap[key]
|
||||
if !ok {
|
||||
cityMap[key] = true
|
||||
cities = append(cities, [3]string{countryName, provinceName, cityName})
|
||||
}
|
||||
|
||||
// town
|
||||
if len(townName) > 0 {
|
||||
key += "_" + townName
|
||||
_, ok = townMap[key]
|
||||
if !ok {
|
||||
townMap[key] = true
|
||||
towns = append(towns, [4]string{countryName, provinceName, cityName, townName})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// provider
|
||||
if len(providerName) > 0 {
|
||||
_, ok := providerMap[providerName]
|
||||
if !ok {
|
||||
providerMap[providerName] = true
|
||||
providers = append(providers, providerName)
|
||||
}
|
||||
}
|
||||
}
|
||||
dataBuf = left
|
||||
}
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
countriesJSON, err := json.Marshal(countries)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
provincesJSON, err := json.Marshal(provinces)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
citiesJSON, err := json.Marshal(cities)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
townsJSON, err := json.Marshal(towns)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
providersJSON, err := json.Marshal(providers)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().IPLibraryFileRPC().CreateIPLibraryFile(this.AdminContext(), &pb.CreateIPLibraryFileRequest{
|
||||
Name: params.Name,
|
||||
Template: params.Template,
|
||||
FileId: fileId,
|
||||
EmptyValues: params.EmptyValues,
|
||||
Password: params.Password,
|
||||
CountriesJSON: countriesJSON,
|
||||
ProvincesJSON: provincesJSON,
|
||||
CitiesJSON: citiesJSON,
|
||||
TownsJSON: townsJSON,
|
||||
ProvidersJSON: providersJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var ipLibraryFileId = createResp.IpLibraryFileId
|
||||
defer this.CreateLogInfo(codes.IPLibraryFile_LogUploadIPLibraryFile, ipLibraryFileId)
|
||||
|
||||
this.Data["libraryFileId"] = ipLibraryFileId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
func (this *UploadAction) parse(template *iplibrary.Template, data []byte, emptyValues []string) (left []byte, valuesList []map[string]string, failLine string, ok bool, err error) {
|
||||
ok = true
|
||||
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
for {
|
||||
var index = bytes.IndexByte(data, '\n')
|
||||
if index >= 0 {
|
||||
var line = data[:index+1]
|
||||
values, found := template.Extract(string(line), emptyValues)
|
||||
if found {
|
||||
valuesList = append(valuesList, values)
|
||||
} else {
|
||||
// 防止错误信息太长
|
||||
if len(line) > 256 {
|
||||
line = line[:256]
|
||||
}
|
||||
failLine = string(line)
|
||||
ok = false
|
||||
return
|
||||
}
|
||||
|
||||
data = data[index+1:]
|
||||
} else {
|
||||
left = data
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user