| 
									
										
										
										
											2023-12-04 18:20:46 +00:00
										 |  |  | package service | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	_ "embed" | 
					
						
							|  |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2024-03-10 21:31:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 18:20:46 +00:00
										 |  |  | 	"x-ui/util/common" | 
					
						
							|  |  |  | 	"x-ui/xray" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type XraySettingService struct { | 
					
						
							|  |  |  | 	SettingService | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *XraySettingService) SaveXraySetting(newXraySettings string) error { | 
					
						
							|  |  |  | 	if err := s.CheckXrayConfig(newXraySettings); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return s.SettingService.saveSetting("xrayTemplateConfig", newXraySettings) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (s *XraySettingService) CheckXrayConfig(XrayTemplateConfig string) error { | 
					
						
							|  |  |  | 	xrayConfig := &xray.Config{} | 
					
						
							|  |  |  | 	err := json.Unmarshal([]byte(XrayTemplateConfig), xrayConfig) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return common.NewError("xray template config invalid:", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |