feat: add config.service

pull/56/head
moonrailgun 2 years ago
parent dfcf129a3f
commit fe8e532a37

@ -96,7 +96,7 @@ export {
// model
export * as model from './model/__all__';
export { fetchAvailableServices } from './model/common';
export { fetchGlobalConfig } from './model/config';
export { fetchGlobalClientConfig } from './model/config';
export {
createDMConverse,
appendDMConverseMembers,

@ -21,8 +21,8 @@ export function getGlobalConfig() {
};
}
export async function fetchGlobalConfig(): Promise<GlobalConfig> {
const { data: config } = await request.get('/api/config/global');
export async function fetchGlobalClientConfig(): Promise<GlobalConfig> {
const { data: config } = await request.get('/api/config/client');
globalConfig = {
...globalConfig,

@ -10,7 +10,7 @@ import {
setTokenGetter,
showErrorToasts,
t,
fetchGlobalConfig,
fetchGlobalClientConfig,
request,
isValidStr,
isDevelopment,
@ -107,7 +107,7 @@ setErrorHook((err) => {
/**
*
*/
fetchGlobalConfig().catch((e) => {
fetchGlobalClientConfig().catch((e) => {
showErrorToasts(t('全局配置加载失败'));
console.error('全局配置加载失败', e);
});

@ -1,14 +1,11 @@
import {
TcService,
TcDbService,
TcPureContext,
config,
} from 'tailchat-server-sdk';
import { TcService, TcPureContext, config } from 'tailchat-server-sdk';
/**
*
*/
class ConfigService extends TcService {
config = {};
get serviceName(): string {
return 'config';
}
@ -19,19 +16,52 @@ class ConfigService extends TcService {
*
* 使
*/
this.registerAction('global', this.globalConfig);
this.registerAction('client', this.client);
this.registerAction('all', this.all, {
visibility: 'public',
});
this.registerAction('get', this.get, {
visibility: 'public',
params: {
key: 'string',
},
});
this.registerAction('set', this.set, {
visibility: 'public',
params: {
key: 'string',
value: 'any',
},
});
this.registerAuthWhitelist(['/config/global']);
this.registerAuthWhitelist(['/config/client']);
}
/**
*
*
*
* 使d
*/
async globalConfig(ctx: TcPureContext) {
async client(ctx: TcPureContext) {
return {
uploadFileLimit: config.storage.limit,
};
}
async all(ctx: TcPureContext) {
return this.config;
}
async get(ctx: TcPureContext<{ key: string }>) {
return this.config[ctx.params.key] ?? null;
}
async set(ctx: TcPureContext<{ key: string; value: string }>) {
const { key, value } = ctx.params;
this.config[key] = value;
await this.broker.broadcast('config.updated', this.config);
}
}
export default ConfigService;

Loading…
Cancel
Save