因同步图片脚本性能问题, 暂时去掉hash比对

This commit is contained in:
结发受长生 2019-05-15 11:21:56 +08:00
parent eebc90135b
commit 58090f0ef2
2 changed files with 14 additions and 14 deletions

View File

@ -55,11 +55,11 @@ class ImageSynchronizer {
item.type = 'new' item.type = 'new'
return true return true
} }
else if (storageItems[index].eTag !== item.md5) { // else if (storageItems[index].eTag !== item.md5) {
// 文件名存在, 但是hash值不同, 代表有变化 // // 文件名存在, 但是hash值不同, 代表有变化
item.type = 'change' // item.type = 'change'
return true // return true
} // }
return false return false
}); });
// 处理待上传的文件 // 处理待上传的文件
@ -85,12 +85,12 @@ class ImageSynchronizer {
}).then(result => { }).then(result => {
// eTag是上传后远端校验的md5值, 用于和本地进行比对 // eTag是上传后远端校验的md5值, 用于和本地进行比对
let eTag = result.eTag.replace(/"/g,'') let eTag = result.eTag.replace(/"/g,'')
if(filesList[index].md5 === eTag) { // if(filesList[index].md5 === eTag) {
console.log(`${filesList[index].name} 上传成功, md5:${eTag} 类型: ${filesList[index].type}`) console.log(`${filesList[index].name} 上传成功, md5:${eTag} 类型: ${filesList[index].type}`)
} else { // } else {
console.warn(`${filesList[index].name} 上传出错, md5值不一致`) // console.warn(`${filesList[index].name} 上传出错, md5值不一致`)
console.warn(`===> 本地文件: ${filesList[index].md5}, 接口返回: ${eTag}`) // console.warn(`===> 本地文件: ${filesList[index].md5}, 接口返回: ${eTag}`)
} // }
this._uploadObject(filesList, ++index) this._uploadObject(filesList, ++index)
}) })
} }

View File

@ -17,12 +17,12 @@ function readDirSync(imageFolderPath, images, rootPath){
readDirSync(`${imageFolderPath}/${item}`, images, rootPath) readDirSync(`${imageFolderPath}/${item}`, images, rootPath)
}else{ }else{
//读取一个Buffer //读取一个Buffer
let buffer = fs.readFileSync(`${imageFolderPath}/${item}`) // let buffer = fs.readFileSync(`${imageFolderPath}/${item}`)
let fsHash = crypto.createHash('md5') // let fsHash = crypto.createHash('md5')
fsHash.update(buffer) // fsHash.update(buffer)
images.push({ images.push({
name: `${imageFolderPath}/${item}`.replace(rootPath, ''), name: `${imageFolderPath}/${item}`.replace(rootPath, ''),
md5: fsHash.digest('hex') // md5: fsHash.digest('hex')
}) })
} }
}) })