fix: fix getui.service cannot get client problem

pull/90/head
moonrailgun 2 years ago
parent 70f98c5226
commit a245373e00

@ -1,3 +1,4 @@
import { RequestError } from 'got';
import { TcService, TcDbService, InboxStruct, call } from 'tailchat-server-sdk'; import { TcService, TcDbService, InboxStruct, call } from 'tailchat-server-sdk';
import { GetuiClient } from '../lib/GetuiClient'; import { GetuiClient } from '../lib/GetuiClient';
import type { GetuiLogDocument, GetuiLogModel } from '../models/log'; import type { GetuiLogDocument, GetuiLogModel } from '../models/log';
@ -9,8 +10,6 @@ interface GetuiService
extends TcService, extends TcService,
TcDbService<GetuiLogDocument, GetuiLogModel> {} TcDbService<GetuiLogDocument, GetuiLogModel> {}
class GetuiService extends TcService { class GetuiService extends TcService {
client: GetuiClient = null;
get serviceName() { get serviceName() {
return 'plugin:com.msgbyte.getui'; return 'plugin:com.msgbyte.getui';
} }
@ -40,7 +39,8 @@ class GetuiService extends TcService {
return; return;
} }
this.initClient(); const { appId, appKey, masterSecert } = this.getuiInfo;
const client = new GetuiClient(appId, appKey, masterSecert);
this.registerLocalDb(require('../models/log').default); this.registerLocalDb(require('../models/log').default);
this.registerEventListener( this.registerEventListener(
@ -62,7 +62,7 @@ class GetuiService extends TcService {
}; };
try { try {
await this.client.singlePush(userId, title, content, payload); await client.singlePush(userId, title, content, payload);
await this.adapter.model.create({ await this.adapter.model.create({
userId, userId,
title, title,
@ -71,24 +71,24 @@ class GetuiService extends TcService {
success: true, success: true,
}); });
} catch (err) { } catch (err) {
let errorMsg = String(err);
if (err instanceof RequestError && err.response) {
errorMsg = String(err.response.body);
}
await this.adapter.model.create({ await this.adapter.model.create({
userId, userId,
title, title,
content, content,
payload, payload,
success: false, success: false,
errorMsg: String(err), errorMsg,
}); });
} }
} }
} }
); );
} }
initClient() {
const { appId, appKey, masterSecert } = this.getuiInfo;
this.client = new GetuiClient(appId, appKey, masterSecert);
}
} }
export default GetuiService; export default GetuiService;

Loading…
Cancel
Save