|
|
@@ -25,6 +25,7 @@ import PQueue from 'p-queue'
|
|
|
import { randomUUID } from 'crypto'
|
|
|
import { setTimeout } from 'timers/promises'
|
|
|
import { SendMessageDto } from './dtos/send-message.dto'
|
|
|
+import { SysConfigService } from 'src/sys-config/sys-config.service'
|
|
|
|
|
|
@Injectable()
|
|
|
export class DeviceService implements OnModuleInit {
|
|
|
@@ -40,7 +41,8 @@ export class DeviceService implements OnModuleInit {
|
|
|
@InjectRepository(DeviceTask)
|
|
|
private deviceTaskRepository: Repository<DeviceTask>,
|
|
|
@InjectRepository(DeviceTaskItem)
|
|
|
- private deviceTaskItemRepository: Repository<DeviceTaskItem>
|
|
|
+ private deviceTaskItemRepository: Repository<DeviceTaskItem>,
|
|
|
+ private sysConfigService: SysConfigService
|
|
|
) {}
|
|
|
|
|
|
async onModuleInit() {
|
|
|
@@ -371,4 +373,31 @@ export class DeviceService implements OnModuleInit {
|
|
|
device.socketId
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
+ @Interval(5 * 60 * 1000)
|
|
|
+ async scheduleApkUpdate() {
|
|
|
+ const apkUrl = await this.sysConfigService.getString('modifier_apk', '')
|
|
|
+ if (!apkUrl) return
|
|
|
+ const apkVersion = await this.sysConfigService.getNumber('modifier_apk_version', 0)
|
|
|
+ if (!apkVersion) return
|
|
|
+ const devices = await this.deviceRepository.findBy({
|
|
|
+ online: true,
|
|
|
+ busy: false
|
|
|
+ })
|
|
|
+ for (const device of devices) {
|
|
|
+ if (!device.version || Number(device.version) < apkVersion) {
|
|
|
+ this.eventsGateway.send(
|
|
|
+ {
|
|
|
+ id: randomUUID(),
|
|
|
+ action: 'updateApk',
|
|
|
+ data: {
|
|
|
+ url: apkUrl
|
|
|
+ }
|
|
|
+ },
|
|
|
+ device.socketId
|
|
|
+ )
|
|
|
+ }
|
|
|
+ await setTimeout(1000)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|