Merge pull request #28 from linhaojun857/dev

merge dev
master
花未眠 3 years ago committed by GitHub
commit 95827848ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,6 +22,6 @@ public class RedisPrefixConstant {
public static final String LOGIN_USER = "login_user";
public static final String USER_ARTICLE_ACCESS = "article_access";
public static final String ARTICLE_ACCESS = "article_access";
}

@ -52,8 +52,8 @@ public class ArticleController {
}
@ApiOperation("根据id获取文章")
@GetMapping("/articles/{id}")
public ResultVO<ArticleDTO> getArticleById(@PathVariable("id") Integer articleId) {
@GetMapping("/articles/{articleId}")
public ResultVO<ArticleDTO> getArticleById(@PathVariable("articleId") Integer articleId) {
return ResultVO.ok(articleService.getArticleById(articleId));
}

@ -17,11 +17,9 @@ public class BizException extends RuntimeException {
this.message = message;
}
public BizException(StatusCodeEnum statusCodeEnum) {
this.code = statusCodeEnum.getCode();
this.message = statusCodeEnum.getDesc();
}
}

@ -1,6 +1,7 @@
package com.aurora.exception;
public class TaskException extends Exception {
private static final long serialVersionUID = 1L;
private final Code code;
@ -9,8 +10,8 @@ public class TaskException extends Exception {
this(msg, code, null);
}
public TaskException(String msg, Code code, Exception nestedEx) {
super(msg, nestedEx);
public TaskException(String msg, Code code, Exception exception) {
super(msg, exception);
this.code = code;
}

@ -20,11 +20,6 @@ import java.nio.charset.StandardCharsets;
import static com.aurora.constant.CommonConstant.APPLICATION_JSON;
/**
* @author
*
*/
@Log4j2
@Component
@SuppressWarnings("all")
@ -35,19 +30,14 @@ public class AccessLimitInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws Exception {
// 如果请求输入方法
if (handler instanceof HandlerMethod) {
HandlerMethod hm = (HandlerMethod) handler;
// 获取方法中的注解,看是否有该注解
AccessLimit accessLimit = hm.getMethodAnnotation(AccessLimit.class);
if (accessLimit != null) {
long seconds = accessLimit.seconds();
int maxCount = accessLimit.maxCount();
// 关于key的生成规则可以自己定义 本项目需求是对每个方法都加上限流功能如果你只是针对ip地址限流那么key只需要只用ip就好
String key = IpUtil.getIpAddress(httpServletRequest) + hm.getMethod().getName();
// 从redis中获取用户访问的次数
try {
// 此操作代表获取该key对应的值自增1后的结果
long q = redisService.incrExpire(key, seconds);
if (q > maxCount) {
render(httpServletResponse, ResultVO.fail("请求过于频繁," + seconds + "秒后再试"));

@ -1,22 +1,35 @@
package com.aurora.listener;
import com.aurora.entity.ExceptionLog;
import com.aurora.entity.OperationLog;
import com.aurora.event.ExceptionLogEvent;
import com.aurora.event.OperationLogEvent;
import com.aurora.mapper.ExceptionLogMapper;
import com.aurora.mapper.OperationLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
public class ExceptionLogListener {
public class AuroraListener {
@Autowired
private OperationLogMapper operationLogMapper;
@Autowired
private ExceptionLogMapper exceptionLogMapper;
@Async
@EventListener(OperationLogEvent.class)
public void saveOperationLog(OperationLogEvent operationLogEvent) {
operationLogMapper.insert((OperationLog) operationLogEvent.getSource());
}
@Async
@EventListener(ExceptionLogEvent.class)
public void saveExceptionLog(ExceptionLogEvent exceptionLogEvent) {
exceptionLogMapper.insert((ExceptionLog) exceptionLogEvent.getSource());
}
}

@ -1,22 +0,0 @@
package com.aurora.listener;
import com.aurora.entity.OperationLog;
import com.aurora.event.OperationLogEvent;
import com.aurora.mapper.OperationLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
public class OperationLogListener {
@Autowired
private OperationLogMapper operationLogMapper;
@Async
@EventListener(OperationLogEvent.class)
public void saveOperationLog(OperationLogEvent operationLogEvent) {
operationLogMapper.insert((OperationLog) operationLogEvent.getSource());
}
}

@ -123,7 +123,7 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
if (articleForCheck.getStatus().equals(2)) {
Boolean isAccess;
try {
isAccess = redisService.sIsMember(USER_ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articleId);
isAccess = redisService.sIsMember(ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articleId);
} catch (Exception exception) {
throw new BizException(ARTICLE_ACCESS_FAIL);
}
@ -167,7 +167,7 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
throw new BizException("文章不存在");
}
if (article.getPassword().equals(articlePasswordVO.getArticlePassword())) {
redisService.sAdd(USER_ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articlePasswordVO.getArticleId());
redisService.sAdd(ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articlePasswordVO.getArticleId());
} else {
throw new BizException("密码错误");
}
@ -343,23 +343,23 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
if (CollectionUtils.isNotEmpty(tagNames)) {
List<Tag> existTags = tagService.list(new LambdaQueryWrapper<Tag>()
.in(Tag::getTagName, tagNames));
List<String> existTagNameList = existTags.stream()
List<String> existTagNames = existTags.stream()
.map(Tag::getTagName)
.collect(Collectors.toList());
List<Integer> existTagIds = existTags.stream()
.map(Tag::getId)
.collect(Collectors.toList());
tagNames.removeAll(existTagNameList);
tagNames.removeAll(existTagNames);
if (CollectionUtils.isNotEmpty(tagNames)) {
List<Tag> tagList = tagNames.stream().map(item -> Tag.builder()
List<Tag> tags = tagNames.stream().map(item -> Tag.builder()
.tagName(item)
.build())
.collect(Collectors.toList());
tagService.saveBatch(tagList);
List<Integer> tagIdList = tagList.stream()
tagService.saveBatch(tags);
List<Integer> tagIds = tags.stream()
.map(Tag::getId)
.collect(Collectors.toList());
existTagIds.addAll(tagIdList);
existTagIds.addAll(tagIds);
}
List<ArticleTag> articleTags = existTagIds.stream().map(item -> ArticleTag.builder()
.articleId(articleId)

@ -94,13 +94,13 @@ public class TalkServiceImpl extends ServiceImpl<TalkMapper, Talk> implements Ta
if (count == 0) {
return new PageResultDTO<>();
}
List<TalkAdminDTO> talkDTOList = talkMapper.listTalksAdmin(PageUtil.getLimitCurrent(), PageUtil.getSize(), conditionVO);
talkDTOList.forEach(item -> {
List<TalkAdminDTO> talkDTOs = talkMapper.listTalksAdmin(PageUtil.getLimitCurrent(), PageUtil.getSize(), conditionVO);
talkDTOs.forEach(item -> {
if (Objects.nonNull(item.getImages())) {
item.setImgs(CommonUtil.castList(JSON.parseObject(item.getImages(), List.class), String.class));
}
});
return new PageResultDTO<>(talkDTOList, count);
return new PageResultDTO<>(talkDTOs, count);
}
@Override

@ -88,6 +88,7 @@ public class UserAuthServiceImpl implements UserAuthService {
}
@Override
@SuppressWarnings("unchecked")
public List<UserAreaDTO> listUserAreas(ConditionVO conditionVO) {
List<UserAreaDTO> userAreaDTOs = new ArrayList<>();
switch (Objects.requireNonNull(getUserAreaType(conditionVO.getType()))) {

@ -22,6 +22,10 @@ import java.net.UnknownHostException;
@Component
public class IpUtil {
private static DbSearcher searcher;
private static Method method;
public static String getIpAddress(HttpServletRequest request) {
String ipAddress = request.getHeader("X-Real-IP");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
@ -56,26 +60,15 @@ public class IpUtil {
return StringUtils.substringBefore(ipAddress, ",");
}
private static DbSearcher searcher;
private static Method method;
/**
* ip2region.db
*/
@PostConstruct
private void initIp2regionResource() throws Exception {
InputStream inputStream = new ClassPathResource("/ip/ip2region.db").getInputStream();
//将 ip2region.db 转为 ByteArray
byte[] dbBinStr = FileCopyUtils.copyToByteArray(inputStream);
DbConfig dbConfig = new DbConfig();
searcher = new DbSearcher(dbConfig, dbBinStr);
//二进制方式初始化 DBSearcher需要使用基于内存的查找算法 memorySearch
method = searcher.getClass().getMethod("memorySearch", String.class);
}
/**
* ip
*/
public static String getIpSource(String ipAddress) {
if (ipAddress == null || !Util.isIpAddress(ipAddress)) {
log.error("Error: Invalid ip address");
@ -103,9 +96,6 @@ public class IpUtil {
return strings[1];
}
/**
* 访
*/
public static UserAgent getUserAgent(HttpServletRequest request) {
return UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
}

@ -46,7 +46,7 @@
</h1>
<ob-skeleton v-else tag="h1" height="3rem" />
<p v-if="article.articleContent">{{ article.articleContent }}</p>
<ob-skeleton v-else tag="p" :count="4" height="16px" />
<ob-skeleton v-else tag="p" :count="5" height="16px" />
<div class="article-footer" v-if="article.author && article.createTime">
<div class="flex flex-row items-center">
<img

@ -46,7 +46,7 @@
</h1>
<ob-skeleton v-else tag="h1" height="3rem" />
<p v-if="article.articleContent">{{ article.articleContent }}</p>
<ob-skeleton v-else tag="p" :count="3" height="20px" />
<ob-skeleton v-else tag="p" :count="4" height="20px" />
<div class="article-footer" v-if="article">
<div class="flex flex-row items-center">
<img
@ -101,9 +101,6 @@ export default defineComponent({
window.open(link)
}
const toArticle = () => {
if (articleStore.topArticle == '') {
return
}
let isAccess = false
userStore.accessArticles.forEach((item: any) => {
if (item == articleStore.topArticle.id) {

@ -5,22 +5,15 @@
data-dia="author">
<div class="profile absolute w-full flex flex-col justify-center items-center">
<div class="flex flex-col justify-center items-center">
<img
v-if="websiteConfig.authorAvatar !== ''"
:class="avatarClass"
:src="websiteConfig.authorAvatar"
alt="avatar" />
<ob-skeleton v-else width="7rem" height="7rem" circle />
<img v-if="websiteConfig.authorAvatar" :class="avatarClass" :src="websiteConfig.authorAvatar" />
<img v-else :class="avatarClass" :src="default" />
<h2 class="text-center pt-4 text-4xl font-semibold text-ob-bright">
<template v-if="websiteConfig.author">
{{ websiteConfig.author }}
</template>
<ob-skeleton v-else height="2.25rem" width="7rem" />
</h2>
<span class="h-1 w-14 rounded-full mt-2" :style="gradientBackground" />
<p
v-if="websiteConfig.authorIntro"
class="pt-6 px-10 w-full text-s text-center"
@ -70,6 +63,7 @@ export default defineComponent({
const appStore = useAppStore()
const { t } = useI18n()
return {
default: 'https://static.linhaojun.top/config/52a81cd2772167b645569342e81ce312.jpg',
avatarClass: computed(() => {
return {
'ob-avatar': true,

@ -2,7 +2,7 @@
<div class="sidebar-box">
<SubTitle :title="'titles.tag_list'" icon="tag" />
<TagList>
<template v-if="tags && tags.length > 0">
<template v-if="tags != '' && tags.length > 0">
<TagItem v-for="tag in tags" :key="tag.id" :id="tag.id" :name="tag.tagName" :count="tag.count" size="xs" />
<div class="flex flex-row items-center hover:opacity-50 mr-2 mb-2 cursor-pointer transition-all">
<span class="text-center px-3 py-1 rounded-md text-sm">
@ -12,15 +12,6 @@
</span>
</div>
</template>
<template v-else-if="tags">
<ob-skeleton tag="li" :count="10" height="20px" width="3rem" />
</template>
<template v-else>
<div class="flex flex-row justify-center items-center">
<svg-icon class="stroke-ob-bright mr-2" icon-class="warning" />
{{ t('settings.empty-tag') }}
</div>
</template>
</TagList>
</div>
</template>

@ -40,6 +40,9 @@ export default defineComponent({
clearInterval(timer)
})
const runTime = () => {
if (!appStore.websiteConfig.websiteCreateTime) {
return
}
let timeold = new Date().getTime() - new Date(appStore.websiteConfig.websiteCreateTime).getTime()
let msPerDay = 24 * 60 * 60 * 1000
let daysold = Math.floor(timeold / msPerDay)

@ -3,8 +3,8 @@ import { defineStore } from 'pinia'
export const useTagStore = defineStore('tagStore', {
state: () => {
return {
homeTags:'' as any,
tags: '' as any
homeTags: '' as any,
tags: '' as any
}
},
actions: {}

Loading…
Cancel
Save