Merge branch 'master' into gva-2.4.6+

This commit is contained in:
奇淼(piexlmax
2022-01-01 00:59:16 +08:00
committed by GitHub
9 changed files with 47 additions and 26 deletions
@@ -2,6 +2,7 @@ package example
import ( import (
"fmt" "fmt"
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
"io/ioutil" "io/ioutil"
"mime/multipart" "mime/multipart"
"strconv" "strconv"
@@ -123,18 +124,18 @@ func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}"
// @Router /fileUploadAndDownload/removeChunk [post] // @Router /fileUploadAndDownload/removeChunk [post]
func (u *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) { func (u *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) {
fileMd5 := c.Query("fileMd5") var file example.ExaFile
fileName := c.Query("fileName") c.ShouldBindJSON(&file)
filePath := c.Query("filePath") err := utils.RemoveChunk(file.FileMd5)
err := utils.RemoveChunk(fileMd5)
if err != nil {
return
}
err = fileUploadAndDownloadService.DeleteFileChunk(fileMd5, fileName, filePath)
if err != nil { if err != nil {
global.GVA_LOG.Error("缓存切片删除失败!", zap.Error(err)) global.GVA_LOG.Error("缓存切片删除失败!", zap.Error(err))
response.FailWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "缓存切片删除失败", c) return
}
err = fileUploadAndDownloadService.DeleteFileChunk(file.FileMd5, file.FileName, file.FilePath)
if err != nil {
global.GVA_LOG.Error(err.Error(), zap.Error(err))
response.FailWithMessage(err.Error(), c)
} else { } else {
response.OkWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c) response.OkWithMessage("缓存切片删除成功", c)
} }
} }
@@ -7,9 +7,9 @@ import (
// file struct, 文件结构体 // file struct, 文件结构体
type ExaFile struct { type ExaFile struct {
global.GVA_MODEL global.GVA_MODEL
FileName string FileName string `json:"fileName"`
FileMd5 string FileMd5 string `json:"fileMd5"`
FilePath string FilePath string `json:"filePath"`
ExaFileChunk []ExaFileChunk ExaFileChunk []ExaFileChunk
ChunkTotal int ChunkTotal int
IsFinish bool IsFinish bool
@@ -56,7 +56,7 @@ func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath st
func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, fileName string, filePath string) error { func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, fileName string, filePath string) error {
var chunks []example.ExaFileChunk var chunks []example.ExaFileChunk
var file example.ExaFile var file example.ExaFile
err := global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error err := global.GVA_DB.Where("file_md5 = ? ", fileMd5).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error
if err != nil { if err != nil {
return err return err
} }
+3 -2
View File
@@ -60,8 +60,9 @@ func (a *api) Initialize() error {
{ApiGroup: "菜单", Method: "POST", Path: "/menu/addMenuAuthority", Description: "增加menu和角色关联关系"}, {ApiGroup: "菜单", Method: "POST", Path: "/menu/addMenuAuthority", Description: "增加menu和角色关联关系"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/findFile", Description: "寻找目标文件(秒传)"}, {ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/findFile", Description: "寻找目标文件(秒传)"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/breakpointContinueFinish", Description: "断点续传"}, {ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/breakpointContinue", Description: "断点续传"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/removeChunk", Description: "传完成"}, {ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/breakpointContinueFinish", Description: "断点续传完成"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/removeChunk", Description: "上传完成移除文件"},
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/upload", Description: "文件上传示例"}, {ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/upload", Description: "文件上传示例"},
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/deleteFile", Description: "删除文件"}, {ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/deleteFile", Description: "删除文件"},
+1
View File
@@ -56,6 +56,7 @@ func (c *casbin) Initialize() error {
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/findFile", V2: "GET"}, {PType: "p", V0: "888", V1: "/fileUploadAndDownload/findFile", V2: "GET"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinueFinish", V2: "POST"}, {PType: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinueFinish", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinue", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/removeChunk", V2: "POST"}, {PType: "p", V0: "888", V1: "/fileUploadAndDownload/removeChunk", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"}, {PType: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"},
+9
View File
@@ -16,6 +16,15 @@ export const findFile = (params) => {
}) })
} }
export const breakpointContinue = (data) => {
return service({
url: '/fileUploadAndDownload/breakpointContinue',
method: 'post',
headers: { 'Content-Type': 'multipart/form-data' },
data
})
}
export const breakpointContinueFinish = (params) => { export const breakpointContinueFinish = (params) => {
return service({ return service({
url: '/fileUploadAndDownload/breakpointContinueFinish', url: '/fileUploadAndDownload/breakpointContinueFinish',
+1 -1
View File
@@ -19,7 +19,7 @@
</template> </template>
<script> <script>
const path = process.env.VUE_APP_BASE_API const path = import.meta.env.VITE_BASE_API
import { getFileList } from '@/api/fileUploadAndDownload' import { getFileList } from '@/api/fileUploadAndDownload'
export default { export default {
props: { props: {
+3 -3
View File
@@ -36,11 +36,11 @@ service.interceptors.request.use(
} }
const token = store.getters['user/token'] const token = store.getters['user/token']
const user = store.getters['user/userInfo'] const user = store.getters['user/userInfo']
config.data = JSON.stringify(config.data)
config.headers = { config.headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'x-token': token, 'x-token': token,
'x-user-id': user.ID 'x-user-id': user.ID,
...config.headers
} }
return config return config
}, },
@@ -70,7 +70,7 @@ service.interceptors.response.use(
} else { } else {
ElMessage({ ElMessage({
showClose: true, showClose: true,
message: response.data.msg||decodeURI(response.headers.msg), message: response.data.msg || decodeURI(response.headers.msg),
type: 'error' type: 'error'
}) })
if (response.data.data && response.data.data.reload) { if (response.data.data && response.data.data.reload) {
+15 -6
View File
@@ -33,11 +33,11 @@
<script> <script>
import SparkMD5 from 'spark-md5' import SparkMD5 from 'spark-md5'
import axios from 'axios'
import { import {
findFile, findFile,
breakpointContinueFinish, breakpointContinueFinish,
removeChunk removeChunk,
breakpointContinue
} from '@/api/breakpoint' } from '@/api/breakpoint'
export default { export default {
name: 'BreakPoint', name: 'BreakPoint',
@@ -47,13 +47,18 @@ export default {
fileMd5: '', fileMd5: '',
formDataList: [], formDataList: [],
waitUpLoad: [], waitUpLoad: [],
waitNum: 0, waitNum: NaN,
limitFileSize: false, limitFileSize: false,
percentage: 0, percentage: 0,
percentageFlage: true, percentageFlage: true,
customColor: '#409eff' customColor: '#409eff'
} }
}, },
watch: {
waitNum() {
this.percentage = Math.floor(((this.formDataList.length - this.waitNum) / this.formDataList.length) * 100)
}
},
methods: { methods: {
// 选中文件的函数 // 选中文件的函数
async choseFile(e) { async choseFile(e) {
@@ -107,6 +112,7 @@ export default {
}) })
} else { } else {
this.waitUpLoad = [] // 秒传则没有需要上传的切片 this.waitUpLoad = [] // 秒传则没有需要上传的切片
this.$message.success('文件已秒传')
} }
this.waitNum = this.waitUpLoad.length // 记录长度用于百分比展示 this.waitNum = this.waitUpLoad.length // 记录长度用于百分比展示
} }
@@ -121,7 +127,6 @@ export default {
this.$message('请先上传文件') this.$message('请先上传文件')
return return
} }
this.percentage = Math.floor(((this.formDataList.length - this.waitNum) / this.formDataList.length) * 100)
if (this.percentage === 100) { if (this.percentage === 100) {
this.percentageFlage = false this.percentageFlage = false
} }
@@ -145,7 +150,10 @@ export default {
}, },
async upLoadFileSlice(item) { async upLoadFileSlice(item) {
// 切片上传 // 切片上传
await axios.post(import.meta.env.VITE_BASE_API + '/fileUploadAndDownload/breakpointContinue', item.formData) const fileRe = await breakpointContinue(item.formData)
if (fileRe.code !== 0) {
return
}
this.waitNum-- // 百分数增加 this.waitNum-- // 百分数增加
if (this.waitNum === 0) { if (this.waitNum === 0) {
// 切片传完以后 合成文件 // 切片传完以后 合成文件
@@ -154,13 +162,14 @@ export default {
fileMd5: this.fileMd5 fileMd5: this.fileMd5
} }
const res = await breakpointContinueFinish(params) const res = await breakpointContinueFinish(params)
if (res.success) { if (res.code === 0) {
// 合成文件过后 删除缓存切片 // 合成文件过后 删除缓存切片
const params = { const params = {
fileName: this.file.name, fileName: this.file.name,
fileMd5: this.fileMd5, fileMd5: this.fileMd5,
filePath: res.data.filePath filePath: res.data.filePath
} }
this.$message.success('上传成功')
await removeChunk(params) await removeChunk(params)
} }
} }