|
@@ -66,19 +66,40 @@ export class DeviceService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async updateDevice1(id: string, country: string, clashProfile: string) {
|
|
|
|
|
- let device = await this.deviceRepository.findOneBy({ id })
|
|
|
|
|
- if (device) {
|
|
|
|
|
- device.pinCountry = country
|
|
|
|
|
- device.clashProfile = clashProfile
|
|
|
|
|
- if (device.pinCountry && !device.clashProfile) {
|
|
|
|
|
- const profiles = await this.ipmoyuProvider.genProfiles(device.pinCountry, 1)
|
|
|
|
|
- device.clashProfile = profiles[0]
|
|
|
|
|
- } else if (device.pinCountry === '') {
|
|
|
|
|
- device.clashProfile = ''
|
|
|
|
|
- }
|
|
|
|
|
- await this.deviceRepository.save(device)
|
|
|
|
|
|
|
+ async updateDevice1({
|
|
|
|
|
+ id,
|
|
|
|
|
+ pinCountry,
|
|
|
|
|
+ matchCountry,
|
|
|
|
|
+ clashProfile
|
|
|
|
|
+ }: {
|
|
|
|
|
+ id: string | string[]
|
|
|
|
|
+ pinCountry: string
|
|
|
|
|
+ matchCountry: Boolean
|
|
|
|
|
+ clashProfile: string
|
|
|
|
|
+ }) {
|
|
|
|
|
+ if (!id) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ let devices = []
|
|
|
|
|
+ if (Array.isArray(id)) {
|
|
|
|
|
+ devices = await this.deviceRepository.findBy({ id: In(id) })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ devices = [await this.deviceRepository.findOneBy({ id })]
|
|
|
}
|
|
}
|
|
|
|
|
+ await Promise.all(
|
|
|
|
|
+ devices.map(async (device) => {
|
|
|
|
|
+ device.pinCountry = pinCountry
|
|
|
|
|
+ device.matchCountry = matchCountry
|
|
|
|
|
+ device.clashProfile = clashProfile
|
|
|
|
|
+ if (device.pinCountry && !device.clashProfile) {
|
|
|
|
|
+ const profiles = await this.ipmoyuProvider.genProfiles(device.pinCountry, 1)
|
|
|
|
|
+ device.clashProfile = profiles[0]
|
|
|
|
|
+ } else if (device.pinCountry === '') {
|
|
|
|
|
+ device.clashProfile = ''
|
|
|
|
|
+ }
|
|
|
|
|
+ return await this.deviceRepository.save(device)
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async pinCountry(ids: number[], country: string) {
|
|
async pinCountry(ids: number[], country: string) {
|