vite_deleteelectron

This commit is contained in:
2026-08-09 21:02:10 +03:00
parent 5d2fc5773c
commit 4ba9dd8012
99 changed files with 7080 additions and 48649 deletions
+7 -2
View File
@@ -4,9 +4,14 @@
const mysql = require('mysql2/promise'); // ✅ Используем promise-версию
const path = require('path');
const fs = require('fs-extra');
const fs = require('fs').promises;
const { logger } = require('./logger');
async function readJson(filePath) {
const data = await fs.readFile(filePath, 'utf8');
return JSON.parse(data);
}
// Загружаем переменные окружения
require('dotenv').config({ path: path.join(__dirname, '../../config.env') });
@@ -42,7 +47,7 @@ let isReconnecting = false;
async function checkTestMode() {
try {
const configPath = path.join(__dirname, '../../config.json');
const config = await fs.readJson(configPath);
const config = await readJson(configPath);
return config.testMode === true;
} catch (err) {
logger.warn('⚠️ Не удалось прочитать config.json для проверки testMode', { error: err.message });
+7 -2
View File
@@ -5,10 +5,15 @@
const express = require('express');
const router = express.Router();
const path = require('path');
const fs = require('fs-extra');
const fs = require('fs').promises;
const { query, queryOne, isDBConnected, getDBStatus } = require('../config/db');
const { logger } = require('../config/logger_cards');
async function readJson(filePath) {
const data = await fs.readFile(filePath, 'utf8');
return JSON.parse(data);
}
// ============================================
// 📊 Вспомогательные функции
// ============================================
@@ -19,7 +24,7 @@ const { logger } = require('../config/logger_cards');
async function getMockEmployee(searchParam, type = 'card') {
try {
const configPath = path.join(__dirname, '../../config.json');
const config = await fs.readJson(configPath);
const config = await readJson(configPath);
if (!config.testMode || !config.mockData) {
return null;
+26 -12
View File
@@ -1,13 +1,27 @@
const express = require('express');
const cors = require('cors');
const path = require('path');
const fs = require('fs-extra');
const fs = require('fs').promises;
const { connectDB } = require('./config/db');
const { logger } = require('./config/logger');
const handbookRoutes = require('./routes/handbook');
const employeeRoutes = require('./routes/employee');
require('dotenv').config({ path: path.join(__dirname, '../config.env') });
async function readJson(filePath) {
const data = await fs.readFile(filePath, 'utf8');
return JSON.parse(data);
}
async function pathExists(filePath) {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}
async function connectToNetworkShare(config) {
if (config.networkCredentials && config.networkCredentials.username) {
try {
@@ -67,7 +81,7 @@ app.get('/api/test', (req, res) => {
app.get('/api/system-status', async (req, res) => {
try {
const configPath = path.join(__dirname, '../config.json');
const config = await fs.readJson(configPath);
const config = await readJson(configPath);
const { getDBStatus } = require('./config/db');
const dbStatus = await getDBStatus();
@@ -76,7 +90,7 @@ app.get('/api/system-status', async (req, res) => {
let networkContents = [];
try {
networkAccess = await fs.pathExists(config.payslipsPath);
networkAccess = await pathExists(config.payslipsPath);
if (networkAccess) {
const stats = await fs.stat(config.payslipsPath);
networkAccess = stats.isDirectory();
@@ -138,7 +152,7 @@ app.get('/api/system-status', async (req, res) => {
app.get('/api/test-network', async (req, res) => {
try {
const configPath = path.join(__dirname, '../config.json');
const config = await fs.readJson(configPath);
const config = await readJson(configPath);
const payslipBasePath = config.payslipsPath;
logger.info(`Testing network connection to: ${payslipBasePath}`);
@@ -156,7 +170,7 @@ app.get('/api/test-network', async (req, res) => {
};
try {
testResults.basePathExists = await fs.pathExists(payslipBasePath);
testResults.basePathExists = await pathExists(payslipBasePath);
logger.info(`Base path exists: ${testResults.basePathExists}`);
if (testResults.basePathExists) {
@@ -189,7 +203,7 @@ app.get('/api/payslip/:period/:fileName', async (req, res) => {
try {
const { period, fileName } = req.params;
const configPath = path.join(__dirname, '../config.json');
const config = await fs.readJson(configPath);
const config = await readJson(configPath);
const payslipBasePath = config.payslipsPath;
logger.info(`Payslip request - Period: ${period}, File: ${fileName}`);
@@ -209,7 +223,7 @@ app.get('/api/payslip/:period/:fileName', async (req, res) => {
logger.info(`Final payslip path: ${finalPayslipPath}`);
try {
const basePathExists = await fs.pathExists(payslipBasePath);
const basePathExists = await pathExists(payslipBasePath);
logger.info(`Base path exists: ${basePathExists}`);
if (basePathExists) {
@@ -224,7 +238,7 @@ app.get('/api/payslip/:period/:fileName', async (req, res) => {
logger.info(`Base path contents: ${JSON.stringify(basePathContents)}`);
const periodPath = path.join(payslipBasePath, period);
const periodPathExists = await fs.pathExists(periodPath);
const periodPathExists = await pathExists(periodPath);
logger.info(`Period path exists: ${periodPathExists} (${periodPath})`);
if (periodPathExists) {
@@ -239,7 +253,7 @@ app.get('/api/payslip/:period/:fileName', async (req, res) => {
});
}
if (await fs.pathExists(finalPayslipPath)) {
if (await pathExists(finalPayslipPath)) {
logger.info(`Payslip found, sending file: ${finalPayslipPath}`);
res.sendFile(finalPayslipPath);
} else {
@@ -267,7 +281,7 @@ app.get('/api/payslip/:fileName', async (req, res) => {
try {
const { fileName } = req.params;
const configPath = path.join(__dirname, '../config.json');
const config = await fs.readJson(configPath);
const config = await readJson(configPath);
const payslipBasePath = config.payslipsPath;
let finalPayslipPath;
@@ -280,7 +294,7 @@ app.get('/api/payslip/:fileName', async (req, res) => {
logger.info(`Attempting to find payslip at resolved path: ${finalPayslipPath}`);
if (await fs.pathExists(finalPayslipPath)) {
if (await pathExists(finalPayslipPath)) {
res.sendFile(finalPayslipPath);
} else {
logger.warn(`Payslip not found: ${finalPayslipPath}`);
@@ -310,7 +324,7 @@ app.get('/api/db-status', async (req, res) => {
async function startServer() {
try {
const configPath = path.join(__dirname, '../config.json');
const config = await fs.readJson(configPath);
const config = await readJson(configPath);
const { host, port } = config.server;
await connectDB();