susee:log
This commit is contained in:
parent
e3571d7d42
commit
e6be9b19f7
@ -2,6 +2,8 @@ const { sequelize,Test,ObligationMaster,ObligationBankStatement,EmiTracking,Repa
|
||||
const { logMsg } = require('../services/logger.js');
|
||||
var swaggerSpecToPdf = require("swagger-spec-to-pdf");
|
||||
const { Console } = require('winston/lib/winston/transports');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
|
||||
// get all Obligation master data
|
||||
@ -316,5 +318,119 @@ exports.GetRepaymentTrackRecord = async (req, res) =>
|
||||
|
||||
|
||||
|
||||
exports.readLogFileName = async (req , res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
folderName = req;
|
||||
const logFilePath = 'storage/log';
|
||||
|
||||
const fileNames = fs.readdirSync(logFilePath);
|
||||
// Remove the first element (0th index)
|
||||
const [, ...data] = fileNames;
|
||||
return data;
|
||||
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
});
|
||||
} //end of try catch
|
||||
};
|
||||
|
||||
|
||||
exports.readLogFile = async (req , res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
folderName = req.body.folder;
|
||||
fileName = req.body.file;
|
||||
const logFilePath = 'storage/log/'+fileName;
|
||||
|
||||
fs.readFile(logFilePath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.status(500).send({'status':404,'message': err.message || "Error reading log file." ,'data': "No data"});
|
||||
}
|
||||
res.send({'status':200 , message:"Success." ,'data': data});
|
||||
});
|
||||
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
});
|
||||
} //end of try catch
|
||||
};
|
||||
|
||||
|
||||
exports.viewLandingPage = async (req , res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
moduleName = [ { "module":"OBLIGATION","folder":"smc_cet_obligation_backend"} ];
|
||||
img = []
|
||||
for(const [index,val] of moduleName.entries())
|
||||
{
|
||||
fileName = await this.readLogFileName(val.folder);
|
||||
for (let i = 0; i < fileName.length; i++)
|
||||
{
|
||||
filePath = 'storage/log/'+fileName[i];
|
||||
const logData = fs.readFileSync(filePath);
|
||||
// Convert the file content to Base64
|
||||
const base64Data = logData.toString('base64');
|
||||
// Create Base64 URL from Base64 data
|
||||
const base64Url = `data:application/octet-stream;base64,${encodeURIComponent(base64Data)}`;
|
||||
img.push(base64Url)
|
||||
}
|
||||
moduleName[index] = await Object.assign(val,{'file':fileName , 'img':img});
|
||||
};
|
||||
res.render( 'module' , { 'data' : moduleName } ,function (err, html ) {
|
||||
res.send(html)
|
||||
})
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
});
|
||||
} //end of try catch
|
||||
};
|
||||
|
||||
|
||||
exports.deleteLogFile = async (req , res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
folderName = req.body.folder;
|
||||
fileName = req.body.file;
|
||||
|
||||
// folderName = 'smc_cet_creditpd_backend';
|
||||
// fileName = 'msg.log.2023-07-10';
|
||||
const logFilePath = 'storage/log/'+fileName;
|
||||
fs.unlink(logFilePath, (err) => {
|
||||
if (err) {
|
||||
console.error(`Error deleting file: ${err}`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('File deleted successfully.');
|
||||
res.send({'status':200 , message:"Success." ,'data': 'No data'});
|
||||
});
|
||||
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
});
|
||||
} //end of try catch
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -669,6 +669,15 @@ router.post("/UpdateRepaymentTrackRecord",Mycontroller.UpdateRepaymentTrackRecor
|
||||
* description: success
|
||||
*/
|
||||
router.get("/getRepaymentTrackRecord",Mycontroller.GetRepaymentTrackRecord)
|
||||
|
||||
|
||||
router.get("/getfilename", Mycontroller.readLogFileName);
|
||||
|
||||
router.post("/readlogs", Mycontroller.readLogFile);
|
||||
|
||||
router.get("/view", Mycontroller.viewLandingPage);
|
||||
|
||||
router.post("/deletelog", Mycontroller.deleteLogFile);
|
||||
|
||||
// routes started here
|
||||
app.use('/api', router);
|
||||
|
||||
337
app/views/module.ejs
Normal file
337
app/views/module.ejs
Normal file
@ -0,0 +1,337 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<style>
|
||||
body {
|
||||
background: #f3f3f3;
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
/* Dashboard Cards */
|
||||
.dashboard-cards {
|
||||
position: relative;
|
||||
padding-bottom: 50px;
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
.dashboard-cards .card {
|
||||
background: #ffffff;
|
||||
display: inline-block;
|
||||
-webkit-perspective: 1000;
|
||||
perspective: 1000;
|
||||
z-index: 20;
|
||||
padding: 0 !important;
|
||||
margin: 5px 5px 10px 5px;
|
||||
position: relative;
|
||||
text-align: left;
|
||||
-webkit-transition: all 0.3s 0s ease-in;
|
||||
transition: all 0.3s 0s ease-in;
|
||||
z-index: 1;
|
||||
/* width: calc(33.33333333% - 10px); */
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.dashboard-cards .card:hover {
|
||||
box-shadow: 0 15px 10px -10px rgba(31, 31, 31, 0.5);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .card-title {
|
||||
background: #ffffff;
|
||||
padding: 20px 15px;
|
||||
position: relative;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .card-title h2 {
|
||||
font-size: 24px;
|
||||
letter-spacing: -0.05em;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .card-title h2 small {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
margin-top: 8px;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .card-description {
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
border-top: 1px solid #ddd;
|
||||
padding: 10px 15px 0 15px;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .card-actions {
|
||||
box-shadow: 0 2px 0px 0 rgba(0, 0, 0, 0.075);
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .card-flap {
|
||||
background: #d9d9d9;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
-webkit-transform-origin: top;
|
||||
transform-origin: top;
|
||||
/* -webkit-transform: rotateX(-90deg);
|
||||
transform: rotateX(-90deg); */
|
||||
}
|
||||
|
||||
.dashboard-cards .card .flap1 {
|
||||
-webkit-transition: all 0.3s 0.3s ease-out;
|
||||
transition: all 0.3s 0.3s ease-out;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .flap2 {
|
||||
-webkit-transition: all 0.3s 0s ease-out;
|
||||
transition: all 0.3s 0s ease-out;
|
||||
z-index: -2;
|
||||
}
|
||||
|
||||
.dashboard-cards.showing .card {
|
||||
cursor: pointer;
|
||||
opacity: 0.6;
|
||||
-webkit-transform: scale(0.88);
|
||||
transform: scale(0.88);
|
||||
}
|
||||
|
||||
.dashboard-cards .no-touch .dashboard-cards.showing .card:hover {
|
||||
opacity: 0.94;
|
||||
-webkit-transform: scale(0.92);
|
||||
transform: scale(0.92);
|
||||
}
|
||||
|
||||
.dashboard-cards .card.d-card-show {
|
||||
opacity: 1 !important;
|
||||
-webkit-transform: scale(1) !important;
|
||||
transform: scale(1) !important;
|
||||
}
|
||||
|
||||
.dashboard-cards .card.d-card-show .card-flap {
|
||||
background: #ffffff;
|
||||
-webkit-transform: rotateX(0deg);
|
||||
transform: rotateX(0deg);
|
||||
}
|
||||
|
||||
.dashboard-cards .card.d-card-show .flap1 {
|
||||
-webkit-transition: all 0.3s 0s ease-out;
|
||||
transition: all 0.3s 0s ease-out;
|
||||
}
|
||||
|
||||
.dashboard-cards .card.d-card-show .flap2 {
|
||||
-webkit-transition: all 0.3s 0.2s ease-out;
|
||||
transition: all 0.3s 0.2s ease-out;
|
||||
}
|
||||
|
||||
.dashboard-cards .card .task-count {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
position: absolute;
|
||||
top: 14px;
|
||||
right: 10px;
|
||||
background: #ecf0f1;
|
||||
text-align: center;
|
||||
line-height: 40px;
|
||||
border-radius: 100%;
|
||||
color: #333333;
|
||||
font-weight: 600;
|
||||
transition: all .2s ease;
|
||||
}
|
||||
|
||||
/* Task List */
|
||||
.dashboard-cards .task-list {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.dashboard-cards .task-list li {
|
||||
padding: 10px 0;
|
||||
padding-left: 10px;
|
||||
margin: 3px 0;
|
||||
list-style-type: none;
|
||||
border-bottom: 1px solid #e9ebed;
|
||||
border-left: 3px solid #f36525;
|
||||
transition: all .2s ease;
|
||||
}
|
||||
|
||||
.dashboard-cards .task-list li:hover {
|
||||
background: #ecf0f1;
|
||||
transition: all .2s ease;
|
||||
}
|
||||
|
||||
.dashboard-cards .task-list li span {
|
||||
float: right;
|
||||
color: #f36525;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.dashboard-cards.showing .card.d-card-show .task-count {
|
||||
color: #ffffff;
|
||||
background: #f36525;
|
||||
transition: all .2s ease;
|
||||
}
|
||||
|
||||
.dashboard-cards .card-actions .btn {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.dashboard-cards .card-actions .btn:hover {
|
||||
color: #f36525;
|
||||
}
|
||||
|
||||
.fileName{
|
||||
display: inline-block;
|
||||
}
|
||||
.delete,.download{
|
||||
float: right;
|
||||
margin-top: 5px;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<div class='row dashboard-cards'>
|
||||
<% for (let i = 0; i < data.length; i++) { %>
|
||||
<div class='card col-md-2'></div>
|
||||
<div class='card col-md-8'>
|
||||
<div class='card-title'>
|
||||
<h2>
|
||||
LOGS
|
||||
<!-- <small>You have 14 pending tasks</small> -->
|
||||
</h2>
|
||||
<div class='task-count'>
|
||||
<%= data[i].file.length %>
|
||||
</div>
|
||||
</div>
|
||||
<div class='card-flap flap1'>
|
||||
<% for (let j = 0; j < data[i].file.length; j++) { %>
|
||||
<div class='card-description'>
|
||||
<ul class='task-list'>
|
||||
<li id="<%= data[i].file[j]+'|'+data[i].folder %>" class="fileName">
|
||||
<%= data[i].file[j] %>
|
||||
</li>
|
||||
<button type="button" id="<%= data[i].file[j]+'|'+data[i].folder %>" class="btn btn-danger delete">Delete</button>
|
||||
<a onclick="downloadImage('<%= data[i].img[j] %>')">Download link</a>
|
||||
</ul>
|
||||
</div>
|
||||
<% } %>
|
||||
<div class='card-flap flap2'>
|
||||
<div class='card-actions'>
|
||||
<a class='btn' href='#'>Close</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='card col-md-2'></div>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<!-- Modal btn -->
|
||||
<button type="button" style="display: none;" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Large Modal</button>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="myModal" role="dialog">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title"></h4>
|
||||
</div>
|
||||
<div class="modal-body" style="white-space: pre-wrap;">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var zindex = 10;
|
||||
|
||||
$("div.card").click(function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var isShowing = false;
|
||||
|
||||
if ($(this).hasClass("d-card-show")) {
|
||||
isShowing = true;
|
||||
}
|
||||
|
||||
if ($("div.dashboard-cards").hasClass("showing")) {
|
||||
// a card is already in view
|
||||
$("div.card.d-card-show").removeClass("d-card-show");
|
||||
|
||||
if (isShowing) {
|
||||
// this card was showing - reset the grid
|
||||
$("div.dashboard-cards").removeClass("showing");
|
||||
} else {
|
||||
// this card isn't showing - get in with it
|
||||
$(this).css({ zIndex: zindex }).addClass("d-card-show");
|
||||
}
|
||||
|
||||
zindex++;
|
||||
} else {
|
||||
// no dashboard-cards in view
|
||||
$("div.dashboard-cards").addClass("showing");
|
||||
$(this).css({ zIndex: zindex }).addClass("d-card-show");
|
||||
|
||||
zindex++;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".fileName").click(function(){
|
||||
data = $(this).attr('id').split("|");
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "/api/readlogs",
|
||||
data: {'file' : data[0] , 'folder' : data[1]},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$('.modal-title').html(data[0]);
|
||||
$('.modal-body').html(response.data);
|
||||
$('#myModal').modal('show');
|
||||
},
|
||||
error: function(jqXHR, textStatus, err) {
|
||||
alert('text status '+textStatus+', err '+err)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".delete").click(function(){
|
||||
data = $(this).attr('id').split("|");
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "/api/deletelog",
|
||||
data: {'file' : data[0] , 'folder' : data[1]},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
location.reload();
|
||||
},
|
||||
error: function(jqXHR, textStatus, err) {
|
||||
alert('text status '+textStatus+', err '+err)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function downloadImage(data)
|
||||
{
|
||||
const base64Image = data; // Replace this with your actual Base64 image data
|
||||
const downloadLink = document.createElement('a');
|
||||
downloadLink.href = base64Image;
|
||||
downloadLink.download = 'log.txt'; // Replace with the desired file name and extension
|
||||
downloadLink.click();
|
||||
}
|
||||
</script>
|
||||
|
||||
</html>
|
||||
5775
package-lock.json
generated
5775
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -14,11 +14,14 @@
|
||||
"cors": "^2.8.5",
|
||||
"date-fns": "^2.28.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"ejs": "^3.1.9",
|
||||
"excel-date-to-js": "^1.1.4",
|
||||
"express": "^4.17.1",
|
||||
"fs": "0.0.1-security",
|
||||
"log4js": "^6.3.0",
|
||||
"moment": "^2.29.4",
|
||||
"mssql": "^7.2.0",
|
||||
"path": "^0.12.7",
|
||||
"request": "^2.88.2",
|
||||
"sequelize": "^6.6.5",
|
||||
"swagger-jsdoc": "^6.1.0",
|
||||
|
||||
@ -2,7 +2,8 @@ require('dotenv').config();
|
||||
const express = require('express')
|
||||
var moment = require('moment')
|
||||
var swaggerSpecToPdf = require("swagger-spec-to-pdf")
|
||||
const app = express()
|
||||
const app = express();
|
||||
const path = require('path');
|
||||
//it is used to clear cache
|
||||
app.use(function(req, res, next) {
|
||||
res.set("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0")
|
||||
@ -12,6 +13,9 @@ app.use(function(req, res, next) {
|
||||
})
|
||||
const {logMsg} = require('./app/services/logger.js');
|
||||
|
||||
app.set('views', path.join(__dirname, 'app\\views'));
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
const swaggerJsdoc = require('swagger-jsdoc');
|
||||
const swaggerUi = require('swagger-ui-express');
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user