Merge pull request '同步dev分支进度,可以开始2.0开发了' (#2) from dev into main

Reviewed-on: #2
This commit is contained in:
柏码の讲师 2024-12-20 16:34:56 +08:00
commit 2b9c0c60c6
4 changed files with 63 additions and 52 deletions

View File

@ -45,7 +45,7 @@ public class FlowLimitingFilter extends HttpFilter {
@Override
protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
String address = request.getRemoteAddr();
if (!tryCount(address))
if (!"OPTIONS".equals(request.getMethod()) && !tryCount(address))
this.writeBlockMessage(response);
else
chain.doFilter(request, response);
@ -72,9 +72,9 @@ public class FlowLimitingFilter extends HttpFilter {
* @throws IOException 可能的异常
*/
private void writeBlockMessage(HttpServletResponse response) throws IOException {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
response.setStatus(429);
response.setContentType("application/json;charset=utf-8");
PrintWriter writer = response.getWriter();
writer.write(RestBean.forbidden("操作频繁,请稍后再试").asJsonString());
writer.write(RestBean.failure(429, "请求频率过快,请稍后再试").asJsonString());
}
}

View File

@ -146,45 +146,43 @@ const editorOption = {
</script>
<template>
<div>
<el-drawer direction="btt" :model-value="show"
:size="650" @open="initEditor"
@close="emit('close')"
:show-close="false">
<template #header>
<div>
<div style="font-weight: bold">发表新的帖子</div>
<div style="font-size: 13px">发表您的内容之前请遵守相关法律法规不要出现骂人爆粗口这种不文明行为</div>
</div>
</template>
<div style="display: flex;gap: 10px">
<div style="width: 120px">
<el-select placeholder="选择类型..." v-model="editor.type" :disabled="!store.forum.types.length">
<el-option v-for="item in store.forum.types" :value="item.id" :label="item.name"/>
</el-select>
</div>
<div style="flex: 1">
<el-input maxlength="30" placeholder="请输入帖子标题..."
:prefix-icon="Document" v-model="editor.title"/>
</div>
</div>
<div style="margin-top: 15px;height: 450px;border-radius: 5px;overflow: hidden"
v-loading="editor.uploading"
element-loading-text="正在上传图片,请稍后...">
<quill-editor ref="refEditor" v-model:content="editor.text"
:options="editorOption" content-type="delta"
style="height: calc(100% - 44px)"/>
</div>
<div style="display: flex;justify-content: space-between;margin-top: 10px">
<div style="color: grey;font-size: 13px">
当前字数: {{ contentLength }}最大支持20000字
</div>
<div>
<el-button @click="submitTopic" type="success" plain>{{submitButton}}</el-button>
</div>
</div>
</el-drawer>
<el-drawer direction="btt" :model-value="show"
:size="650" @open="initEditor"
@close="emit('close')"
:show-close="false">
<template #header>
<div>
<div style="font-weight: bold">发表新的帖子</div>
<div style="font-size: 13px">发表您的内容之前请遵守相关法律法规不要出现骂人爆粗口这种不文明行为</div>
</div>
</template>
<div style="display: flex;gap: 10px">
<div style="width: 120px">
<el-select placeholder="选择类型..." v-model="editor.type" :disabled="!store.forum.types.length">
<el-option v-for="item in store.forum.types" :value="item.id" :label="item.name"/>
</el-select>
</div>
<div style="flex: 1">
<el-input maxlength="30" placeholder="请输入帖子标题..."
:prefix-icon="Document" v-model="editor.title"/>
</div>
</div>
<div style="margin-top: 15px;height: 450px;border-radius: 5px;overflow: hidden"
v-loading="editor.uploading"
element-loading-text="正在上传图片,请稍后...">
<quill-editor ref="refEditor" v-model:content="editor.text"
:options="editorOption" content-type="delta"
style="height: calc(100% - 44px)"/>
</div>
<div style="display: flex;justify-content: space-between;margin-top: 10px">
<div style="color: grey;font-size: 13px">
当前字数: {{ contentLength }}最大支持20000字
</div>
<div>
<el-button @click="submitTopic" type="success" plain>{{submitButton}}</el-button>
</div>
</div>
</el-drawer>
</template>
<style lang="less" scoped>

View File

@ -1,5 +1,6 @@
import axios from "axios";
import {ElMessage} from "element-plus";
import router from "@/router";
const authItemName = "authorize"
@ -11,7 +12,12 @@ const accessHeader = () => {
const defaultError = (error) => {
console.error(error)
ElMessage.error('发生了一些错误,请联系管理员')
const status = error.response.status
if (status === 429) {
ElMessage.error(error.response.data.message)
} else {
ElMessage.error('发生了一些错误,请联系管理员')
}
}
const defaultFailure = (message, status, url) => {
@ -43,26 +49,37 @@ function storeAccessToken(remember, token, expire){
sessionStorage.setItem(authItemName, str)
}
function deleteAccessToken() {
function deleteAccessToken(redirect = false) {
localStorage.removeItem(authItemName)
sessionStorage.removeItem(authItemName)
if(redirect) {
router.push({ name: 'welcome-login' })
}
}
function internalPost(url, data, headers, success, failure, error = defaultError){
axios.post(url, data, { headers: headers }).then(({data}) => {
if(data.code === 200)
if(data.code === 200) {
success(data.data)
else
} else if(data.code === 401) {
failure('登录状态已过期,请重新登录!')
deleteAccessToken(true)
} else {
failure(data.message, data.code, url)
}
}).catch(err => error(err))
}
function internalGet(url, headers, success, failure, error = defaultError){
axios.get(url, { headers: headers }).then(({data}) => {
if(data.code === 200)
if(data.code === 200) {
success(data.data)
else
} else if(data.code === 401) {
failure('登录状态已过期,请重新登录!')
deleteAccessToken(true)
} else {
failure(data.message, data.code, url)
}
}).catch(err => error(err))
}

View File

@ -18,7 +18,6 @@ import {get} from "@/net";
import {ElMessage} from "element-plus";
import TopicEditor from "@/components/TopicEditor.vue";
import {useStore} from "@/store";
import axios from "axios";
import router from "@/router";
import TopicCollectList from "@/components/TopicCollectList.vue";
import TopicTag from "@/components/TopicTag.vue";
@ -95,7 +94,7 @@ navigator.geolocation.getCurrentPosition(position => {
</script>
<template>
<div style="display: flex;margin: 20px auto;gap: 20px;max-width: 1000px">
<div style="display: flex;margin: 20px auto;gap: 20px;max-width: 1000px;padding: 0 20px">
<div style="flex: 1">
<light-card>
<div class="edit-topic">
@ -222,9 +221,6 @@ navigator.geolocation.getCurrentPosition(position => {
<div class="friend-link">
<el-image src="https://element-plus.org/images/vform-banner.png" style="height: 100%"/>
</div>
<div class="friend-link">
<el-image src="https://element-plus.org/images/sponsors/jnpfsoft.jpg" style="height: 100%"/>
</div>
</div>
</div>
</div>