save
This commit is contained in:
parent
34bf3142f1
commit
839b90cfb0
|
|
@ -0,0 +1,22 @@
|
|||
quqw u uq2w3PORT=7777
|
||||
HOST=0.0.0.0
|
||||
NODE_ENV=development
|
||||
APP_KEY=lbWiz3KKfnBB9ML_nqWzUwH4eeIQ6w7n
|
||||
DRIVE_DISK=local
|
||||
DB_CONNECTION=mysql
|
||||
MYSQL_HOST=localhost
|
||||
MYSQL_PORT=3307
|
||||
MYSQL_USER=admin
|
||||
MYSQL_PASSWORD=Work1234
|
||||
MYSQL_DB_NAME=log_service
|
||||
FOLDER_LOGS=/home/logs
|
||||
JWT_KEY=DOMAYBIETDO
|
||||
SESSION_DRIVER=cookie
|
||||
URL_FILE_SHELL=/home/giteaHook.sh
|
||||
ZULIP_STREAM_ALERT=AUS_VN_Test
|
||||
ZULIP_TOPIC_ALERT=Test Log Alerts
|
||||
RUN_ENV=prod
|
||||
REDIS_CONNECTION=local
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=
|
||||
|
|
@ -18,6 +18,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
async function updateFileList() {
|
||||
//get date now
|
||||
let dateNow = moment(Date.now()).format("YYYY/MM/DD");
|
||||
const dateCheck = moment(Date.now()).format("YYYYMMDD");
|
||||
//Get list file in folder
|
||||
fileList = fs.readdirSync(folderPath);
|
||||
//Get date modified
|
||||
|
|
@ -28,10 +29,11 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
|
||||
//scan file today
|
||||
if (dateNow !== moment(stats.mtime).format("YYYY/MM/DD")) {
|
||||
fileList = fileList.filter((i) => i !== file);
|
||||
fileList = fileList.filter((i) => i !== file && i.includes(dateCheck));
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log(fileList)
|
||||
}
|
||||
|
||||
const checkSpecialVersion = (paragraph) => {
|
||||
|
|
@ -212,7 +214,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
report.$original.line === index + 1 &&
|
||||
report.$original.detected_content === value
|
||||
);
|
||||
if (checkLog2?.length === 0) {
|
||||
if (log && checkLog2?.length === 0) {
|
||||
await LogReport.create({
|
||||
detected_content: value,
|
||||
line: index + 1,
|
||||
|
|
@ -224,7 +226,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
console.log("ERROR CHECK ", fileName)
|
||||
}
|
||||
}
|
||||
if (checkLog?.length === 0) {
|
||||
if (log && checkLog?.length === 0) {
|
||||
await LogReport.create({
|
||||
detected_content: value,
|
||||
line: index + 1,
|
||||
|
|
@ -259,7 +261,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
report.$original.detected_content === checkVersion
|
||||
);
|
||||
|
||||
if (checkLog?.length === 0) {
|
||||
if (log && checkLog?.length === 0) {
|
||||
await LogReport.create({
|
||||
detected_content: checkVersion,
|
||||
line: index + 1,
|
||||
|
|
@ -299,7 +301,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
report.$original.detected_content === value
|
||||
);
|
||||
|
||||
if (checkLog?.length === 0) {
|
||||
if (log && checkLog?.length === 0) {
|
||||
await LogReport.create({
|
||||
detected_content: value,
|
||||
line: index + 1,
|
||||
|
|
@ -334,7 +336,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
report.$original.detected_content === checkVersion
|
||||
);
|
||||
|
||||
if (checkLog?.length === 0) {
|
||||
if (log && checkLog?.length === 0) {
|
||||
await LogReport.create({
|
||||
detected_content: checkVersion,
|
||||
line: index + 1,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -28,6 +28,7 @@
|
|||
"@adonisjs/repl": "^3.1.11",
|
||||
"@adonisjs/session": "^6.4.0",
|
||||
"@adonisjs/view": "^6.2.0",
|
||||
"@google-cloud/documentai": "^8.7.0",
|
||||
"@kaperskyguru/adonis-cache": "^2.1.1",
|
||||
"axios": "^1.4.0",
|
||||
"child_process": "^1.0.2",
|
||||
|
|
|
|||
253
start/routes.ts
253
start/routes.ts
|
|
@ -1,4 +1,4 @@
|
|||
import fs from 'fs';
|
||||
import fs from "fs";
|
||||
import axios from "axios";
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
@ -30,22 +30,23 @@ 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";
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
const util = require("util");
|
||||
const exec = util.promisify(require("child_process").exec);
|
||||
const { DocumentProcessorServiceClient } =
|
||||
require("@google-cloud/documentai").v1;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
runtimeCheckLogs(Env.get("FOLDER_LOGS"));
|
||||
|
||||
|
||||
Route.post("/api/getIndexSerialNumber", "ErpsController.getIndexSerialNumber")
|
||||
.middleware("checkToken").middleware(
|
||||
"writeLog"
|
||||
);
|
||||
// .middleware("writeLog");
|
||||
.middleware("checkToken")
|
||||
.middleware("writeLog");
|
||||
// .middleware("writeLog");
|
||||
|
||||
Route.post("/api/getParagraph", "ErpsController.getParagraph")
|
||||
.middleware("checkToken")
|
||||
.middleware("writeLog")
|
||||
|
||||
.middleware("checkToken")
|
||||
.middleware("writeLog");
|
||||
|
||||
//Users
|
||||
Route.post("/api/account/createUser", "UsersController.create").middleware(
|
||||
|
|
@ -61,18 +62,16 @@ Route.get("/api/log/showLog/:name?", "LogsController.showLog").middleware(
|
|||
"writeLog"
|
||||
);
|
||||
|
||||
Route.get("/api/getAllLogDetect", "LogsController.getAllLogDetect")
|
||||
Route.get("/api/getAllLogDetect", "LogsController.getAllLogDetect");
|
||||
|
||||
//Key-Value
|
||||
Route.post("/api/getKeyValue", "ValuesController.getKeyValue")
|
||||
Route.post("/api/getKeyValue", "ValuesController.getKeyValue");
|
||||
|
||||
Route.post("/api/deleteValue", "ValuesController.destroy").middleware(
|
||||
"writeLog"
|
||||
);
|
||||
|
||||
Route.post("/api/editValue", "ValuesController.edit").middleware(
|
||||
"writeLog"
|
||||
);
|
||||
Route.post("/api/editValue", "ValuesController.edit").middleware("writeLog");
|
||||
|
||||
Route.post("/api/addValue", "ValuesController.create").middleware("writeLog");
|
||||
|
||||
|
|
@ -125,48 +124,51 @@ Route.post("/api/backupProduct", async ({ request, response }) => {
|
|||
|
||||
Route.post("/api/sendMailInforDevice", async () => {
|
||||
try {
|
||||
sendDeviceInfora()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}).middleware("checkToken").middleware(
|
||||
"writeLog"
|
||||
);
|
||||
|
||||
Route.post("/api/private-log/getFileOnFolder", async ({ request, response }) => {
|
||||
try {
|
||||
let result = [];
|
||||
let path = request.all().folerPath;
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readdir(path, (err, entries) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
entries.forEach((entry) => {
|
||||
const entryPath = path+"/"+entry;
|
||||
|
||||
fs.stat(entryPath, (statErr, stats) => {
|
||||
if (statErr) {
|
||||
reject(statErr);
|
||||
return;
|
||||
}
|
||||
|
||||
const type = stats.isFile() ? "file" : "directory";
|
||||
result.push({ name: entryPath, type: type });
|
||||
|
||||
if (result.length === entries.length) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
sendDeviceInfora();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
})
|
||||
.middleware("checkToken")
|
||||
.middleware("writeLog");
|
||||
|
||||
Route.post(
|
||||
"/api/private-log/getFileOnFolder",
|
||||
async ({ request, response }) => {
|
||||
try {
|
||||
let result = [];
|
||||
let path = request.all().folerPath;
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readdir(path, (err, entries) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
entries.forEach((entry) => {
|
||||
const entryPath = path + "/" + entry;
|
||||
|
||||
fs.stat(entryPath, (statErr, stats) => {
|
||||
if (statErr) {
|
||||
reject(statErr);
|
||||
return;
|
||||
}
|
||||
|
||||
const type = stats.isFile() ? "file" : "directory";
|
||||
result.push({ name: entryPath, type: type });
|
||||
|
||||
if (result.length === entries.length) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Route.post("/api/private-log/readFile", async ({ request, response }) => {
|
||||
try {
|
||||
|
|
@ -176,14 +178,131 @@ Route.post("/api/private-log/readFile", async ({ request, response }) => {
|
|||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Route.post("/api/extension/addressDetect", async ({ request, response }) => {
|
||||
// TODO(developer): Uncomment these variables before running the sample.
|
||||
const projectId = "532287737140";
|
||||
const location = "us"; // Format is 'us' or 'eu'
|
||||
const processorId = "64ad0cc100561909"; // Create processor before running sample
|
||||
// const filePath = "https://int.ipsupply.com.au/upload/temp/packagepurchaseorder_17162360547876.jpeg";
|
||||
const mimeType = "image/jpeg"; // Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types
|
||||
const fieldMask = ["entities"]; // Optional. The fields to return in the Document object.
|
||||
const processorVersionId = "8aa31873669ac16f"; // Optional. Processor version to use
|
||||
const bucketName = "get-address"; // Replace with your GCS bucket name
|
||||
|
||||
// Set up authentication
|
||||
process.env.GOOGLE_APPLICATION_CREDENTIALS =
|
||||
"strategic-block-424302-v3-54b10fc7e085.json";
|
||||
|
||||
async function downloadFile(url, outputLocationPath) {
|
||||
const writer = fs.createWriteStream(outputLocationPath);
|
||||
const response = await axios({
|
||||
url,
|
||||
method: "GET",
|
||||
responseType: "stream",
|
||||
});
|
||||
response.data.pipe(writer);
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on("finish", resolve);
|
||||
writer.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
async function processDocument(filePath) {
|
||||
const client = new DocumentProcessorServiceClient();
|
||||
|
||||
let name;
|
||||
if (processorVersionId) {
|
||||
// The full resource name of the processor version, e.g.:
|
||||
// `projects/${projectId}/locations/${location}/processors/${processorId}/processorVersions/${processorVersionId}`
|
||||
name = client.processorVersionPath(
|
||||
projectId,
|
||||
location,
|
||||
processorId,
|
||||
processorVersionId
|
||||
);
|
||||
} else {
|
||||
// The full resource name of the processor, e.g.:
|
||||
// `projects/${projectId}/locations/${location}/processors/${processorId}`
|
||||
name = client.processorPath(projectId, location, processorId);
|
||||
}
|
||||
|
||||
// Download the file from URL
|
||||
let imageContent;
|
||||
const tempFilePath = path.join(__dirname, "images/temp.jpeg");
|
||||
if (filePath.includes("http")) {
|
||||
console.log("Download file");
|
||||
await downloadFile(filePath, tempFilePath);
|
||||
imageContent = fs.readFileSync(tempFilePath);
|
||||
} else {
|
||||
imageContent = fs.readFileSync(filePath);
|
||||
}
|
||||
// Read the file into memory
|
||||
// imageContent = fs.readFileSync(filePath);
|
||||
|
||||
// Load binary data
|
||||
const rawDocument = {
|
||||
content: imageContent,
|
||||
mimeType: mimeType,
|
||||
};
|
||||
|
||||
// Optional: Additional configurations for processing.
|
||||
const processOptions = {
|
||||
individualPageSelector: {
|
||||
pages: [1],
|
||||
},
|
||||
};
|
||||
|
||||
// Configure the process request
|
||||
const request = {
|
||||
name: name,
|
||||
rawDocument: rawDocument,
|
||||
fieldMask: fieldMask, // Join fieldMask array into a comma-separated string
|
||||
processOptions: processOptions,
|
||||
};
|
||||
|
||||
const [result] = await client.processDocument(request);
|
||||
|
||||
// For a full list of `Document` object attributes, reference this page:
|
||||
// https://cloud.google.com/document-ai/docs/reference/rest/v1/Document
|
||||
const document = result.document;
|
||||
|
||||
// Read the text recognition output from the processor
|
||||
console.log("The document contains the following text:");
|
||||
return extractAndPrintData(document.entities);
|
||||
}
|
||||
|
||||
// Function to extract and print data
|
||||
function extractAndPrintData(response) {
|
||||
let result = "";
|
||||
response.forEach((item) => {
|
||||
const type = item.type;
|
||||
const mentionText = item.mentionText;
|
||||
result += `${type} : ${mentionText}\n\n`;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
const { filePath } = request.all();;
|
||||
console.log(filePath)
|
||||
try {
|
||||
await processDocument(filePath).then((result)=>{
|
||||
console.log(result)
|
||||
response.status(200).send(JSON.stringify(result));
|
||||
}).catch((e)=>console.log(e));
|
||||
} catch (error) {
|
||||
response.status(500).send(`Error: ${error.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
Route.post("/api/find-value", async ({ request, response }) => {
|
||||
try {
|
||||
const { value } = request.all();
|
||||
|
||||
console.log(value)
|
||||
const { stdout, stderr } = await exec(`grep -nr "${value}" /home/logs`,{maxBuffer: 1024 * 500});
|
||||
console.log(value);
|
||||
const { stdout, stderr } = await exec(`grep -nrE "${value}" /home/logs`, {
|
||||
maxBuffer: 1024 * 500,
|
||||
});
|
||||
|
||||
// response.status(200).send("sdjkghs");
|
||||
response.status(200).send(JSON.stringify(stdout));
|
||||
|
|
@ -195,16 +314,16 @@ Route.post("/api/find-value", async ({ request, response }) => {
|
|||
|
||||
Route.post("/api/test", async () => {
|
||||
try {
|
||||
const logs = await Cache.get('logs')
|
||||
const logs = await Cache.get("logs");
|
||||
|
||||
if(logs){
|
||||
return {type: "cache", data: logs}
|
||||
}else{
|
||||
let data = await LogReport.all();
|
||||
Cache.set('logs', data, 120)
|
||||
return {type: "no cache", data: data}
|
||||
}
|
||||
if (logs) {
|
||||
return { type: "cache", data: logs };
|
||||
} else {
|
||||
let data = await LogReport.all();
|
||||
Cache.set("logs", data, 120);
|
||||
return { type: "no cache", data: data };
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
console.log(error);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue