图片上传hash 有bug,修复
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import MD5 from 'crypto-js/md5.js';
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
|
||||
export const getHash = (file: string) => {
|
||||
if (!fs.existsSync(file)) return '';
|
||||
const content = fs.readFileSync(file, 'utf-8');
|
||||
return MD5(content).toString();
|
||||
const buffer = fs.readFileSync(file); // 不指定编码,返回 Buffer
|
||||
return crypto.createHash('md5').update(buffer).digest('hex');
|
||||
};
|
||||
|
||||
export const getBufferHash = (buffer: Buffer) => {
|
||||
return MD5(buffer.toString()).toString();
|
||||
return crypto.createHash('md5').update(buffer).digest('hex');
|
||||
};
|
||||
|
||||
export const getStringHash = (str: string) => {
|
||||
return MD5(str).toString();
|
||||
}
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
}
|
||||
Reference in New Issue
Block a user