优化
This commit is contained in:
36
server/services/debug.service.ts
Normal file
36
server/services/debug.service.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { TcService, TcPureContext } from 'tailchat-server-sdk';
|
||||
import { sleep } from '../lib/utils';
|
||||
|
||||
export default class TestService extends TcService {
|
||||
get serviceName(): string {
|
||||
return 'debug';
|
||||
}
|
||||
|
||||
onInit(): void {
|
||||
this.registerAction('hello', this.echo, {
|
||||
params: {
|
||||
name: [{ type: 'string', optional: true }],
|
||||
},
|
||||
});
|
||||
this.registerAction('sleep', this.sleep, {
|
||||
params: {
|
||||
second: 'number',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Action
|
||||
echo(ctx: TcPureContext<{ name: string }>): string {
|
||||
console.log(ctx.meta);
|
||||
return `Hello ${
|
||||
ctx.params.name ?? ctx.meta.t('匿名用户')
|
||||
}, \nHere is your meta info: ${JSON.stringify(ctx.meta, null, 2)}`;
|
||||
}
|
||||
|
||||
// Action
|
||||
async sleep(ctx: TcPureContext<{ second: number }>) {
|
||||
await sleep(ctx.params.second * 1000);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user