update routes
This commit is contained in:
parent
aba12b380c
commit
ce1b146eca
|
|
@ -0,0 +1,115 @@
|
||||||
|
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
import Database from '@ioc:Adonis/Lucid/Database';
|
||||||
|
import KeyValue from 'App/Models/KeyValue';
|
||||||
|
import LogDetectFile from 'App/Models/LogDetectFile';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default class LogsController {
|
||||||
|
public async showLog({request, response}: HttpContextContract) {
|
||||||
|
try {
|
||||||
|
// fghf
|
||||||
|
console.log(request.params().name);
|
||||||
|
let fileDetect = await LogDetectFile.findBy(
|
||||||
|
"file_name",
|
||||||
|
request.params().name
|
||||||
|
);
|
||||||
|
let logsDetect = await Database.rawQuery(
|
||||||
|
"select * from log_reports where id_file = " + fileDetect?.id_ldf
|
||||||
|
);
|
||||||
|
|
||||||
|
let modelSpecialDetected = [];
|
||||||
|
let issueSpecialDetected = [];
|
||||||
|
let listLine = logsDetect[0]
|
||||||
|
.map((obj) => obj.line)
|
||||||
|
.filter((value, index, self) => {
|
||||||
|
return self.indexOf(value) === index;
|
||||||
|
})
|
||||||
|
.sort((a, b) => a - b);
|
||||||
|
|
||||||
|
const content = await axios.get(
|
||||||
|
request.params().name.search("AUTO") !== -1
|
||||||
|
? "http://192.168.5.7:8080/AUTOlog/" + request.params().name
|
||||||
|
: "http://192.168.5.7:8080/" + request.params().name
|
||||||
|
);
|
||||||
|
let allValue = await KeyValue.all();
|
||||||
|
let listKeyValues = allValue.filter(
|
||||||
|
(i) =>
|
||||||
|
i.$original.key === "MODEL_SPECIAL" ||
|
||||||
|
i.$original.key === "CATCH_FAULTY"
|
||||||
|
);
|
||||||
|
|
||||||
|
let MODEL_SPECIAL = allValue
|
||||||
|
.filter((i) => i.$original.key === "MODEL_SPECIAL")
|
||||||
|
.map((obj) => obj.$original.value);
|
||||||
|
|
||||||
|
let listExcludeErr = allValue
|
||||||
|
.filter((i) => i.$original.key === "EXCLUDE_ERR")
|
||||||
|
.map((obj) => obj.$original.value);
|
||||||
|
|
||||||
|
let data = content.data.split("\n");
|
||||||
|
data.map((line, index) => {
|
||||||
|
data[index] = index + 1 + "|-|" + line;
|
||||||
|
listKeyValues
|
||||||
|
.map((obj) => obj.$original.value)
|
||||||
|
.map(async (value) => {
|
||||||
|
if (
|
||||||
|
line.search(value) !== -1 &&
|
||||||
|
listExcludeErr.filter((err) => line.includes(err)).length === 0
|
||||||
|
) {
|
||||||
|
data[index] =
|
||||||
|
data[index].slice(0, data[index].search(value)) +
|
||||||
|
"|-|" +
|
||||||
|
value +
|
||||||
|
"|-|" +
|
||||||
|
data[index].slice(data[index].search(value) + value.length);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
listLine.map((u) => {
|
||||||
|
if (
|
||||||
|
listExcludeErr.filter((err) => data[u - 1].includes(err)).length === 0
|
||||||
|
) {
|
||||||
|
if (MODEL_SPECIAL.filter((i) => data[u - 1].includes(i)).length > 0) {
|
||||||
|
modelSpecialDetected.push(data[u - 1]);
|
||||||
|
} else {
|
||||||
|
issueSpecialDetected.push(data[u - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let modelSpecial =
|
||||||
|
modelSpecialDetected.length > 0 ? modelSpecialDetected.join("\n") : "";
|
||||||
|
let issueItem =
|
||||||
|
issueSpecialDetected.length > 0 ? issueSpecialDetected.join("\n") : "";
|
||||||
|
response.status(200).send({
|
||||||
|
modelSpecial: modelSpecial,
|
||||||
|
issueItem: issueItem,
|
||||||
|
contentFile: data.join("\n"),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// console.error(error);
|
||||||
|
response.status(203).send("FILE NOT FOUND");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getAllLogDetect({request, response}: HttpContextContract) {
|
||||||
|
try {
|
||||||
|
let fileDetect = await LogDetectFile.all();
|
||||||
|
let listFiles = fileDetect.map((obj) => obj.file_name);
|
||||||
|
response.status(200).send(listFiles);
|
||||||
|
} catch (error) {
|
||||||
|
response.status(203).send("NO FILE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async store({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async show({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async edit({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async update({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async destroy({}: HttpContextContract) {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import type { HttpContextContract } from "@ioc:Adonis/Core/HttpContext";
|
||||||
|
import KeyValue from "App/Models/KeyValue";
|
||||||
|
|
||||||
|
export default class ValuesController {
|
||||||
|
public async getKeyValue({ request, response }: HttpContextContract) {
|
||||||
|
let data = await KeyValue.all();
|
||||||
|
response.status(200).send(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async create({ request, response }: HttpContextContract) {
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async store({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async show({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async edit({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async update({}: HttpContextContract) {}
|
||||||
|
|
||||||
|
public async destroy({ request, response }: HttpContextContract) {
|
||||||
|
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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -51,6 +51,7 @@ const databaseConfig: DatabaseConfig = {
|
||||||
migrations: {
|
migrations: {
|
||||||
naturalSort: true,
|
naturalSort: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
healthCheck: false,
|
healthCheck: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
160
start/routes.ts
160
start/routes.ts
|
|
@ -1,4 +1,3 @@
|
||||||
import fs from "fs";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
@ -21,17 +20,8 @@ import axios from "axios";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Route from "@ioc:Adonis/Core/Route";
|
import Route from "@ioc:Adonis/Core/Route";
|
||||||
import LogDetectFile from "App/Models/LogDetectFile";
|
|
||||||
import { runtimeCheckLogs } from "App/utils/runtimeCheckLogs";
|
import { runtimeCheckLogs } from "App/utils/runtimeCheckLogs";
|
||||||
import Env from "@ioc:Adonis/Core/Env";
|
import Env from "@ioc:Adonis/Core/Env";
|
||||||
import KeyValue from "App/Models/KeyValue";
|
|
||||||
import ErpsController from "App/Controllers/Http/ErpsController";
|
|
||||||
import LogReport from "App/Models/LogReport";
|
|
||||||
import Database from "@ioc:Adonis/Lucid/Database";
|
|
||||||
import { exec } from "child_process";
|
|
||||||
import ImagesController from "App/Controllers/Http/ImagesController";
|
|
||||||
import { uploadFileToZulip } from "App/utils/uploadFileZulip";
|
|
||||||
import { screenShot } from "App/utils/screenShot";
|
|
||||||
import { sendMessToZulip } from "App/utils/sendMessToZulip";
|
import { sendMessToZulip } from "App/utils/sendMessToZulip";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import Product from "App/Models/Product";
|
import Product from "App/Models/Product";
|
||||||
|
|
@ -221,156 +211,16 @@ Route.post("/api/account/createUser", "UsersController.create");
|
||||||
Route.post("/api/account/checkLogin", "UsersController.checkLogin");
|
Route.post("/api/account/checkLogin", "UsersController.checkLogin");
|
||||||
|
|
||||||
//Log
|
//Log
|
||||||
Route.get("/api/log/showLog/:name?", async ({ request, response }) => {
|
Route.get("/api/log/showLog/:name?", "LogsController.showLog");
|
||||||
try {
|
|
||||||
// fghf
|
|
||||||
console.log(request.params().name);
|
|
||||||
let fileDetect = await LogDetectFile.findBy(
|
|
||||||
"file_name",
|
|
||||||
request.params().name
|
|
||||||
);
|
|
||||||
let logsDetect = await Database.rawQuery(
|
|
||||||
"select * from log_reports where id_file = " + fileDetect?.id_ldf
|
|
||||||
);
|
|
||||||
|
|
||||||
let modelSpecialDetected = [];
|
Route.get("/api/getAllLogDetect", "LogsController.getAllLogDetect");
|
||||||
let issueSpecialDetected = [];
|
|
||||||
let listLine = logsDetect[0]
|
|
||||||
.map((obj) => obj.line)
|
|
||||||
.filter((value, index, self) => {
|
|
||||||
return self.indexOf(value) === index;
|
|
||||||
})
|
|
||||||
.sort((a, b) => a - b);
|
|
||||||
|
|
||||||
const content = await axios.get(
|
|
||||||
request.params().name.search("AUTO") !== -1
|
|
||||||
? "http://192.168.5.7:8080/AUTOlog/" + request.params().name
|
|
||||||
: "http://192.168.5.7:8080/" + request.params().name
|
|
||||||
);
|
|
||||||
let allValue = await KeyValue.all();
|
|
||||||
let listKeyValues = allValue.filter(
|
|
||||||
(i) =>
|
|
||||||
i.$original.key === "MODEL_SPECIAL" ||
|
|
||||||
i.$original.key === "CATCH_FAULTY"
|
|
||||||
);
|
|
||||||
|
|
||||||
let MODEL_SPECIAL = allValue
|
|
||||||
.filter((i) => i.$original.key === "MODEL_SPECIAL")
|
|
||||||
.map((obj) => obj.$original.value);
|
|
||||||
|
|
||||||
let listExcludeErr = allValue
|
|
||||||
.filter((i) => i.$original.key === "EXCLUDE_ERR")
|
|
||||||
.map((obj) => obj.$original.value);
|
|
||||||
|
|
||||||
let data = content.data.split("\n");
|
|
||||||
data.map((line, index) => {
|
|
||||||
data[index] = index + 1 + "|-|" + line;
|
|
||||||
listKeyValues
|
|
||||||
.map((obj) => obj.$original.value)
|
|
||||||
.map(async (value) => {
|
|
||||||
if (
|
|
||||||
line.search(value) !== -1 &&
|
|
||||||
listExcludeErr.filter((err) => line.includes(err)).length === 0
|
|
||||||
) {
|
|
||||||
data[index] =
|
|
||||||
data[index].slice(0, data[index].search(value)) +
|
|
||||||
"|-|" +
|
|
||||||
value +
|
|
||||||
"|-|" +
|
|
||||||
data[index].slice(data[index].search(value) + value.length);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
listLine.map((u) => {
|
|
||||||
if (
|
|
||||||
listExcludeErr.filter((err) => data[u - 1].includes(err)).length === 0
|
|
||||||
) {
|
|
||||||
if (MODEL_SPECIAL.filter((i) => data[u - 1].includes(i)).length > 0) {
|
|
||||||
modelSpecialDetected.push(data[u - 1]);
|
|
||||||
} else {
|
|
||||||
issueSpecialDetected.push(data[u - 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let modelSpecial =
|
|
||||||
modelSpecialDetected.length > 0 ? modelSpecialDetected.join("\n") : "";
|
|
||||||
let issueItem =
|
|
||||||
issueSpecialDetected.length > 0 ? issueSpecialDetected.join("\n") : "";
|
|
||||||
response.status(200).send({
|
|
||||||
modelSpecial: modelSpecial,
|
|
||||||
issueItem: issueItem,
|
|
||||||
contentFile: data.join("\n"),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
// console.error(error);
|
|
||||||
response.status(203).send("FILE NOT FOUND");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Route.get("/api/getAllLogDetect", async ({ request, response }) => {
|
|
||||||
try {
|
|
||||||
let fileDetect = await LogDetectFile.all();
|
|
||||||
let listFiles = fileDetect.map((obj) => obj.file_name);
|
|
||||||
response.status(200).send(listFiles);
|
|
||||||
} catch (error) {
|
|
||||||
response.status(203).send("NO FILE");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//Key-Value
|
//Key-Value
|
||||||
|
Route.post("/api/getKeyValue", "ValuesController.getKeyValue");
|
||||||
|
|
||||||
Route.post("/api/getKeyValue", async ({ request, response }) => {
|
Route.post("/api/deleteValue", "ValuesController.destroy");
|
||||||
let data = await KeyValue.all();
|
|
||||||
response.status(200).send(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
Route.post("/api/deleteValue", async ({ request, response }) => {
|
Route.post("/api/addValue", "ValuesController.create");
|
||||||
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!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Route.post("/api/gitea-webhook", ({ request, response }) => {
|
|
||||||
console.log("New event ---> ", request.header("x-gitea-event"));
|
|
||||||
|
|
||||||
exec(Env.get("URL_FILE_SHELL"), async (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.error(`Error executing command: ${error}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await sendMessToZulip(
|
|
||||||
"private",
|
|
||||||
"joseph.le@apactech.io",
|
|
||||||
"none",
|
|
||||||
"** NEW EVENT -> " +
|
|
||||||
request.header("x-gitea-event") +
|
|
||||||
" **\n```\n" +
|
|
||||||
stdout +
|
|
||||||
"\n```"
|
|
||||||
);
|
|
||||||
console.log(res);
|
|
||||||
console.log(`Command output:\n${stdout}`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
Route.post("/api/backupProduct", async ({ request, response }) => {
|
Route.post("/api/backupProduct", async ({ request, response }) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue