mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	IP库文件可以加密
This commit is contained in:
		@@ -72,7 +72,7 @@ func (this *IPLibraryFileDAO) FindEnabledIPLibraryFile(tx *dbs.Tx, id int64) (*I
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CreateLibraryFile 创建文件
 | 
					// CreateLibraryFile 创建文件
 | 
				
			||||||
func (this *IPLibraryFileDAO) CreateLibraryFile(tx *dbs.Tx, name string, template string, emptyValues []string, fileId int64, countries []string, provinces [][2]string, cities [][3]string, towns [][4]string, providers []string) (int64, error) {
 | 
					func (this *IPLibraryFileDAO) CreateLibraryFile(tx *dbs.Tx, name string, template string, emptyValues []string, password string, fileId int64, countries []string, provinces [][2]string, cities [][3]string, towns [][4]string, providers []string) (int64, error) {
 | 
				
			||||||
	var op = NewIPLibraryFileOperator()
 | 
						var op = NewIPLibraryFileOperator()
 | 
				
			||||||
	op.Name = name
 | 
						op.Name = name
 | 
				
			||||||
	op.Template = template
 | 
						op.Template = template
 | 
				
			||||||
@@ -86,6 +86,8 @@ func (this *IPLibraryFileDAO) CreateLibraryFile(tx *dbs.Tx, name string, templat
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	op.EmptyValues = emptyValuesJSON
 | 
						op.EmptyValues = emptyValuesJSON
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						op.Password = password
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	op.FileId = fileId
 | 
						op.FileId = fileId
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if countries == nil {
 | 
						if countries == nil {
 | 
				
			||||||
@@ -337,7 +339,7 @@ func (this *IPLibraryFileDAO) GenerateIPLibrary(tx *dbs.Tx, libraryFileId int64)
 | 
				
			|||||||
	var countries = []*iplibrary.Country{}
 | 
						var countries = []*iplibrary.Country{}
 | 
				
			||||||
	for _, country := range dbCountries {
 | 
						for _, country := range dbCountries {
 | 
				
			||||||
		countries = append(countries, &iplibrary.Country{
 | 
							countries = append(countries, &iplibrary.Country{
 | 
				
			||||||
			Id:    country.Id,
 | 
								Id:    types.Uint16(country.Id),
 | 
				
			||||||
			Name:  country.DisplayName(),
 | 
								Name:  country.DisplayName(),
 | 
				
			||||||
			Codes: country.AllCodes(),
 | 
								Codes: country.AllCodes(),
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
@@ -352,7 +354,7 @@ func (this *IPLibraryFileDAO) GenerateIPLibrary(tx *dbs.Tx, libraryFileId int64)
 | 
				
			|||||||
	var provinces = []*iplibrary.Province{}
 | 
						var provinces = []*iplibrary.Province{}
 | 
				
			||||||
	for _, province := range dbProvinces {
 | 
						for _, province := range dbProvinces {
 | 
				
			||||||
		provinces = append(provinces, &iplibrary.Province{
 | 
							provinces = append(provinces, &iplibrary.Province{
 | 
				
			||||||
			Id:    province.Id,
 | 
								Id:    types.Uint16(province.Id),
 | 
				
			||||||
			Name:  province.DisplayName(),
 | 
								Name:  province.DisplayName(),
 | 
				
			||||||
			Codes: province.AllCodes(),
 | 
								Codes: province.AllCodes(),
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
@@ -397,7 +399,7 @@ func (this *IPLibraryFileDAO) GenerateIPLibrary(tx *dbs.Tx, libraryFileId int64)
 | 
				
			|||||||
	var providers = []*iplibrary.Provider{}
 | 
						var providers = []*iplibrary.Provider{}
 | 
				
			||||||
	for _, provider := range dbProviders {
 | 
						for _, provider := range dbProviders {
 | 
				
			||||||
		providers = append(providers, &iplibrary.Provider{
 | 
							providers = append(providers, &iplibrary.Provider{
 | 
				
			||||||
			Id:    provider.Id,
 | 
								Id:    types.Uint16(provider.Id),
 | 
				
			||||||
			Name:  provider.DisplayName(),
 | 
								Name:  provider.DisplayName(),
 | 
				
			||||||
			Codes: provider.AllCodes(),
 | 
								Codes: provider.AllCodes(),
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
@@ -414,7 +416,7 @@ func (this *IPLibraryFileDAO) GenerateIPLibrary(tx *dbs.Tx, libraryFileId int64)
 | 
				
			|||||||
		Towns:     towns,
 | 
							Towns:     towns,
 | 
				
			||||||
		Providers: providers,
 | 
							Providers: providers,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	writer, err := iplibrary.NewFileWriter(filePath, meta)
 | 
						writer, err := iplibrary.NewFileWriter(filePath, meta, libraryFile.Password)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,7 @@ type IPLibraryFile struct {
 | 
				
			|||||||
	Towns           dbs.JSON `field:"towns"`           // 区县
 | 
						Towns           dbs.JSON `field:"towns"`           // 区县
 | 
				
			||||||
	Providers       dbs.JSON `field:"providers"`       // ISP服务商
 | 
						Providers       dbs.JSON `field:"providers"`       // ISP服务商
 | 
				
			||||||
	Code            string   `field:"code"`            // 文件代号
 | 
						Code            string   `field:"code"`            // 文件代号
 | 
				
			||||||
 | 
						Password        string   `field:"password"`        // 密码
 | 
				
			||||||
	CreatedAt       uint64   `field:"createdAt"`       // 上传时间
 | 
						CreatedAt       uint64   `field:"createdAt"`       // 上传时间
 | 
				
			||||||
	State           uint8    `field:"state"`           // 状态
 | 
						State           uint8    `field:"state"`           // 状态
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -37,6 +38,7 @@ type IPLibraryFileOperator struct {
 | 
				
			|||||||
	Towns           any // 区县
 | 
						Towns           any // 区县
 | 
				
			||||||
	Providers       any // ISP服务商
 | 
						Providers       any // ISP服务商
 | 
				
			||||||
	Code            any // 文件代号
 | 
						Code            any // 文件代号
 | 
				
			||||||
 | 
						Password        any // 密码
 | 
				
			||||||
	CreatedAt       any // 上传时间
 | 
						CreatedAt       any // 上传时间
 | 
				
			||||||
	State           any // 状态
 | 
						State           any // 状态
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -70,6 +70,7 @@ func (this *IPLibraryFileService) FindAllFinishedIPLibraryFiles(ctx context.Cont
 | 
				
			|||||||
			CreatedAt:       int64(libraryFile.CreatedAt),
 | 
								CreatedAt:       int64(libraryFile.CreatedAt),
 | 
				
			||||||
			GeneratedFileId: int64(libraryFile.GeneratedFileId),
 | 
								GeneratedFileId: int64(libraryFile.GeneratedFileId),
 | 
				
			||||||
			GeneratedAt:     int64(libraryFile.GeneratedAt),
 | 
								GeneratedAt:     int64(libraryFile.GeneratedAt),
 | 
				
			||||||
 | 
								Password:        libraryFile.Password,
 | 
				
			||||||
			CountryNames:    pbCountryNames,
 | 
								CountryNames:    pbCountryNames,
 | 
				
			||||||
			Provinces:       pbProvinces,
 | 
								Provinces:       pbProvinces,
 | 
				
			||||||
			Cities:          pbCities,
 | 
								Cities:          pbCities,
 | 
				
			||||||
@@ -133,6 +134,7 @@ func (this *IPLibraryFileService) FindAllUnfinishedIPLibraryFiles(ctx context.Co
 | 
				
			|||||||
			FileId:        int64(libraryFile.FileId),
 | 
								FileId:        int64(libraryFile.FileId),
 | 
				
			||||||
			IsFinished:    libraryFile.IsFinished,
 | 
								IsFinished:    libraryFile.IsFinished,
 | 
				
			||||||
			CreatedAt:     int64(libraryFile.CreatedAt),
 | 
								CreatedAt:     int64(libraryFile.CreatedAt),
 | 
				
			||||||
 | 
								Password:      libraryFile.Password,
 | 
				
			||||||
			CountryNames:  pbCountryNames,
 | 
								CountryNames:  pbCountryNames,
 | 
				
			||||||
			Provinces:     pbProvinces,
 | 
								Provinces:     pbProvinces,
 | 
				
			||||||
			Cities:        pbCities,
 | 
								Cities:        pbCities,
 | 
				
			||||||
@@ -204,6 +206,7 @@ func (this *IPLibraryFileService) FindIPLibraryFile(ctx context.Context, req *pb
 | 
				
			|||||||
			IsFinished:      libraryFile.IsFinished,
 | 
								IsFinished:      libraryFile.IsFinished,
 | 
				
			||||||
			CreatedAt:       int64(libraryFile.CreatedAt),
 | 
								CreatedAt:       int64(libraryFile.CreatedAt),
 | 
				
			||||||
			GeneratedFileId: int64(libraryFile.GeneratedFileId),
 | 
								GeneratedFileId: int64(libraryFile.GeneratedFileId),
 | 
				
			||||||
 | 
								Password:        libraryFile.Password,
 | 
				
			||||||
			CountryNames:    pbCountryNames,
 | 
								CountryNames:    pbCountryNames,
 | 
				
			||||||
			Provinces:       pbProvinces,
 | 
								Provinces:       pbProvinces,
 | 
				
			||||||
			Cities:          pbCities,
 | 
								Cities:          pbCities,
 | 
				
			||||||
@@ -252,7 +255,7 @@ func (this *IPLibraryFileService) CreateIPLibraryFile(ctx context.Context, req *
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var tx = this.NullTx()
 | 
						var tx = this.NullTx()
 | 
				
			||||||
	libraryFileId, err := models.SharedIPLibraryFileDAO.CreateLibraryFile(tx, req.Name, req.Template, req.EmptyValues, req.FileId, countries, provinces, cities, towns, providers)
 | 
						libraryFileId, err := models.SharedIPLibraryFileDAO.CreateLibraryFile(tx, req.Name, req.Template, req.EmptyValues, req.Password, req.FileId, countries, provinces, cities, towns, providers)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user