Update api wiki

This commit is contained in:
Joseph Le 2025-09-25 19:41:00 +10:00
parent a811a77165
commit abfe83fb29
7 changed files with 701 additions and 247 deletions

View File

@ -79,7 +79,7 @@ export default class ErpsController {
return null;
};
const extractInfoFromLine = (line, index, fName) => {
const extractInfoFromLine = (line, index, fName, lines) => {
const cleanedLine = line.replace(/\r/g, "");
const results: any = [];
@ -163,7 +163,7 @@ export default class ErpsController {
}
// Processor board ID
if (cleanedLine.includes("Processor board ID")) {
if (cleanedLine.includes("Processor board ID") || cleanedLine.includes("Processor Board ID")) {
const PBID = extractSN(cleanedLine.split(" ").pop());
if (PBID?.length >= 8) {
results.push({
@ -214,7 +214,7 @@ export default class ErpsController {
const output = [];
lines.forEach((line, i) => {
const lineResult = extractInfoFromLine(line, i, fName);
const lineResult = extractInfoFromLine(line, i, fName, lines);
mergeLines(output, lineResult);
});
@ -222,7 +222,7 @@ export default class ErpsController {
});
const finalReport = report.filter(
(i) => i.SN && /^[A-Z0-9-]{5,}$/.test(i.SN) && i.PID
(i) => i.SN && /^[A-Z0-9-]{5,}$/.test(i.SN)
);
fs.writeFileSync(

View File

@ -171,7 +171,7 @@ export const checkIndexSN = async (
}
// Pattern: "Processor board ID"
if (line.includes("Processor board ID") && i >= beginLine) {
if ((line.includes("Processor board ID") || line.includes("Processor Board ID")) && i >= beginLine ) {
const parts = line.split(" ");
const PBID = parts[parts.length - 1]
?.replace("\r", "")
@ -206,9 +206,15 @@ export const checkIndexSN = async (
const pattern = /[\x00-\x20\x7F]/g;
const invalidPIDItems = output.filter(
(i) => i.PID !== "" && !i.PID.match(pattern)
(i) => !i.PID.match(pattern)
);
const fileName =
"./app/store/logsAPI/" +
moment().format("DD_MM_YYYY") +
".log";
if (invalidPIDItems.length > 0) {
const tokenStage = Env.get("STAGE_TOKEN_REQUEST");
const tokenProd = Env.get("INT_TOKEN_REQUEST");
@ -219,13 +225,20 @@ export const checkIndexSN = async (
// Try stage first
try {
await axios.post(
const response_stage = await axios.post(
"https://stage.nswteam.net/api/transferPostData",
data,
{
headers: { Authorization: "Bearer " + tokenStage },
}
);
addLogFunction(
fileName,
"URL: https://stage.nswteam.net/api/transferPostData\n" +
JSON.stringify(response_stage?.data, null, 2),
"Update SN index to stage.nswteam.net"
);
} catch (e) {
console.error("Error sending to stage.nswteam.net:", JSON.stringify(e));
}
@ -242,11 +255,6 @@ export const checkIndexSN = async (
);
console.log(nameF + " response\n", response_int.data);
const fileName =
"./app/store/logsAPI/" +
moment().format("DD_MM_YYYY") +
".log";
addLogFunction(
fileName,
"URL: https://int.ipsupply.com.au/api/transferPostData\n" +

View File

@ -3,7 +3,7 @@ const zulip = require("zulip-js");
const moment = require("moment");
const { addLogFunction } = require("./addLogFunctionJS");
(async () => {
(async () => {
// Launch a headless browser
const browser = await puppeteer.launch({
headless: true,
@ -25,50 +25,53 @@ const { addLogFunction } = require("./addLogFunctionJS");
// In ra nội dung của trang mới
setTimeout(async () => {
const tableData = await page.evaluate(() => {
const tbody = document.querySelector("tbody"); // Lựa chọn thẻ <tbody> cần trích xuất
const rows = tbody.querySelectorAll("tr"); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
const htmlContent = await page.evaluate(() => {
// const tbody = document.querySelector("tbody"); // Lựa chọn thẻ <tbody> cần trích xuất
// const rows = tbody.querySelectorAll("tr"); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
// Lặp qua từng hàng và lấy nội dung của các cột (thẻ <td>) trong hàng
const data = [];
// // Lặp qua từng hàng và lấy nội dung của các cột (thẻ <td>) trong hàng
// const data = [];
rows.forEach((row) => {
const columns = Array.from(row.querySelectorAll("td")); // Lựa chọn tất cả các cột (thẻ <td>) trong hàng
const rowData = columns.map((column) => column.textContent.trim()); // Lấy nội dung của các cột và xóa khoảng trắng
data.push(rowData); // Thêm dữ liệu của hàng vào mảng data
// rows.forEach((row) => {
// const columns = Array.from(row.querySelectorAll("td")); // Lựa chọn tất cả các cột (thẻ <td>) trong hàng
// const rowData = columns.map((column) => column.textContent.trim()); // Lấy nội dung của các cột và xóa khoảng trắng
// data.push(rowData); // Thêm dữ liệu của hàng vào mảng data
// });
const htmlContent = document.querySelector('.notification').outerHTML
return htmlContent || "";
});
return data.map((u) => u.join("\n\n"));
});
var TurndownService = require('turndown')
const turndownService = new TurndownService();
const markdown = turndownService.turndown(htmlContent);
await browser.close();
let params = {
type: "stream",
to: "networkToolBot",
topic: "powerSchedule",
content:
":warning: :date: :warning:\n\n" + tableData.join("\n\n") + "\n-------",
`:warning: <time:${(new Date()).toDateString()}> :warning:\n\n ${markdown.replaceAll('KDC 91B', ':warning:KDC 91B:warning:').replaceAll('B31', ':warning:B31:warning:')}\n-------`,
};
client.messages.send(params);
let checkTime = moment(Date.now()).format("DD_MM_YYYY").toString()
if (
tableData.filter((i) => (i.includes("KDC 91B") || i.includes("KDC91B")) && i.includes(checkTime))
.length > 0
) {
// if (
// markdown.filter((i) => (i.includes("KDC 91B") || i.includes("KDC91B")) && i.includes(checkTime))
// .length > 0
// ) {
let params = {
type: "stream",
to: "Cục tình báo",
topic: "Thông báo chung",
content:
":warning: :date: :warning:\n\n" +
tableData
.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))[0]
.replace(/KDC 91B/g, "**KDC 91B**") +
"\n-------",
};
client.messages.send(params);
}
// let params = {
// type: "stream",
// to: "Cục tình báo",
// topic: "Thông báo chung",
// content:
// ":warning: :date: :warning:\n\n" +
// markdown
// .filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))[0]
// .replace(/KDC 91B/g, "**KDC 91B**") +
// "\n-------",
// };
// client.messages.send(params);
// }
const fileName =
"/home/Log_service/app/store/logsAPI/" +
moment(Date.now()).format("DD_MM_YYYY").toString() +
@ -77,4 +80,4 @@ const { addLogFunction } = require("./addLogFunctionJS");
addLogFunction(fileName, JSON.stringify(params, null, 2), "powerSchedule")
}, 5000);
})();
})();

View File

@ -338,7 +338,7 @@ export const sendDeviceInfora = async () => {
});
const options = {
from: "admin@apactech.io",
to: "joseph@apactech.io",
to: "joseph@apactech.io, ips@ipsupply.com.au",
// to: "joseph@apactech.io",
subject: "(AUTO-REPORT) SERIAL NUMBER",
html:

448
package-lock.json generated
View File

@ -18,10 +18,12 @@
"@google-cloud/documentai": "^8.7.0",
"@kaperskyguru/adonis-cache": "^2.1.1",
"axios": "^1.4.0",
"axios-cookiejar-support": "^6.0.4",
"child_process": "^1.0.2",
"chokidar": "^3.5.3",
"crypto": "^1.0.1",
"dotenv": "^16.3.1",
"form-data": "^4.0.4",
"fs": "^0.0.1-security",
"helpers": "^0.0.6",
"jsonwebtoken": "^9.0.1",
@ -36,6 +38,8 @@
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.2",
"source-map-support": "^0.5.21",
"tough-cookie": "^5.1.2",
"turndown": "^7.2.1",
"zulip-js": "^2.0.9"
},
"devDependencies": {
@ -1131,6 +1135,11 @@
}
}
},
"node_modules/@mixmark-io/domino": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@mixmark-io/domino/-/domino-2.2.0.tgz",
"integrity": "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw=="
},
"node_modules/@mrmlnc/readdir-enhanced": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
@ -1777,12 +1786,9 @@
"dev": true
},
"node_modules/agent-base": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz",
"integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==",
"dependencies": {
"debug": "^4.3.4"
},
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz",
"integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==",
"engines": {
"node": ">= 14"
}
@ -2150,6 +2156,24 @@
"proxy-from-env": "^1.1.0"
}
},
"node_modules/axios-cookiejar-support": {
"version": "6.0.4",
"resolved": "https://registry.npmjs.org/axios-cookiejar-support/-/axios-cookiejar-support-6.0.4.tgz",
"integrity": "sha512-4Bzj+l63eGwnWDBFdJHeGS6Ij3ytpyqvo//ocsb5kCLN/rKthzk27Afh2iSkZtuudOBkHUWWIcyCb4GKhXqovQ==",
"dependencies": {
"http-cookie-agent": "^7.0.2"
},
"engines": {
"node": ">=20.0.0"
},
"funding": {
"url": "https://github.com/sponsors/3846masa"
},
"peerDependencies": {
"axios": ">=0.20.0",
"tough-cookie": ">=4.0.0"
}
},
"node_modules/b4a": {
"version": "1.6.4",
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
@ -2446,6 +2470,18 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-me-maybe": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.2.tgz",
@ -3335,6 +3371,19 @@
"url": "https://github.com/motdotla/dotenv?sponsor=1"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/duplexify": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.3.tgz",
@ -3631,11 +3680,52 @@
"is-arrayish": "^0.2.1"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-module-lexer": {
"version": "0.3.26",
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.3.26.tgz",
"integrity": "sha512-Va0Q/xqtrss45hWzP8CZJwzGSZJjDM5/MJRE3IXXnUCcVLElR9BRaE9F62BopysASyc4nM3uwhSW7FFB9nlWAA=="
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-set-tostringtag": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
"dependencies": {
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
@ -4186,12 +4276,14 @@
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"hasown": "^2.0.2",
"mime-types": "^2.1.12"
},
"engines": {
@ -4288,9 +4380,12 @@
}
},
"node_modules/function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/gaxios": {
"version": "6.6.0",
@ -4345,14 +4440,23 @@
}
},
"node_modules/get-intrinsic": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz",
"integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==",
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"dependencies": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-proto": "^1.0.1",
"has-symbols": "^1.0.3"
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
@ -4378,6 +4482,18 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/get-source": {
"version": "2.0.12",
"resolved": "https://registry.npmjs.org/get-source/-/get-source-2.0.12.tgz",
@ -4764,6 +4880,17 @@
"node": ">=14"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
@ -4870,10 +4997,10 @@
"node": ">=8"
}
},
"node_modules/has-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==",
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"engines": {
"node": ">= 0.4"
},
@ -4881,10 +5008,13 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
"node_modules/has-tostringtag": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
"dependencies": {
"has-symbols": "^1.0.3"
},
"engines": {
"node": ">= 0.4"
},
@ -4964,6 +5094,17 @@
"node": ">=8"
}
},
"node_modules/hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/haye": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/haye/-/haye-3.0.0.tgz",
@ -5059,6 +5200,29 @@
"node": ">=8"
}
},
"node_modules/http-cookie-agent": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/http-cookie-agent/-/http-cookie-agent-7.0.2.tgz",
"integrity": "sha512-aHaES6SOFtnSlmWu0yEaaQvu+QexUG2gscSAvMhJ7auzW8r/jYOgGrzuAm9G9nHbksuhz7Lw4zOwDHmfQaxZvw==",
"dependencies": {
"agent-base": "^7.1.4"
},
"engines": {
"node": ">=20.0.0"
},
"funding": {
"url": "https://github.com/sponsors/3846masa"
},
"peerDependencies": {
"tough-cookie": "^4.0.0 || ^5.0.0",
"undici": "^7.0.0"
},
"peerDependenciesMeta": {
"undici": {
"optional": true
}
}
},
"node_modules/http-errors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
@ -6211,6 +6375,14 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/md5": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/md5/-/md5-2.2.1.tgz",
@ -9174,6 +9346,22 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/tldts": {
"version": "6.1.86",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz",
"integrity": "sha512-WMi/OQ2axVTf/ykqCQgXiIct+mSQDFdH2fkwhPwgEwvJ1kSzZRiinb0zF2Xb8u4+OqPChmyI6MEu4EezNJz+FQ==",
"dependencies": {
"tldts-core": "^6.1.86"
},
"bin": {
"tldts": "bin/cli.js"
}
},
"node_modules/tldts-core": {
"version": "6.1.86",
"resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.86.tgz",
"integrity": "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA=="
},
"node_modules/tmp-cache": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/tmp-cache/-/tmp-cache-1.1.0.tgz",
@ -9256,6 +9444,17 @@
"url": "https://github.com/sponsors/Borewit"
}
},
"node_modules/tough-cookie": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz",
"integrity": "sha512-FVDYdxtnj0G6Qm/DhNPSb8Ju59ULcup3tuJxkFb5K8Bv2pUXILbf0xZWU8PX8Ov19OXljbUyveOFwRMwkXzO+A==",
"dependencies": {
"tldts": "^6.1.32"
},
"engines": {
"node": ">=16"
}
},
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
@ -9280,6 +9479,14 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
},
"node_modules/turndown": {
"version": "7.2.1",
"resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.1.tgz",
"integrity": "sha512-7YiPJw6rLClQL3oUKN3KgMaXeJJ2lAyZItclgKDurqnH61so4k4IH/qwmMva0zpuJc/FhRExBBnk7EbeFANlgQ==",
"dependencies": {
"@mixmark-io/domino": "^2.2.0"
}
},
"node_modules/type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
@ -10715,6 +10922,11 @@
"fs": "^0.0.1-security"
}
},
"@mixmark-io/domino": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@mixmark-io/domino/-/domino-2.2.0.tgz",
"integrity": "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw=="
},
"@mrmlnc/readdir-enhanced": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
@ -11282,12 +11494,9 @@
"dev": true
},
"agent-base": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz",
"integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==",
"requires": {
"debug": "^4.3.4"
}
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz",
"integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="
},
"aggregate-error": {
"version": "3.1.0",
@ -11563,6 +11772,14 @@
"proxy-from-env": "^1.1.0"
}
},
"axios-cookiejar-support": {
"version": "6.0.4",
"resolved": "https://registry.npmjs.org/axios-cookiejar-support/-/axios-cookiejar-support-6.0.4.tgz",
"integrity": "sha512-4Bzj+l63eGwnWDBFdJHeGS6Ij3ytpyqvo//ocsb5kCLN/rKthzk27Afh2iSkZtuudOBkHUWWIcyCb4GKhXqovQ==",
"requires": {
"http-cookie-agent": "^7.0.2"
}
},
"b4a": {
"version": "1.6.4",
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz",
@ -11781,6 +11998,15 @@
"get-intrinsic": "^1.0.2"
}
},
"call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"requires": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
}
},
"call-me-maybe": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.2.tgz",
@ -12467,6 +12693,16 @@
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz",
"integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ=="
},
"dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"requires": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
}
},
"duplexify": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.3.tgz",
@ -12721,11 +12957,40 @@
"is-arrayish": "^0.2.1"
}
},
"es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g=="
},
"es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw=="
},
"es-module-lexer": {
"version": "0.3.26",
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.3.26.tgz",
"integrity": "sha512-Va0Q/xqtrss45hWzP8CZJwzGSZJjDM5/MJRE3IXXnUCcVLElR9BRaE9F62BopysASyc4nM3uwhSW7FFB9nlWAA=="
},
"es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"requires": {
"es-errors": "^1.3.0"
}
},
"es-set-tostringtag": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
"requires": {
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
}
},
"escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
@ -13133,12 +13398,14 @@
"dev": true
},
"form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"hasown": "^2.0.2",
"mime-types": "^2.1.12"
}
},
@ -13210,9 +13477,9 @@
"optional": true
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
},
"gaxios": {
"version": "6.6.0",
@ -13255,14 +13522,20 @@
"dev": true
},
"get-intrinsic": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz",
"integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==",
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-proto": "^1.0.1",
"has-symbols": "^1.0.3"
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
}
},
"get-package-type": {
@ -13276,6 +13549,15 @@
"integrity": "sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==",
"dev": true
},
"get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"requires": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
}
},
"get-source": {
"version": "2.0.12",
"resolved": "https://registry.npmjs.org/get-source/-/get-source-2.0.12.tgz",
@ -13603,6 +13885,11 @@
"uuid": "^9.0.1"
}
},
"gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg=="
},
"graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
@ -13691,15 +13978,18 @@
"integrity": "sha512-Pq0h+hvsVm6dDEa8x82GnLSYHOzNDt7f0ddFa3FqcQlgzEiptPqL+XrOJNavjOzSYiYWIrgeVYYgGlLmnxwilQ==",
"dev": true
},
"has-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg=="
},
"has-symbols": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A=="
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ=="
},
"has-tostringtag": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
"requires": {
"has-symbols": "^1.0.3"
}
},
"has-value": {
"version": "1.0.0",
@ -13759,6 +14049,14 @@
"integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==",
"dev": true
},
"hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"requires": {
"function-bind": "^1.1.2"
}
},
"haye": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/haye/-/haye-3.0.0.tgz",
@ -13838,6 +14136,14 @@
"integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==",
"dev": true
},
"http-cookie-agent": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/http-cookie-agent/-/http-cookie-agent-7.0.2.tgz",
"integrity": "sha512-aHaES6SOFtnSlmWu0yEaaQvu+QexUG2gscSAvMhJ7auzW8r/jYOgGrzuAm9G9nHbksuhz7Lw4zOwDHmfQaxZvw==",
"requires": {
"agent-base": "^7.1.4"
}
},
"http-errors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
@ -14707,6 +15013,11 @@
}
}
},
"math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="
},
"md5": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/md5/-/md5-2.2.1.tgz",
@ -16982,6 +17293,19 @@
"convert-hrtime": "^3.0.0"
}
},
"tldts": {
"version": "6.1.86",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz",
"integrity": "sha512-WMi/OQ2axVTf/ykqCQgXiIct+mSQDFdH2fkwhPwgEwvJ1kSzZRiinb0zF2Xb8u4+OqPChmyI6MEu4EezNJz+FQ==",
"requires": {
"tldts-core": "^6.1.86"
}
},
"tldts-core": {
"version": "6.1.86",
"resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.86.tgz",
"integrity": "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA=="
},
"tmp-cache": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/tmp-cache/-/tmp-cache-1.1.0.tgz",
@ -17041,6 +17365,14 @@
"ieee754": "^1.2.1"
}
},
"tough-cookie": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz",
"integrity": "sha512-FVDYdxtnj0G6Qm/DhNPSb8Ju59ULcup3tuJxkFb5K8Bv2pUXILbf0xZWU8PX8Ov19OXljbUyveOFwRMwkXzO+A==",
"requires": {
"tldts": "^6.1.32"
}
},
"tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
@ -17062,6 +17394,14 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
},
"turndown": {
"version": "7.2.1",
"resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.1.tgz",
"integrity": "sha512-7YiPJw6rLClQL3oUKN3KgMaXeJJ2lAyZItclgKDurqnH61so4k4IH/qwmMva0zpuJc/FhRExBBnk7EbeFANlgQ==",
"requires": {
"@mixmark-io/domino": "^2.2.0"
}
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",

View File

@ -31,10 +31,12 @@
"@google-cloud/documentai": "^8.7.0",
"@kaperskyguru/adonis-cache": "^2.1.1",
"axios": "^1.4.0",
"axios-cookiejar-support": "^6.0.4",
"child_process": "^1.0.2",
"chokidar": "^3.5.3",
"crypto": "^1.0.1",
"dotenv": "^16.3.1",
"form-data": "^4.0.4",
"fs": "^0.0.1-security",
"helpers": "^0.0.6",
"jsonwebtoken": "^9.0.1",
@ -49,6 +51,8 @@
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.2",
"source-map-support": "^0.5.21",
"tough-cookie": "^5.1.2",
"turndown": "^7.2.1",
"zulip-js": "^2.0.9"
}
}

View File

@ -77,9 +77,11 @@ Route.post("/api/addValue", "ValuesController.create").middleware("writeLog");
Route.post("/api/backupProduct", async ({ request, response }) => {
try {
const from = request.all().from || moment(Date.now()).format("YYYYMMDD");
const to = request.all().to || moment(Date.now()).format("YYYYMMDD");
const res = await axios.post(
"https://logs.danielvu.com/api/getIndexSerialNumber",
{ from: request.all().from, to: request.all().to },
{ from: from, to: to },
{
headers: {
Authorization: request.headers().authorization?.replace(/"/g, ""),
@ -97,7 +99,7 @@ Route.post("/api/backupProduct", async ({ request, response }) => {
warehouse: res.data[index].warehouse,
};
});
const addProduct = await Product.createMany(res.data);
await Product.createMany(res.data);
// console.log(addProduct)
response.status(200).send("Add " + res.data.length + " success!");
await sendMessToZulip(
@ -105,9 +107,9 @@ Route.post("/api/backupProduct", async ({ request, response }) => {
"networkToolBot",
"Log service",
"Backup product " +
request.all().from +
from +
" to " +
request.all().to +
to +
" success with " +
res.data.length +
" products"
@ -287,10 +289,10 @@ Route.post("/api/extension/addressDetect", async ({ request, response }) => {
const { filePath } = request.all();;
console.log(filePath)
try {
await processDocument(filePath).then((result)=>{
await processDocument(filePath).then((result) => {
console.log(result)
response.status(200).send(JSON.stringify(result));
}).catch((e)=>console.log(e));
}).catch((e) => console.log(e));
} catch (error) {
response.status(500).send(`Error: ${error.message}`);
}
@ -328,3 +330,100 @@ Route.post("/api/test", async () => {
console.log(error);
}
});
Route.post('/api/wiki/page/insert', async ({ request, response }) => {
try {
const { title, data: dataPayload, pid, vid,sn, lineNumber, license } = request.all()
if (!title || !dataPayload) {
return response.status(422).send({ error: `'title' & 'text' is required` })
}
let text = ""
if(typeof dataPayload === "string")
text = dataPayload.replace(/\\n/g, '\n')
else if(Array.isArray(dataPayload)){
text = `<pre>
Line ${lineNumber ?? ""}:
PID: ${pid ?? ""}
VID: ${vid ?? ""}
SN: ${sn ?? ""}
List commands: ${dataPayload.map(value => value.command?.trim()).join(", ")}
License: ${license ?? ""}
</pre>
`
}
// ============ LOGIN LẤY COOKIE ============
const loginTokenRes = await fetch(
'https://jv.ipsupply.com.au/wiki/api.php?action=query&meta=tokens&type=login&format=json'
)
const loginToken = (await loginTokenRes.json())?.query?.tokens?.logintoken
if (!loginToken) return response.status(500).send('Không lấy được loginToken')
// gửi login
const bodyLogin = new URLSearchParams()
bodyLogin.append('username', 'Ips')
bodyLogin.append('password', 'Work1234%')
bodyLogin.append('logintoken', loginToken)
bodyLogin.append('format', 'json')
bodyLogin.append("loginreturnurl", "https://jv.ipsupply.com.au/wiki")
const loginRes = await fetch(
'https://jv.ipsupply.com.au/wiki/api.php?action=clientlogin',
{
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded', cookie: loginTokenRes.headers.get('set-cookie') ?? '' },
body: bodyLogin,
}
)
const loginCookies = loginRes.headers.raw()['set-cookie']?.join('; ') ?? ''
const loginData = await loginRes.json()
if (loginData?.clientlogin?.status !== 'PASS') {
return response.status(500).send(loginData)
}
// ============ LẤY CSRF TOKEN ============
const csrfRes = await fetch(
'https://jv.ipsupply.com.au/wiki/api.php?action=query&meta=tokens&type=csrf&format=json',
{
headers: { cookie: loginCookies },
}
)
const csrfToken = (await csrfRes.json())?.query?.tokens?.csrftoken
if (!csrfToken) return response.status(500).send('Không lấy được CSRF token')
// ============ LẤY PAGE CŨ ============
const pageRes = await fetch(
`https://jv.ipsupply.com.au/wiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=${encodeURIComponent(title)}`,
{
headers: { cookie: loginCookies },
}
)
const pageJson = await pageRes.json()
const pageId = Object.keys(pageJson.query.pages)[0]
const oldContent = pageJson.query.pages[pageId]?.revisions?.[0]?.['*'] ?? ''
// nối nội dung mới vào
const newText = `${text}\n\n${oldContent}`
// ============ EDIT PAGE ============
const formData = new FormData()
formData.append('text', newText)
formData.append('token', csrfToken)
const editRes = await fetch(
`https://jv.ipsupply.com.au/wiki/api.php?action=edit&format=json&title=${encodeURIComponent(title)}`,
{
method: 'POST',
headers: { cookie: loginCookies },
body: formData,
}
)
const editResult = await editRes.json()
return response.status(200).send(editResult)
} catch (err) {
console.error(err)
return response.status(500).send(err)
}
})