mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	Fix custom endpoints
This commit is contained in:
		| @@ -8,6 +8,7 @@ import { | |||||||
|   TouchableOpacity, |   TouchableOpacity, | ||||||
|   Linking, |   Linking, | ||||||
|   Image, |   Image, | ||||||
|  |   NativeModules, | ||||||
| } from 'react-native'; | } from 'react-native'; | ||||||
|  |  | ||||||
| import { | import { | ||||||
| @@ -70,6 +71,12 @@ export default class App extends Component { | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   checkUpdate = async () => { |   checkUpdate = async () => { | ||||||
|  |     return await this.doUpdate({ | ||||||
|  |       update: true, | ||||||
|  |       pdiffUrl: 'http://localhost:8888/1.pdiff', | ||||||
|  |       hash: 'test', | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     let info; |     let info; | ||||||
|     try { |     try { | ||||||
|       info = await checkUpdate(appKey); |       info = await checkUpdate(appKey); | ||||||
| @@ -108,17 +115,17 @@ export default class App extends Component { | |||||||
|   render() { |   render() { | ||||||
|     return ( |     return ( | ||||||
|       <View style={styles.container}> |       <View style={styles.container}> | ||||||
|         <Text style={styles.welcome}>欢迎使用热更新服务</Text> |         <Text style={styles.welcome}>443欢迎使用热更新服务</Text> | ||||||
|         <Image |         <Image | ||||||
|           resizeMode={'contain'} |           resizeMode={'contain'} | ||||||
|           source={require('./assets/shoucang.png')} |           source={require('./assets/shezhi.png')} | ||||||
|           style={styles.image} |           style={styles.image} | ||||||
|         /> |         /> | ||||||
|         <Text style={styles.instructions}> |         <Text style={styles.instructions}> | ||||||
|           这是版本一 {'\n'} |           这是版本一 {'\n'} | ||||||
|           当前包版本号: {packageVersion} |           当前原生包版本号: {packageVersion} | ||||||
|           {'\n'} |           {'\n'} | ||||||
|           当前版本Hash: {currentVersion || '(空)'} |           当前热更新版本Hash: {currentVersion || '(空)'} | ||||||
|           {'\n'} |           {'\n'} | ||||||
|         </Text> |         </Text> | ||||||
|         <TouchableOpacity onPress={this.checkUpdate}> |         <TouchableOpacity onPress={this.checkUpdate}> | ||||||
|   | |||||||
| @@ -29,6 +29,9 @@ let backupEndpointsQueryUrl = | |||||||
|   'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json'; |   'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json'; | ||||||
|  |  | ||||||
| export async function tryBackupEndpoints() { | export async function tryBackupEndpoints() { | ||||||
|  |   if (!backupEndpoints.length && !backupEndpointsQueryUrl) { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|   try { |   try { | ||||||
|     await ping(getStatusUrl(), true); |     await ping(getStatusUrl(), true); | ||||||
|     logger('current endpoint ok'); |     logger('current endpoint ok'); | ||||||
| @@ -73,10 +76,14 @@ export function getCheckUrl(APPKEY, endpoint = currentEndpoint) { | |||||||
|   return `${endpoint}/checkUpdate/${APPKEY}`; |   return `${endpoint}/checkUpdate/${APPKEY}`; | ||||||
| } | } | ||||||
|  |  | ||||||
| export function setCustomEndpoints(mainEndpoint, backups) { | export function setCustomEndpoints({ main, backups, backupQueryUrl }) { | ||||||
|   currentEndpoint = mainEndpoint; |   currentEndpoint = main; | ||||||
|  |   backupEndpointsQueryUrl = null; | ||||||
|   if (Array.isArray(backups) && backups.length > 0) { |   if (Array.isArray(backups) && backups.length > 0) { | ||||||
|     backupEndpoints = backups; |     backupEndpoints = backups; | ||||||
|     pickFatestAvailableEndpoint(); |     pickFatestAvailableEndpoint(); | ||||||
|   } |   } | ||||||
|  |   if (typeof backupQueryUrl === 'string') { | ||||||
|  |     backupEndpointsQueryUrl = backupQueryUrl; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										21
									
								
								lib/index.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										21
									
								
								lib/index.d.ts
									
									
									
									
										vendored
									
									
								
							| @@ -21,7 +21,7 @@ export interface UpdateAvailableResult { | |||||||
|   metaInfo: string; |   metaInfo: string; | ||||||
|   pdiffUrl: string; |   pdiffUrl: string; | ||||||
|   diffUrl?: string; |   diffUrl?: string; | ||||||
| }; | } | ||||||
|  |  | ||||||
| export type CheckResult = | export type CheckResult = | ||||||
|   | ExpiredResult |   | ExpiredResult | ||||||
| @@ -40,7 +40,18 @@ export function switchVersionLater(hash: string): void; | |||||||
|  |  | ||||||
| export function markSuccess(): void; | export function markSuccess(): void; | ||||||
|  |  | ||||||
| export function setCustomEndpoints( | /** | ||||||
|   mainEndpoint: string, |  * @param {string} main - The main api endpoint | ||||||
|   backupEndpoints?: string[], |  * @param {string[]} [backups] - The back up endpoints. | ||||||
| ): void; |  * @param {string} [backupQueryUrl] - An url that return a json file containing an array of endpoint. | ||||||
|  |  *                                    like: ["https://backup.api/1", "https://backup.api/2"] | ||||||
|  |  */ | ||||||
|  | export function setCustomEndpoints({ | ||||||
|  |   main, | ||||||
|  |   backups, | ||||||
|  |   backupQueryUrl, | ||||||
|  | }: { | ||||||
|  |   main: string; | ||||||
|  |   backUps?: string[]; | ||||||
|  |   backupQueryUrl?: string; | ||||||
|  | }): void; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm