fix:文件同步bug修复,md5
This commit is contained in:
parent
68b831e155
commit
1247134435
|
@ -14,16 +14,17 @@ class UploadUtils {
|
|||
});
|
||||
static Bucket = 'note-1324909903'
|
||||
static Region = 'ap-beijing'
|
||||
|
||||
static staticStore
|
||||
constructor(store) {
|
||||
this.store = store;
|
||||
UploadUtils.staticStore = store;
|
||||
}
|
||||
getActiveFile() {
|
||||
let tableBarItem = JSON.parse(this.store.get("persist:tableBarItem"));
|
||||
if (!tableBarItem) {
|
||||
return;
|
||||
}
|
||||
return tableBarItem.activeKey ? tableBarItem.activeKey.replaceAll('"', "") : undefined;
|
||||
return tableBarItem.activeKey ? JSON.parse(tableBarItem.activeKey) : undefined;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -33,7 +34,6 @@ class UploadUtils {
|
|||
let dirMessage = JSON.parse(this.store.get("persist:dirMessage"));
|
||||
let fileMd5
|
||||
if (activeFile && dirMessage && dirMessage.data) {
|
||||
console.log("dirMessage.data", JSON.parse(dirMessage.data, []))
|
||||
let find = JSON.parse(dirMessage.data, []).find(file => file.fileId === activeFile || file.filePath === activeFile);
|
||||
if (find) {
|
||||
fileMd5 = find.fileMd5;
|
||||
|
@ -53,8 +53,9 @@ class UploadUtils {
|
|||
Bucket: UploadUtils.Bucket,
|
||||
Region: UploadUtils.Region,
|
||||
// 不能以 / 开头
|
||||
Key: activeFile,
|
||||
Key: process.platform==='win32'?activeFile.replaceAll("\\","/"):activeFile
|
||||
}, function (err, data) {
|
||||
console.log('upLoadFileUtil:',err || data);
|
||||
if (data && data.ETag) {
|
||||
// 文件存在,比较MD5值
|
||||
let onlineMd5 = data.ETag.replaceAll('"', "")
|
||||
|
@ -65,10 +66,11 @@ class UploadUtils {
|
|||
"buttons": ["确认"],
|
||||
"defaultId": 0
|
||||
});
|
||||
return
|
||||
}
|
||||
}else {
|
||||
UploadUtils.selfUploadFile(activeFile)
|
||||
}
|
||||
UploadUtils.selfUploadFile(activeFile,fileMd5)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -79,8 +81,9 @@ class UploadUtils {
|
|||
Bucket: UploadUtils.Bucket,
|
||||
Region: UploadUtils.Region,
|
||||
// 不能以 / 开头
|
||||
Key: activeFile,
|
||||
Key: process.platform==='win32'?activeFile.replaceAll("\\","/"):activeFile,
|
||||
}, function (err, data) {
|
||||
console.log('downLoadFileUtil:',err || data);
|
||||
if (data && data.ETag) {
|
||||
// 文件存在,比较MD5值
|
||||
let onlineMd5 = data.ETag.replaceAll('"', "")
|
||||
|
@ -91,19 +94,19 @@ class UploadUtils {
|
|||
"buttons": ["确认"],
|
||||
"defaultId": 0
|
||||
});
|
||||
return
|
||||
}
|
||||
}else {
|
||||
UploadUtils.selfDownLoadFile(activeFile)
|
||||
}
|
||||
UploadUtils.selfDownLoadFile(activeFile)
|
||||
})
|
||||
}
|
||||
|
||||
static selfUploadFile(activeFile) {
|
||||
console.log("cos.uploadFile")
|
||||
static selfUploadFile(activeFile,fileMd5) {
|
||||
console.log("cos.uploadFile",activeFile,fileMd5)
|
||||
UploadUtils.cos.uploadFile({
|
||||
Bucket: UploadUtils.Bucket, /* 填入您自己的存储桶,必须字段 */
|
||||
Region: UploadUtils.Region, /* 存储桶所在地域,例如 ap-beijing,必须字段 */
|
||||
Key: activeFile, /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),必须字段 */
|
||||
Key: process.platform==='win32'?activeFile.replaceAll("\\","/"):activeFile, /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),必须字段 */
|
||||
FilePath: activeFile, /* 必须 */
|
||||
SliceSize: 1024 * 1024 * 5, /* 触发分块上传的阈值,超过5MB使用分块上传,非必须 */
|
||||
onTaskReady: function (taskId) { /* 非必须 */
|
||||
|
@ -132,7 +135,7 @@ class UploadUtils {
|
|||
},
|
||||
// 支持自定义headers 非必须
|
||||
}, function (err, data) {
|
||||
console.log(err || data);
|
||||
console.log("uploadFile:callback:",err || data);
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -142,7 +145,7 @@ class UploadUtils {
|
|||
UploadUtils.cos.getObject({
|
||||
Bucket: UploadUtils.Bucket, /* 填入您自己的存储桶,必须字段 */
|
||||
Region: UploadUtils.Region, /* 存储桶所在地域,例如 ap-beijing,必须字段 */
|
||||
Key: activeFile, /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),必须字段 */
|
||||
Key: process.platform==='win32'?activeFile.replaceAll("\\","/"):activeFile, /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),必须字段 */
|
||||
Output: activeFile
|
||||
// 支持自定义headers 非必须
|
||||
}, function (err, data) {
|
||||
|
@ -161,6 +164,20 @@ class UploadUtils {
|
|||
"buttons": ["确认"],
|
||||
"defaultId": 0
|
||||
})
|
||||
// 修改store中Md5值
|
||||
let persist = UploadUtils.staticStore.get("persist:dirMessage");
|
||||
if (persist){
|
||||
let persistObj = JSON.parse(persist)
|
||||
let data1 = persistObj.data;
|
||||
console.log("data1",data1,Array.isArray(data1))
|
||||
let parseArray = JSON.parse(data1, []);
|
||||
let find =parseArray.find(file => file.fileId === activeFile || file.filePath === activeFile);
|
||||
if (find) {
|
||||
find.fileMd5=data.ETag.replaceAll('"',"");
|
||||
}
|
||||
persistObj.data=JSON.stringify(parseArray)
|
||||
UploadUtils.staticStore.set("persist:dirMessage",JSON.stringify(persistObj))
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -174,7 +191,7 @@ class UploadUtils {
|
|||
Bucket: UploadUtils.Bucket,
|
||||
Region: UploadUtils.Region,
|
||||
// 不能以 / 开头
|
||||
Key: activeFile,
|
||||
Key: process.platform==='win32'?activeFile.replaceAll("\\","/"):activeFile,
|
||||
}, function (err, data) {
|
||||
console.log("err || data.CommonPrefixes" + activeFile, err || data);
|
||||
if (data && data.ETag) {
|
||||
|
@ -199,11 +216,11 @@ class UploadUtils {
|
|||
"buttons": ["是", "否"],
|
||||
"defaultId": 0
|
||||
}) === 0) {
|
||||
UploadUtils.selfUploadFile(activeFile)
|
||||
UploadUtils.selfUploadFile(activeFile,fileMd5)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
UploadUtils.selfUploadFile(activeFile)
|
||||
UploadUtils.selfUploadFile(activeFile,fileMd5)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -87,14 +87,15 @@ const SaveFilePlugin=(props)=> {
|
|||
// 后期不再读取文件,直接读取文件MD5
|
||||
importFile(filePath).then(value => {
|
||||
let save
|
||||
let newFileMd5
|
||||
let oldFileMd5
|
||||
let newFileMd5 =md5(resultSave)
|
||||
if (props.filePath.endsWith(".md")){
|
||||
// editorState
|
||||
newFileMd5 = md5(value.toString());
|
||||
save = (isEmpty(value)) || md5(resultSave) !== newFileMd5;
|
||||
oldFileMd5 = md5(value.toString());
|
||||
save = (isEmpty(value)) || newFileMd5 !== oldFileMd5;
|
||||
}else {
|
||||
newFileMd5 = md5(JSON.stringify(JSON.parse(value.toString())));
|
||||
save = (isEmpty(value)) || md5(resultSave) !== newFileMd5;
|
||||
oldFileMd5 = md5(JSON.stringify(JSON.parse(value.toString())));
|
||||
save = (isEmpty(value)) || newFileMd5 !== oldFileMd5;
|
||||
}
|
||||
if (save) {
|
||||
overWriteFile(filePath, resultSave).then(()=>{
|
||||
|
|
Loading…
Reference in New Issue