From 2e9937c9b56fbd409ad080c80ae4f573866a6d33 Mon Sep 17 00:00:00 2001 From: Anduin Xue Date: Sun, 20 Apr 2025 12:39:16 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E6=A3=80=E6=9F=A5=EF=BC=8C=E7=A1=AE=E4=BF=9D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E8=B6=85=E8=BF=871MB=E9=99=90=E5=88=B6?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=8F=90=E7=A4=BA=E7=94=A8=E6=88=B7=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E6=88=96=E5=88=86=E5=89=B2=E6=96=87=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/manual_lint.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/manual_lint.js b/.github/manual_lint.js index bb982e2e..c7951916 100644 --- a/.github/manual_lint.js +++ b/.github/manual_lint.js @@ -3,11 +3,33 @@ const glob = util.promisify(require('glob')); const fs = require("fs").promises; const path = require('path'); +const MAX_FILE_SIZE = 1024 * 1024; // 1MB + +async function checkFileSize(filePath) { + try { + const stats = await fs.stat(filePath); + return stats.size; + } catch (error) { + console.error(`Error checking file size for ${filePath}: ${error.message}`); + return 0; + } +} async function main() { var errors = []; var directories = await glob(__dirname + '../../dishes/**/*.md'); + // Check all files in dishes directory for size + var allFiles = await glob(__dirname + '../../dishes/**/*'); + + // Check each file size + for (var filePath of allFiles) { + const fileSize = await checkFileSize(filePath); + if (fileSize > MAX_FILE_SIZE) { + errors.push(`文件 ${filePath} 超过了1MB大小限制 (${(fileSize/1048576).toFixed(2)}MB)! 请压缩图片或分割文件。`); + } + } + for (var filePath of directories) { var data = await fs.readFile(filePath, 'utf8'); var filename = path.parse(filePath).base.replace(".md","");