This commit is contained in:
COOL 2025-02-11 14:14:00 +08:00
parent 17cad1b1ca
commit 338c43eea7
6 changed files with 24 additions and 17 deletions

View File

@ -34,7 +34,8 @@ export class Utils {
const req = ctx.req;
return (
req.headers['x-forwarded-for'] ||
req.socket.remoteAddress.replace('::ffff:', '')
req.socket.remoteAddress?.replace('::ffff:', '') ||
''
);
}

View File

@ -210,7 +210,12 @@ export class BaseTranslateService {
const commLockExists = this.checkLockFile('comm');
const dictLockExists = this.checkDictLockFile();
if (!menuLockExists || !msgLockExists || !dictLockExists || !commLockExists) {
if (
!menuLockExists ||
!msgLockExists ||
!dictLockExists ||
!commLockExists
) {
const tasks = [];
if (!msgLockExists) {
tasks.push(this.genBaseMsg());
@ -473,17 +478,16 @@ export class BaseTranslateService {
this.createLockFile('msg');
}
/**
*
*/
async genCommMsg(){
async genCommMsg() {
const file = path.join(this.basePath, 'comm', 'zh-cn.json');
const scanPath = path.join(this.app.getBaseDir(), '..', 'src', 'modules');
const messages = {};
// 递归扫描目录
const scanDir = (dir: string) => {
// 递归扫描目录
const scanDir = (dir: string) => {
const files = fs.readdirSync(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
@ -536,7 +540,7 @@ export class BaseTranslateService {
await Promise.all(translatePromises);
this.createLockFile('comm');
}
/**
*
* @param text

View File

@ -5,14 +5,16 @@ import { DemoI18nService } from '../../service/i18n';
*
*/
@CoolController({
serviceApis: [{
method: 'en',
summary: '翻译成英文',
},
serviceApis: [
{
method: 'en',
summary: '翻译成英文',
},
{
method: 'tw',
summary: '翻译成繁体',
}],
},
],
service: DemoI18nService,
})
export class DemoI18nController extends BaseController {}

View File

@ -7,7 +7,7 @@ import { CoolCache } from '@cool-midway/core';
@Provide()
export class DemoCacheService {
// 数据缓存5秒
@CoolCache(5)
@CoolCache(5000)
async get() {
console.log('执行方法');
return {

View File

@ -15,7 +15,7 @@ export class DemoI18nService {
async en() {
const value = this.translate.comm('一个很Cool的框架')['en'];
console.log(value);
return value
return value;
}
/**
@ -24,6 +24,6 @@ export class DemoI18nService {
async tw() {
const value = this.translate.comm('一个很Cool的框架')['zh-tw'];
console.log(value);
return value
return value;
}
}

View File

@ -185,11 +185,10 @@ export class UserLoginService extends BaseService {
if (wxInfo) {
wxUserInfo.id = wxInfo.id;
}
await this.userWxEntity.save({
return this.userWxEntity.save({
...wxUserInfo,
type,
});
return wxUserInfo;
}
/**
@ -231,6 +230,7 @@ export class UserLoginService extends BaseService {
avatarUrl,
gender: wxUserInfo.gender,
tenantId: userInfo['tenantId'],
loginType: wxUserInfo.type,
};
await this.userInfoEntity.insert(userInfo);
}