From 3fc2d8d165b3ee0cdbd63b8e415ea87608bc30fd Mon Sep 17 00:00:00 2001 From: Sara <1622138424@qq.com> Date: Fri, 25 Aug 2023 11:13:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=AB=99=E5=AE=89=E5=85=A8=E6=80=A7?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8Ebug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++- package.json | 4 +- src/assets/css/color.css | 2 - src/components/admin/postEdit.vue | 52 ++++++-------- src/components/admin/resourceList.vue | 1 + src/components/comment/graffiti.vue | 57 ++++++--------- src/components/common/uploadPicture.vue | 95 ++++++++++++------------- src/main.js | 6 +- src/store/index.js | 32 +++------ src/utils/ajaxUpload.js | 77 ++++++++++++++++++++ src/utils/constant.js | 2 +- 11 files changed, 187 insertions(+), 149 deletions(-) create mode 100644 src/utils/ajaxUpload.js diff --git a/README.md b/README.md index 2c8626b..1d7b34b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,12 @@ - 优化:前端美化 - 优化:个别Bug修复 +### 2023年9月1日更新:安全,安全,安全 +- 优化:所有保存接口、邮件发送接口、文件上传接口都限制次数,防止恶意调用 +- 优化:修复vuex中用户信息丢失错乱的Bug +- 优化:文件上传模块改造,每次上传之前获取上传密钥,每个密钥只能上传一个文件 +- 优化:个别Bug修复 + ### 首页 ![首页](首页.jpg) @@ -103,7 +109,7 @@ npm run build 一定要`Star` -## 欢迎进群 +## 欢迎进群(一定要Star) 1. 交流(摸鱼) 2. 安装部署:互相帮助,争取每个人都零基础拥有自己的个人网站 3. 博客答疑:每段代码都是我自己写的,爱学习的小伙伴可以在这里提问,互相学习,互相进步 diff --git a/package.json b/package.json index 20b1354..7673a22 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,9 @@ "qs": "^6.10.3", "vue": "^2.6.11", "vue-baberrage": "^3.2.4", - "vue-ripple-directive": "^2.0.1", "vue-router": "^3.2.0", "vue-seamless-scroll": "^1.1.23", - "vuex": "^3.4.0", - "vuex-persistedstate": "^4.0.0" + "vuex": "^3.4.0" }, "devDependencies": { "@vue/cli-plugin-babel": "~4.5.0", diff --git a/src/assets/css/color.css b/src/assets/css/color.css index 0b6e63a..0f70c7d 100644 --- a/src/assets/css/color.css +++ b/src/assets/css/color.css @@ -23,8 +23,6 @@ /* 主题悬停背景 */ --gradualRed: linear-gradient(to right, #ff4b2b, #ff416c); - /* 水波纹 */ - --rippleColor: rgba(0, 0, 0, 0.5); /* 导航栏字体 */ --toolbarFont: #333333; /* 导航栏背景 */ diff --git a/src/components/admin/postEdit.vue b/src/components/admin/postEdit.vue index 59a7138..be25158 100644 --- a/src/components/admin/postEdit.vue +++ b/src/components/admin/postEdit.vue @@ -105,7 +105,6 @@ data() { return { id: this.$route.query.id, - token: "", article: { articleTitle: "", articleContent: "", @@ -164,7 +163,6 @@ created() { this.getSortAndLabel(); - this.getUpToken(); }, mounted() { @@ -172,45 +170,35 @@ }, methods: { - getUpToken() { - this.$http.get(this.$constant.baseURL + "/qiniu/getUpToken", {}, true) - .then((res) => { - if (!this.$common.isEmpty(res.data)) { - this.token = res.data; - } - }) - .catch((error) => { - this.$message({ - message: error.message, - type: "error" - }); - }); - }, imgAdd(pos, file) { - if (this.$common.isEmpty(this.token)) { - this.$message({ - message: "上传出错!", - type: "warning" - }); - return; - } - let suffix = ""; if (file.name.lastIndexOf('.') !== -1) { suffix = file.name.substring(file.name.lastIndexOf('.')); } - + let key = "articlePicture" + "/" + this.$store.state.currentAdmin.username.replace(/[^a-zA-Z]/g, '') + this.$store.state.currentAdmin.id + new Date().getTime() + Math.floor(Math.random() * 1000) + suffix; let fd = new FormData(); fd.append("file", file); - fd.append("token", this.token); - fd.append("key", "articlePicture" + "/" + this.$store.state.currentAdmin.username.replace(/[^a-zA-Z]/g, '') + this.$store.state.currentAdmin.id + new Date().getTime() + Math.floor(Math.random() * 1000) + suffix); + fd.append("key", key); - this.$http.uploadQiniu(this.$constant.qiniuUrl, fd) + this.$http.get(this.$constant.baseURL + "/qiniu/getUpToken", {key: key}, true) .then((res) => { - if (!this.$common.isEmpty(res.key)) { - let url = this.$constant.qiniuDownload + res.key; - this.$common.saveResource(this, "articlePicture", url, file.size, file.type, true); - this.$refs.md.$img2Url(pos, url); + if (!this.$common.isEmpty(res.data)) { + fd.append("token", res.data); + + this.$http.uploadQiniu(this.$constant.qiniuUrl, fd) + .then((res) => { + if (!this.$common.isEmpty(res.key)) { + let url = this.$constant.qiniuDownload + res.key; + this.$common.saveResource(this, "articlePicture", url, file.size, file.type, true); + this.$refs.md.$img2Url(pos, url); + } + }) + .catch((error) => { + this.$message({ + message: error.message, + type: "error" + }); + }); } }) .catch((error) => { diff --git a/src/components/admin/resourceList.vue b/src/components/admin/resourceList.vue index b1d5e3b..4d59382 100644 --- a/src/components/admin/resourceList.vue +++ b/src/components/admin/resourceList.vue @@ -3,6 +3,7 @@
+ diff --git a/src/components/comment/graffiti.vue b/src/components/comment/graffiti.vue index 7412d16..e000efa 100644 --- a/src/components/comment/graffiti.vue +++ b/src/components/comment/graffiti.vue @@ -85,7 +85,6 @@ }, data() { return { - token: "", context: {}, canvasMoveUse: false, // 存储当前表面状态数组-上一步 @@ -144,25 +143,8 @@ this.setCanvasStyle(); }, created() { - if (!this.$common.isEmpty(this.$store.state.currentUser)) { - this.getUpToken(); - } }, methods: { - getUpToken() { - this.$http.get(this.$constant.baseURL + "/qiniu/getUpToken") - .then((res) => { - if (!this.$common.isEmpty(res.data)) { - this.token = res.data; - } - }) - .catch((error) => { - this.$message({ - message: error.message, - type: "error" - }); - }); - }, canvasOutMove(e) { const canvas = document.querySelector("#canvas"); if (e.target !== canvas) { @@ -264,14 +246,6 @@ return; } - if (this.$common.isEmpty(this.token)) { - this.$message({ - message: "上传出错!", - type: "warning" - }); - return; - } - if (this.preDrawAry.length < 1) { this.$message({ message: "你还没画呢~", @@ -291,19 +265,32 @@ u8arr[n] = str.charCodeAt(n); } let obj = new Blob([u8arr], {type: mine}); + let key = "graffiti" + "/" + this.$store.state.currentUser.username.replace(/[^a-zA-Z]/g, '') + this.$store.state.currentUser.id + new Date().getTime() + Math.floor(Math.random() * 1000) + ".png"; let fd = new FormData(); fd.append("file", obj); - fd.append("token", this.token); - fd.append("key", "graffiti" + "/" + this.$store.state.currentUser.username.replace(/[^a-zA-Z]/g, '') + this.$store.state.currentUser.id + new Date().getTime() + Math.floor(Math.random() * 1000) + ".png"); + fd.append("key", key); - this.$http.uploadQiniu(this.$constant.qiniuUrl, fd) + this.$http.get(this.$constant.baseURL + "/qiniu/getUpToken", {key: key}) .then((res) => { - if (!this.$common.isEmpty(res.key)) { - this.clearContext(); - let url = this.$constant.qiniuDownload + res.key; - this.$common.saveResource(this, "graffiti", url, obj.size, obj.type); - let img = "<你画我猜," + url + ">"; - this.$emit("addGraffitiComment", img); + if (!this.$common.isEmpty(res.data)) { + fd.append("token", res.data); + + this.$http.uploadQiniu(this.$constant.qiniuUrl, fd) + .then((res) => { + if (!this.$common.isEmpty(res.key)) { + this.clearContext(); + let url = this.$constant.qiniuDownload + res.key; + this.$common.saveResource(this, "graffiti", url, obj.size, obj.type); + let img = "<你画我猜," + url + ">"; + this.$emit("addGraffitiComment", img); + } + }) + .catch((error) => { + this.$message({ + message: error.message, + type: "error" + }); + }); } }) .catch((error) => { diff --git a/src/components/common/uploadPicture.vue b/src/components/common/uploadPicture.vue index a45d14a..e5d1747 100644 --- a/src/components/common/uploadPicture.vue +++ b/src/components/common/uploadPicture.vue @@ -6,11 +6,12 @@ multiple drag :action="$constant.qiniuUrl" - :data="qiniuParam" :on-change="handleChange" :before-upload="beforeUpload" :on-success="handleSuccess" :on-error="handleError" + :on-remove="handleRemove" + :http-request="customUpload" :list-type="listType" :accept="accept" :limit="maxNumber" @@ -48,6 +49,8 @@