v1.0.3
This commit is contained in:
@@ -200,10 +200,10 @@ public class CaptchaManager {
|
||||
String cacheKey = CACHE_KEY.formatted(uniqueId);
|
||||
String cacheValue = redisCaptcha.get(cacheKey);
|
||||
if (TimiJava.isEmpty(cacheValue)) {
|
||||
throw new TimiException(TimiCode.ARG_EXPIRED).msgKey("captcha.expire");
|
||||
throw new TimiException(TimiCode.ARG_EXPIRED, "captcha.expire");
|
||||
}
|
||||
if (!value.trim().equalsIgnoreCase(cacheValue)) {
|
||||
throw new TimiException(TimiCode.RESULT_BAD).msgKey("captcha.error");
|
||||
throw new TimiException(TimiCode.RESULT_BAD, "captcha.error");
|
||||
}
|
||||
// 清除缓存
|
||||
redisCaptcha.destroy(cacheKey);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.imyeyu.api.util;
|
||||
|
||||
import com.imyeyu.api.modules.common.service.SettingService;
|
||||
import com.imyeyu.lang.mapper.AbstractLanguageMapper;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.util.GlobalReturnHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.jgit.api.ArchiveCommand;
|
||||
@@ -42,20 +39,11 @@ public class InitApplication implements ApplicationRunner {
|
||||
private String devLang;
|
||||
|
||||
private final SettingService settingService;
|
||||
private final RedisMultilingual redisMultilingual;
|
||||
private final GlobalReturnHandler globalReturnHandler;
|
||||
|
||||
private void initGitCommand() {
|
||||
ArchiveCommand.registerFormat("tar.gz", new TarFormat());
|
||||
}
|
||||
|
||||
private void initMultilingual() {
|
||||
globalReturnHandler.setMultilingualHeader(mapping -> {
|
||||
AbstractLanguageMapper map = redisMultilingual.map(TimiSpring.getLanguage());
|
||||
return map.textArgs(mapping.getMsgKey(), mapping.getMsgArgs());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
Method[] methods = getClass().getDeclaredMethods();
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.imyeyu.api.util;
|
||||
|
||||
import com.imyeyu.api.TimiServerAPI;
|
||||
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||
import com.imyeyu.java.bean.Language;
|
||||
import com.imyeyu.lang.mapper.AbstractLanguageMapper;
|
||||
import com.imyeyu.utils.StringInterpolator;
|
||||
import org.jcodec.api.NotSupportedException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @version 2024-04-03 11:01
|
||||
*/
|
||||
public class RedisLanguage extends AbstractLanguageMapper {
|
||||
|
||||
private static final StringInterpolator INTERPOLATOR = new StringInterpolator(StringInterpolator.SIMPLE_OBJ);
|
||||
|
||||
public RedisLanguage(Language.Enum language) {
|
||||
super(language);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(String id, String value) {
|
||||
throw new NotSupportedException("not supported to add value, MultilingualService will auto cache when not found value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String id) {
|
||||
return text(id).equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String text(String id) {
|
||||
return TimiServerAPI.applicationContext.getBean(MultilingualService.class).get(id).getValue(language);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String textArgs(String id, Map<String, Object> args) {
|
||||
return INTERPOLATOR.inject(text(id), args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.imyeyu.api.util;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Multilingual;
|
||||
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.Language;
|
||||
import com.imyeyu.lang.message.MessageResolver;
|
||||
import com.imyeyu.utils.StringInterpolator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Redis 消息解析器
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-08-01 00:00
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RedisMessageResolver implements MessageResolver {
|
||||
|
||||
private static final StringInterpolator INTERPOLATOR = new StringInterpolator(StringInterpolator.SIMPLE_OBJ);
|
||||
|
||||
private final MultilingualService multilingualService;
|
||||
|
||||
@Override
|
||||
public String resolve(String messageCode, Map<String, Object> messageArgs, Language.Enum language) {
|
||||
if (TimiJava.isEmpty(messageCode)) {
|
||||
return "";
|
||||
}
|
||||
Language.Enum actualLanguage = language == null ? Language.Enum.zh_CN : language;
|
||||
Multilingual multilingual = multilingualService.get(messageCode);
|
||||
if (multilingual == null) {
|
||||
return INTERPOLATOR.inject(messageCode, messageArgs);
|
||||
}
|
||||
String template = multilingual.getValue(actualLanguage);
|
||||
if (TimiJava.isEmpty(template)) {
|
||||
return INTERPOLATOR.inject(messageCode, messageArgs);
|
||||
}
|
||||
return INTERPOLATOR.inject(template, messageArgs);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.imyeyu.api.util;
|
||||
|
||||
import com.imyeyu.java.bean.Language;
|
||||
import com.imyeyu.lang.multi.Multilingual;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @version 2024-04-03 11:15
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RedisMultilingual extends Multilingual {
|
||||
|
||||
@PostConstruct
|
||||
private void postConstruct() {
|
||||
Language.Enum[] languages = Language.Enum.values();
|
||||
for (Language.Enum language : languages) {
|
||||
add(language, new RedisLanguage(language));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user