mirror of
https://github.com/nocobase/nocobase.git
synced 2026-08-30 16:56:07 +08:00
5d5f455b3c
* feat: environments plugin * feat: improve code * fix: improve code * feat: improve code * refactor: package description * feat: bulk import * fix: remove * refactor: file manager support environment variables * refactor: file manager support environment variables * refactor: map manager support environment variables * refactor: support environment variables * refactor: support environment variables * refactor: support delete environment variables * fix: bug * refactor: workflow support environment variables * refactor: email environment variables * refactor: support bulk import * refactor: support bulk import * refactor: support bulk import * refactor: support bulk import * refactor: code improve * feat: env * chore: update * feat: environment * fix: bug * fix: acl snippet * fix: acl snippets * chore: map manager * refactor: support line break * refactor: support password * chore: environment variables * fix: bug * fix: bug * chore: enviroment variables * chore: system settings * fix: improve code * feat: verification * feat: map * feat: file-manager * feat: notification * fix: bug * feat: workflow * fix: improve code * fix: bug * feat: data-source * feat: auth * fix: error * fix: bug * refactor: description * refactor: locale * refactor: locale * refactor: locale * refactor: code improve * refactor: locale * refactor: locale * style: style improve * fix: error * fix: bug * fix: bug * refactor: environment * fix: ellipsis * refactor: password * fix: bug * fix: bug * fix: bug * fix: bug * fix: bug * chore: test * fix: cache * fix: mysql dialect options * refactor: email config form * fix: bug * fix: bug * fix: authenticator.dataValues parse * fix: include undefined * fix: json * fix: json parse * chore: enviromentProvider * fix: acl * fix: rowKey * fix: update ProviderOptions.tsx * feat: get app instance * fix: bug * fix: text * fix: build error * fix: error * chore: migration rules options * chore: migration rules * refactor: code improve * feat: env v2 * chore: environment varibales * chore: environment serve * fix: getVariables * feat: improve code * fix: bug * chore: collection options for migration * chore: tree collection options * chore: migration rules * chore: migration rules * chore: env api * chore: env api * fix: optionsKeysNotAllowedInEnv * fix: required true * fix: improve code * fix: app refresh * fix: remove db.import * fix: type error * fix: map * refactor: locale improve * refactor: tx-cos * fix: undefined * refactor: code improve * chore: use bookworm * fix: npm add user * fix: npm login * fix: npm adduser * fix: npm adduser * fix: expect * fix: expect * fix: environmentVariables * refactor: support bulk delete & filter * refactor: locale improve * feat: filter * refactor: useGlobalVariable * fix: scope * fix: bug * fix: optionsKeysNotAllowedInEnv * fix: test error * fix: test * fix: test * feat: improve code --------- Co-authored-by: chenos <chenlinxh@gmail.com> Co-authored-by: Chareice <chareice@live.com>
131 lines
4.2 KiB
TypeScript
131 lines
4.2 KiB
TypeScript
/**
|
|
* This file is part of the NocoBase (R) project.
|
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
* Authors: NocoBase Team.
|
|
*
|
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
*/
|
|
|
|
import { Plugin } from '@nocobase/server';
|
|
import * as process from 'node:process';
|
|
import { resolve } from 'path';
|
|
import { getAntdLocale } from './antd';
|
|
import { getCronLocale } from './cron';
|
|
import { getCronstrueLocale } from './cronstrue';
|
|
|
|
async function getLang(ctx) {
|
|
const SystemSetting = ctx.db.getRepository('systemSettings');
|
|
const systemSetting = await SystemSetting.findOne();
|
|
const enabledLanguages: string[] = systemSetting.get('enabledLanguages') || [];
|
|
const currentUser = ctx.state.currentUser;
|
|
let lang = enabledLanguages?.[0] || process.env.APP_LANG || 'en-US';
|
|
if (enabledLanguages.includes(currentUser?.appLang)) {
|
|
lang = currentUser?.appLang;
|
|
}
|
|
if (ctx.request.query.locale && enabledLanguages.includes(ctx.request.query.locale)) {
|
|
lang = ctx.request.query.locale;
|
|
}
|
|
return lang;
|
|
}
|
|
|
|
export class PluginClientServer extends Plugin {
|
|
async beforeLoad() {}
|
|
|
|
async install() {
|
|
const uiSchemas = this.db.getRepository<any>('uiSchemas');
|
|
await uiSchemas.insert({
|
|
type: 'void',
|
|
'x-uid': 'nocobase-admin-menu',
|
|
'x-component': 'Menu',
|
|
'x-designer': 'Menu.Designer',
|
|
'x-initializer': 'MenuItemInitializers',
|
|
'x-component-props': {
|
|
mode: 'mix',
|
|
theme: 'dark',
|
|
// defaultSelectedUid: 'u8',
|
|
onSelect: '{{ onSelect }}',
|
|
sideMenuRefScopeKey: 'sideMenuRef',
|
|
},
|
|
properties: {},
|
|
});
|
|
}
|
|
|
|
async load() {
|
|
this.app.localeManager.setLocaleFn('antd', async (lang) => getAntdLocale(lang));
|
|
this.app.localeManager.setLocaleFn('cronstrue', async (lang) => getCronstrueLocale(lang));
|
|
this.app.localeManager.setLocaleFn('cron', async (lang) => getCronLocale(lang));
|
|
this.db.addMigrations({
|
|
namespace: 'client',
|
|
directory: resolve(__dirname, './migrations'),
|
|
context: {
|
|
plugin: this,
|
|
},
|
|
});
|
|
this.app.acl.allow('app', 'getLang');
|
|
this.app.acl.allow('app', 'getInfo');
|
|
this.app.acl.registerSnippet({
|
|
name: 'app',
|
|
actions: ['app:restart', 'app:refresh', 'app:clearCache'],
|
|
});
|
|
const dialect = this.app.db.sequelize.getDialect();
|
|
|
|
this.app.resourceManager.define({
|
|
name: 'app',
|
|
actions: {
|
|
async getInfo(ctx, next) {
|
|
const SystemSetting = ctx.db.getRepository('systemSettings');
|
|
const systemSetting = await SystemSetting.findOne();
|
|
const enabledLanguages: string[] = systemSetting.get('enabledLanguages') || [];
|
|
const currentUser = ctx.state.currentUser;
|
|
let lang = enabledLanguages?.[0] || process.env.APP_LANG || 'en-US';
|
|
if (enabledLanguages.includes(currentUser?.appLang)) {
|
|
lang = currentUser?.appLang;
|
|
}
|
|
|
|
const info: any = {
|
|
database: {
|
|
dialect,
|
|
},
|
|
version: await ctx.app.version.get(),
|
|
lang,
|
|
name: ctx.app.name,
|
|
theme: currentUser?.systemSettings?.theme || systemSetting?.options?.theme || 'default',
|
|
};
|
|
|
|
if (process.env['EXPORT_LIMIT']) {
|
|
info.exportLimit = parseInt(process.env['EXPORT_LIMIT']);
|
|
}
|
|
ctx.body = info;
|
|
await next();
|
|
},
|
|
async getLang(ctx, next) {
|
|
const lang = await getLang(ctx);
|
|
const resources = await ctx.app.localeManager.get(lang);
|
|
ctx.body = {
|
|
lang,
|
|
...resources,
|
|
};
|
|
await next();
|
|
},
|
|
async clearCache(ctx, next) {
|
|
await ctx.cache.reset();
|
|
await next();
|
|
},
|
|
async restart(ctx, next) {
|
|
ctx.app.runAsCLI(['restart'], { from: 'user' });
|
|
await next();
|
|
},
|
|
async refresh(ctx, next) {
|
|
ctx.app.runCommand('refresh');
|
|
await next();
|
|
},
|
|
},
|
|
});
|
|
|
|
this.app.auditManager.registerActions(['app:restart', 'app:refresh', 'app:clearCache']);
|
|
}
|
|
}
|
|
|
|
export default PluginClientServer;
|