137 lines
3.9 KiB
TypeScript
137 lines
3.9 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";
|
|
import ErpsController from "App/Controllers/Http/ErpsController";
|
|
|
|
runtimeCheckLogs(Env.get("FOLDER_LOGS"));
|
|
|
|
// Route.get("/api/list", async () => {
|
|
// const a = await LogDetectFile.all();
|
|
// return a;
|
|
// });
|
|
|
|
//ERP get index serial number
|
|
Route.post(
|
|
"/api/getIndexSerialNumber",
|
|
"ErpsController.getIndexSerialNumber"
|
|
).middleware("checkToken");
|
|
Route.post("/api/getParagraph", "ErpsController.getParagraph").middleware(
|
|
"checkToken"
|
|
);
|
|
|
|
//Users
|
|
Route.post("/api/account/createUser", "UsersController.create");
|
|
Route.post("/api/account/checkLogin", "UsersController.checkLogin");
|
|
|
|
//Log
|
|
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();
|
|
let data = content.data.split("\n");
|
|
data.map((line, index) => {
|
|
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) {
|
|
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>"
|
|
);
|
|
});
|
|
|
|
//Key-Value
|
|
|
|
Route.post("/api/getKeyValue", async ({ request, response }) => {
|
|
let data = await KeyValue.all();
|
|
response.status(200).send(data);
|
|
});
|
|
|
|
Route.post("/api/deleteValue", async ({ request, response }) => {
|
|
try {
|
|
const value = await KeyValue.findOrFail(request.all().id);
|
|
await value.delete();
|
|
response.status(200).send("DELETE VALUE SUCCESS!");
|
|
} catch (error) {
|
|
response.status(500).send("DELETE VALUE FAIL!");
|
|
}
|
|
});
|
|
|
|
Route.post("/api/addValue", async ({ request, response }) => {
|
|
try {
|
|
const value = await KeyValue.create({
|
|
key: request.all().key,
|
|
value: request.all().value,
|
|
model: "All",
|
|
});
|
|
response.status(200).send("ADD VALUE SUCCESS!");
|
|
} catch (error) {
|
|
response.status(500).send("ADD VALUE FAIL!");
|
|
}
|
|
});
|