|
|
@@ -1,3 +1,4 @@
|
|
|
+import { count } from 'console'
|
|
|
import { Logger } from '@nestjs/common'
|
|
|
import axios from 'axios'
|
|
|
import { readFileSync } from 'fs'
|
|
|
@@ -5,22 +6,33 @@ import { resolve } from 'path'
|
|
|
import * as randomstring from 'randomstring'
|
|
|
|
|
|
export class IpmoyuProvider implements ProxyProvider {
|
|
|
- async genProfiles(country, num) {
|
|
|
- const {
|
|
|
- data: { data: countryList }
|
|
|
- } = await axios.get('http://global.ipmoyu.com/proxy/web/map/countryList', {
|
|
|
- params: {
|
|
|
- page: 1,
|
|
|
- limit: 1000
|
|
|
- }
|
|
|
- })
|
|
|
+ private countryList: {
|
|
|
+ abbr: string
|
|
|
+ chnName: string
|
|
|
+ continent: string
|
|
|
+ country: string
|
|
|
+ id: number
|
|
|
+ }[] = []
|
|
|
+ constructor() {
|
|
|
+ axios
|
|
|
+ .get('http://global.ipmoyu.com/proxy/web/map/countryList', {
|
|
|
+ params: {
|
|
|
+ page: 1,
|
|
|
+ limit: 1000
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(({ data }) => {
|
|
|
+ this.countryList = data.data
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- let countryId = countryList.find((i) => i.abbr === country.toUpperCase())?.id
|
|
|
+ async genProfiles(country, num) {
|
|
|
+ let countryId = this.countryList.find((i) => i.abbr === country.toUpperCase())?.id
|
|
|
if (!countryId) {
|
|
|
Logger.log(`Invalid country ${country}, use US as default`)
|
|
|
country = 'US'
|
|
|
}
|
|
|
- countryId = countryList.find((i) => i.abbr === country.toUpperCase())?.id
|
|
|
+ countryId = this.countryList.find((i) => i.abbr === country.toUpperCase())?.id
|
|
|
if (!countryId) {
|
|
|
throw new Error(`Invalid country ${country}`)
|
|
|
}
|