Log_service/start/routes.ts

115 lines
3.5 KiB
TypeScript

import axios from "axios";
/*
|--------------------------------------------------------------------------
| Routes
|--------------------------------------------------------------------------
|
| This file is dedicated for defining HTTP routes. A single file is enough
| for majority of projects, however you can define routes in different
| files and just make sure to import them inside this file. For example
|
| Define routes in following two files
| ├── start/routes/cart.ts
| ├── start/routes/customer.ts
|
| and then import them inside `start/routes.ts` as follows
|
| import './routes/cart'
| import './routes/customer'
|
*/
import Route from "@ioc:Adonis/Core/Route";
import LogDetectFile from "App/Models/LogDetectFile";
import { runtimeCheckLogs } from "App/utils/runtimeCheckLogs";
import Env from "@ioc:Adonis/Core/Env";
import KeyValue from "App/Models/KeyValue";
runtimeCheckLogs(Env.get("FOLDER_LOGS"));
Route.get("/api/list", async () => {
const a = await LogDetectFile.all();
// console.log("first")
return a;
});
Route.post(
"/api/getIndexSerialNumber",
"ErpsController.getIndexSerialNumber"
).middleware("checkToken");
Route.post("/api/getParagraph", "ErpsController.getParagraph").middleware(
"checkToken"
);
Route.post("/api/account/createUser", "UsersController.create");
Route.post("/api/account/checkLogin", "UsersController.checkLogin");
Route.get("/api/log/showLog/:name?", async ({ request, response }) => {
const content = await axios.get(
"http://192.168.5.7:8080/" + request.params().name
);
let listKeyValues = await KeyValue.all();
// console.log(listKeyValues)
let data = content.data.split("\n");
// console.log(data)
data.map((line, index) => {
// console.log(line)
data[index] = "<span style='background-color:pink;'>" + (index + 1) + "</span>" + line;
listKeyValues
.map((obj) => obj.$original.value)
.map(async (value) => {
if (line.search(value) !== -1) {
// let keyWord = "";
// line.split(" ").map((word) => {
// if (word.toLocaleLowerCase().includes(value)) {
// keyWord = keyWord + word;
// }
// });
// if (value.length === keyWord.length || value.length + 1 === keyWord.length) {
data[index] =
data[index].slice(0, data[index].search(value)) +
"<span style='background-color:yellow;'>" +
value +
"</span>" +
data[index].slice(data[index].search(value) + value.length);
// }
}
});
});
// console.log(data)
response.send(
"<html>\
<body>\
<div style='width:100%;height:100%;word-wrap:break-word;white-space:pre;overflow: auto;font-family: monospace;text-rendering: auto;\
color: fieldtext;\
letter-spacing: normal;\
word-spacing: normal;\
line-height: normal;\
text-transform: none;\
text-indent: 0px;\
text-shadow: none;\
display: inline-block;\
text-align: start;\
appearance: auto;\
-webkit-rtl-ordering: logical;\
resize: auto;\
cursor: text;\
background-color: field;\
column-count: initial !important;\
writing-mode: horizontal-tb !important;\
box-sizing: border-box;\
margin: 0em;\
border-width: 1px;\
border-style: solid;\
border-color: -internal-light-dark(rgb(118, 118, 118), rgb(133, 133, 133));\
border-image: initial;\
padding: 2px;'>" +
data.join("\n") +
"</div>\
</body>\
</html>"
);
});