()
| 803 | } |
| 804 | |
| 805 | private async restoreJobs(): Promise<void> { |
| 806 | const runtime = tryGetCurrentRuntime(); |
| 807 | if (!runtime) return; |
| 808 | |
| 809 | const db = await this.getDb(); |
| 810 | await db.read(); |
| 811 | if (!db.data) db.data = { jobs: {} }; |
| 812 | if (!db.data.jobs) db.data.jobs = {}; |
| 813 | |
| 814 | const removedKeys: string[] = []; |
| 815 | for (const [key, stored] of Object.entries(db.data.jobs)) { |
| 816 | try { |
| 817 | const channel = deserializeChannel(stored.channel); |
| 818 | const userEntity = deserializeUser(stored.user); |
| 819 | this.scheduleExpiry(key, { |
| 820 | client: runtime.client, |
| 821 | channel, |
| 822 | chatKey: stored.chatKey, |
| 823 | peerId: toSendPeer(channel), |
| 824 | userEntity, |
| 825 | userId: stored.userId, |
| 826 | userDisplay: stored.userDisplay, |
| 827 | originalRank: stored.originalRank || "", |
| 828 | replyToMsgId: stored.replyToMsgId, |
| 829 | expiresAt: stored.expiresAt, |
| 830 | retryCount: stored.retryCount || 0, |
| 831 | }); |
| 832 | } catch (error) { |
| 833 | console.error(`[tmp_admin] 跳过无法恢复的任务 ${key}:`, error); |
| 834 | removedKeys.push(key); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | if (removedKeys.length > 0) { |
| 839 | await this.mutateDb((data) => { |
| 840 | for (const key of removedKeys) delete data.jobs[key]; |
| 841 | }); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | private async demoteAdmin(client: any, channel: any, userEntity: any, originalRank?: string): Promise<void> { |
| 846 | await client.invoke( |
no test coverage detected