diff --git a/app/utils/helper.ts b/app/utils/helper.ts index 3ef9bba..a0f4c95 100644 --- a/app/utils/helper.ts +++ b/app/utils/helper.ts @@ -14,3 +14,12 @@ export const checkSpecialVersion = (paragraph: string): string => { return ""; } }; + +export const checkDateWiki = (logString:string) => { + const now = new Date(); + const currentDate = `ngay ${String(now.getDate()).padStart(2, "0")}/${String(now.getMonth() + 1).padStart(2, "0")}/${now.getFullYear()}`; + + const lines = logString.split("
").slice(0,3); + const lineDate = lines?.length > 1 ? lines[1] : "" + return lineDate === currentDate +} \ No newline at end of file diff --git a/start/routes.ts b/start/routes.ts index a9b7fe5..7ee2592 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -30,6 +30,7 @@ import { sendDeviceInfora } from "App/utils/sendDeviceInfor"; import InfoDevice from "App/Models/InfoDevice"; import LogReport from "App/Models/LogReport"; import Cache from "@ioc:Kaperskyguru/Adonis-Cache"; +import { checkDateWiki } from "App/utils/helper"; const util = require("util"); const exec = util.promisify(require("child_process").exec); const { DocumentProcessorServiceClient } = @@ -407,7 +408,10 @@ License: ${license ?? ""} const oldContent = pageJson.query.pages[pageId]?.revisions?.[0]?.['*'] ?? '' // nối nội dung mới vào - const newText = `${text}\n\n${oldContent}` + const now = new Date(); + const lineDate = `${String(now.getDate()).padStart(2, "0")}/${String(now.getMonth() + 1).padStart(2, "0")}/${now.getFullYear()}`; + const scopeDate = `-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ngay ${lineDate}
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

` + const newText = `${scopeDate}${text}\n\n${checkDateWiki(oldContent) ? oldContent.replace(scopeDate, "") : oldContent}` // ============ EDIT PAGE ============ const formData = new FormData()