Skip to content

Commit fae293b

Browse files
committed
3.1.2
1 parent 9f95450 commit fae293b

3 files changed

Lines changed: 26 additions & 29 deletions

File tree

app/app-uploader.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,35 +265,32 @@ async function uploadDir(localDir, remoteDir){
265265

266266
console.log(':: Checking created file...');
267267
const rmeta = await app.getFileMeta([upload_info.path]);
268+
const fmeta = rmeta.info[0];
268269

269-
// hash check
270-
271-
let hashmatch;
272-
if(data.hash.chunks.length > 1){
273-
const hashStr = JSON.stringify(data.hash.chunks);
274-
const tbServerHash = crypto.createHash('md5').update(hashStr).digest('hex');
275-
hashmatch = tbServerHash == upload_info.md5;
276-
}
277-
else{
278-
hashmatch = data.hash.file == upload_info.md5;
279-
}
270+
// build weak etag
271+
const chunksJSON = JSON.stringify(data.hash.chunks);
272+
const chunksETAG = crypto.createHash('md5').update(chunksJSON).digest('hex');
273+
const weakEtag = data.hash.chunks.length > 1 ? chunksETAG : data.hash.file;
280274

281-
const hashMatchMsg = hashmatch ? 'MATCH' : 'MISMATCH';
282-
const logHashMatch = hashmatch ? console.log : console.error;
283-
logHashMatch(':: HASH:', upload_info.md5, `(${hashMatchMsg})`);
284-
285-
// file size check
286-
287-
const fsizeMatchMsg = data.size == rmeta.info[0].size ? 'MATCH' : 'MISMATCH';
288-
const logFSize = data.size == rmeta.info[0].size ? console.log : console.error;
289-
logFSize(':: SIZE:', rmeta.info[0].size, `(${fsizeMatchMsg})`);
275+
// hash check
276+
const hashMatch = weakEtag === fmeta.md5;
277+
const hashMatchMsg = hashMatch ? 'MATCH' : 'MISMATCH';
278+
const logHashMatch = hashMatch ? console.log : console.error;
279+
logHashMatch(':: HASH:', fmeta.md5, `(${hashMatchMsg})`);
290280

291-
// skip deleting tbtemp file...
281+
// size check
282+
const sizeMatch = data.size === fmeta.size;
283+
const sizeMatchMsg = sizeMatch ? 'MATCH' : 'MISMATCH';
284+
const logSizeMatch = sizeMatch ? console.log : console.error;
285+
logSizeMatch(':: SIZE:', fmeta.size, `(${sizeMatchMsg})`);
292286

293-
if(data.size != rmeta.info[0].size || !hashmatch){
287+
// skip deleting tbtemp file if mismatch...
288+
if(!sizeMatch || !hashMatch){
289+
console.error(':: File is BAD!');
294290
continue;
295291
}
296292

293+
// remove tbtemp file if everything is ok
297294
console.log(':: File is OK!');
298295
removeTbTemp(tbtempfile);
299296
continue;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "terabox-node",
33
"name_ext": "TeraBox node",
4-
"version": "3.1.1",
4+
"version": "3.1.2",
55
"type": "module",
66
"bin": {
77
"tb-check": "app/app-check.js",
@@ -25,7 +25,7 @@
2525
"dateformat": "^5.0.3",
2626
"filesize": "^10.1.6",
2727
"qrcode-terminal": "^0.12.0",
28-
"terabox-api": "^1.3.8",
28+
"terabox-api": "^1.3.10",
2929
"tough-cookie": "^5.1.2",
3030
"undici": "^7.10.0",
3131
"yaml": "^2.8.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)