diff --git a/config.yml b/config.yml index 6e1af8c..76f16a7 100644 --- a/config.yml +++ b/config.yml @@ -1 +1,2 @@ -path: string \ No newline at end of file +path: string +deleteAfter: number \ No newline at end of file diff --git a/index.ts b/index.ts index 82d9759..1e2a085 100644 --- a/index.ts +++ b/index.ts @@ -2,15 +2,15 @@ import fs from 'fs' import got, {HTTPError, Options} from 'got' import YAML from 'yaml' -import {IrequestData} from './types.js' +import {Iconfig, IrequestData} from './types.js' -const path: string = YAML.parse(fs.readFileSync('../config.yml', 'utf-8')).path +const config: Iconfig = YAML.parse(fs.readFileSync('../config.yml', 'utf-8')) const lock: string[] = [] -fs.watch(path, async function (event, filename) { +fs.watch(config.path, async function (event, filename) { if (!(filename && event === 'change') || lock.includes(filename)) return lock.push(filename) - const jpath: string = `${path}/${filename}` + const jpath: string = `${config.path}/${filename}` const requestData: IrequestData = JSON.parse(fs.readFileSync(jpath).toString()) if (requestData.Processed === true) return const method: any = requestData.Request.Mode.toUpperCase() @@ -44,6 +44,9 @@ fs.watch(path, async function (event, filename) { requestData.Processed = true fs.writeFileSync(jpath, JSON.stringify(requestData)) setTimeout(() => { - lock.splice(lock.indexOf(filename), 1) - }, 300) + fs.unlinkSync(jpath) + setTimeout(() => { + lock.splice(lock.indexOf(filename), 1) + }, 300) + }, config.deleteAfter * 1000) }) diff --git a/types.ts b/types.ts index 4bd6060..e4fa269 100644 --- a/types.ts +++ b/types.ts @@ -12,3 +12,8 @@ export interface IrequestData { } Processed?: boolean } + +export interface Iconfig { + path: string + deleteAfter: number +}