flat:代码合并

This commit is contained in:
Apcallover
2025-12-19 10:37:41 +08:00
3 changed files with 48 additions and 47 deletions

View File

@@ -1,6 +1,6 @@
/**
* FileValidator.js
* 封装好的文件安全校验类 (ES Module)
* 封装好的文件安全校验类
*/
// ==========================================
@@ -141,7 +141,7 @@ export class FileValidator {
// 获取文件头 Hex (读取足够长的字节以覆盖最长的魔数PNG需8字节)
const fileHeader = this._bufferToHex(buffer.slice(0, 8));
// 使用 startsWith 匹配 (兼容 4字节或8字节魔数)
// 使用 startsWith 匹配
if (fileHeader.startsWith(expectedMagic)) {
isSafe = true;
} else {
@@ -154,7 +154,7 @@ export class FileValidator {
reader.onerror = () => reject('文件读取失败,无法校验');
// 读取前 1KB 足够进行判断
// 读取前 1KB 进行判断
reader.readAsArrayBuffer(file.slice(0, 1024));
});
}
@@ -170,12 +170,12 @@ export class FileValidator {
// imageValidator
// .validate(file)
// .then(() => {
// statusDiv.textContent = `检测通过: ${file.name}`;
// statusDiv.textContent = `检测通过: ${file.name}`;
// statusDiv.style.color = 'green';
// console.log('图片校验通过,开始上传...');
// // upload(file)...
// })
// .catch((err) => {
// statusDiv.textContent = `检测失败: ${err}`;
// statusDiv.textContent = `检测失败: ${err}`;
// statusDiv.style.color = 'red';
// });