From b78ca6a79371c93c802f4f3c750f817c2936e803 Mon Sep 17 00:00:00 2001 From: WongXX Date: Mon, 27 Jan 2025 17:37:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=BE=A9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9B=A3=E8=81=BD=E9=87=8D=E5=BE=A9=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 8386eb9..82d9759 100644 --- a/index.ts +++ b/index.ts @@ -5,9 +5,11 @@ import YAML from 'yaml' import {IrequestData} from './types.js' const path: string = YAML.parse(fs.readFileSync('../config.yml', 'utf-8')).path +const lock: string[] = [] fs.watch(path, async function (event, filename) { - if (!(filename && event === 'change')) return + if (!(filename && event === 'change') || lock.includes(filename)) return + lock.push(filename) const jpath: string = `${path}/${filename}` const requestData: IrequestData = JSON.parse(fs.readFileSync(jpath).toString()) if (requestData.Processed === true) return @@ -41,4 +43,7 @@ fs.watch(path, async function (event, filename) { } requestData.Processed = true fs.writeFileSync(jpath, JSON.stringify(requestData)) + setTimeout(() => { + lock.splice(lock.indexOf(filename), 1) + }, 300) })