fix upload

This commit is contained in:
EvaPeng 2020-12-20 14:21:50 +08:00
parent c25861a4e9
commit 5c60f4ac09
4 changed files with 15 additions and 12 deletions

View File

@ -126,7 +126,6 @@ export async function post(url, content = '', overwrite = false, onupload) {
return; return;
} }
debugger;
let fileSize = content.size; let fileSize = content.size;
let mb = 1024 * 1024; let mb = 1024 * 1024;
let fileSizeMB = fileSize / mb; let fileSizeMB = fileSize / mb;
@ -147,11 +146,12 @@ export async function post(url, content = '', overwrite = false, onupload) {
endInex = fileSize; endInex = fileSize;
} }
fileContent = blobSlice.call(allContent, startIndex, endInex); fileContent = blobSlice.call(allContent, startIndex, endInex);
debugger; debugger;
let params = `&fileID=${fileID}&chunckIndex=${index + 1}&totalChunck=${totalChunks}` let params = `&fileID=${fileID}&chunckIndex=${index + 1}&totalChunck=${totalChunks}`
await partialUpload(url, params, fileContent).catch(err => { await partialUpload(url, params, fileContent).then(() => {
debugger; tryCount = 0;
}).catch(err => {
if (tryCount <= 2) {//one file try three times if (tryCount <= 2) {//one file try three times
index--; index--;
tryCount++; tryCount++;
@ -159,7 +159,6 @@ export async function post(url, content = '', overwrite = false, onupload) {
throw err; throw err;
} }
}); });
tryCount = 0;
} }
} }

View File

@ -6,10 +6,12 @@ const getters = {
isPreview: state => state.previewMode, isPreview: state => state.previewMode,
selectedCount: state => state.selected.length, selectedCount: state => state.selected.length,
progress : state => { progress : state => {
/* eslint-disable no-debugger */
if (state.upload.progress.length == 0) { if (state.upload.progress.length == 0) {
return 0; return 0;
} }
debugger;
let sum = state.upload.progress.reduce((acc, val) => acc + val) let sum = state.upload.progress.reduce((acc, val) => acc + val)
return Math.ceil(sum / state.upload.size * 100); return Math.ceil(sum / state.upload.size * 100);
} }

View File

@ -12,9 +12,10 @@ const state = {
queue: [], queue: [],
uploads: {} uploads: {}
} }
/* eslint-disable no-debugger */
const mutations = { const mutations = {
setProgress(state, { id, loaded }) { setProgress(state, { id, loaded }) {
debugger;
Vue.set(state.progress, id, loaded) Vue.set(state.progress, id, loaded)
}, },
reset: (state) => { reset: (state) => {

View File

@ -139,7 +139,7 @@ var resourcePostPutHandler = withUser(func(w http.ResponseWriter, r *http.Reques
filePath = dir + spieceFileName filePath = dir + spieceFileName
if totalChunck != chunckIndex { if totalChunck != chunckIndex {
_, err := d.user.Fs.Stat(filePath) _, err := d.user.Fs.Stat(filePath)
if err != nil { if err == nil {
//the piece has exist //the piece has exist
isPieceHasUpload = true isPieceHasUpload = true
} }
@ -152,7 +152,7 @@ var resourcePostPutHandler = withUser(func(w http.ResponseWriter, r *http.Reques
return err return err
} }
file, err := d.user.Fs.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775) file, err = d.user.Fs.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775)
if err != nil { if err != nil {
return err return err
} }
@ -172,10 +172,11 @@ var resourcePostPutHandler = withUser(func(w http.ResponseWriter, r *http.Reques
if chunckIndex == totalChunck && totalChunckInt > 1 { if chunckIndex == totalChunck && totalChunckInt > 1 {
//merge all spiece files //merge all spiece files
itemPath := "" itemPath := ""
var err error
//create original file //create original file
file, _err := d.user.Fs.OpenFile(r.URL.Path, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0777) file, err = d.user.Fs.OpenFile(r.URL.Path, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0777)
if _err != nil { if err != nil {
return _err return err
} }
defer file.Close() defer file.Close()