Compare commits
No commits in common. "v0.4.2.9" and "main" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -40,7 +40,6 @@ Desktop.ini
|
||||
|
||||
# Project Specific - Server
|
||||
server/.env
|
||||
server/.env.local
|
||||
server/.env.backup*
|
||||
server/*.tmp
|
||||
server/backups/
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "smartims",
|
||||
"private": true,
|
||||
"version": "0.4.2.8",
|
||||
"version": "0.4.2.7",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
const mysql = require('mysql2');
|
||||
const path = require('path');
|
||||
// Prioritize machine-specific local config (.env.local)
|
||||
require('dotenv').config({ path: path.join(__dirname, '.env.local') });
|
||||
require('dotenv').config(); // Fallback to standard .env
|
||||
require('dotenv').config();
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const path = require('path');
|
||||
// Prioritize machine-specific local config (.env.local)
|
||||
require('dotenv').config({ path: path.join(__dirname, '.env.local') });
|
||||
require('dotenv').config(); // Fallback to standard .env
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
const authRoutes = require('./routes/auth');
|
||||
@ -14,6 +11,7 @@ const { isAuthenticated } = require('./middleware/authMiddleware');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3005; // Changed to 3005 to avoid conflict with Synology services (3001 issue)
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Ensure uploads directory exists
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "0.4.2.8",
|
||||
"version": "0.4.2.7",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -40,18 +40,11 @@ const ALLOWED_SETTING_KEYS = [
|
||||
];
|
||||
|
||||
// --- .env File Utilities ---
|
||||
// Use .env.local for local machine settings (Ignored by Git)
|
||||
const localEnvPath = path.join(__dirname, '../.env.local');
|
||||
const defaultEnvPath = path.join(__dirname, '../.env');
|
||||
const envPath = path.join(__dirname, '../.env');
|
||||
|
||||
const readEnv = () => {
|
||||
// 1. Check for .env.local first
|
||||
let path = fs.existsSync(localEnvPath) ? localEnvPath : defaultEnvPath;
|
||||
|
||||
// 2. Migration: If ONLY .env exists, we'll read from it and later save will create .env.local
|
||||
if (!fs.existsSync(path)) return {};
|
||||
|
||||
const content = fs.readFileSync(path, 'utf8');
|
||||
if (!fs.existsSync(envPath)) return {};
|
||||
const content = fs.readFileSync(envPath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
const env = {};
|
||||
lines.forEach(line => {
|
||||
@ -64,16 +57,7 @@ const readEnv = () => {
|
||||
};
|
||||
|
||||
const writeEnv = (updates) => {
|
||||
// If .env.local doesn't exist, create it by copying .env (if exists) or from empty
|
||||
if (!fs.existsSync(localEnvPath)) {
|
||||
if (fs.existsSync(defaultEnvPath)) {
|
||||
fs.copyFileSync(defaultEnvPath, localEnvPath);
|
||||
} else {
|
||||
fs.writeFileSync(localEnvPath, '', 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
let content = fs.readFileSync(localEnvPath, 'utf8');
|
||||
let content = fs.readFileSync(envPath, 'utf8');
|
||||
Object.entries(updates).forEach(([key, value]) => {
|
||||
const regex = new RegExp(`^${key}=.*`, 'm');
|
||||
if (regex.test(content)) {
|
||||
@ -82,7 +66,7 @@ const writeEnv = (updates) => {
|
||||
content += `\n${key}=${value}`;
|
||||
}
|
||||
});
|
||||
fs.writeFileSync(localEnvPath, content, 'utf8');
|
||||
fs.writeFileSync(envPath, content, 'utf8');
|
||||
};
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
@ -519,7 +503,7 @@ router.get('/version/remote', isAuthenticated, hasRole('admin'), async (req, res
|
||||
const rootPkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
||||
currentVersion = rootPkg.version;
|
||||
} catch (err) {
|
||||
currentVersion = '0.4.2.8';
|
||||
currentVersion = '0.4.2.7';
|
||||
}
|
||||
}
|
||||
|
||||
@ -668,10 +652,6 @@ if not exist "%BACKUP_PATH%" (
|
||||
)
|
||||
|
||||
echo [Update] Backing up Config...
|
||||
if exist "server\\.env.local" (
|
||||
copy /Y "server\\.env.local" "%BACKUP_PATH%\\.env.local.backup.${timestamp}"
|
||||
copy /Y "server\\.env.local" "server\\.env.local.tmp"
|
||||
)
|
||||
if exist "server\\.env" (
|
||||
copy /Y "server\\.env" "%BACKUP_PATH%\\.env.backup.${timestamp}"
|
||||
copy /Y "server\\.env" "server\\.env.tmp"
|
||||
@ -682,13 +662,6 @@ git fetch "${remoteUrl}" --tags --force --prune
|
||||
git checkout -f ${targetTag}
|
||||
|
||||
echo [Update] Restoring Config...
|
||||
if exist "server\\.env.local.tmp" (
|
||||
copy /Y "server\\.env.local.tmp" "server\\.env.local"
|
||||
del "server\\.env.local.tmp"
|
||||
) else if exist "%BACKUP_PATH%\\.env.local.backup.${timestamp}" (
|
||||
copy /Y "%BACKUP_PATH%\\.env.local.backup.${timestamp}" "server\\.env.local"
|
||||
)
|
||||
|
||||
if exist "server\\.env.tmp" (
|
||||
copy /Y "server\\.env.tmp" "server\\.env"
|
||||
del "server\\.env.tmp"
|
||||
@ -733,17 +706,12 @@ else
|
||||
fi
|
||||
|
||||
echo "[Update] Backing up Config..."
|
||||
# Backup .env.local (Priority)
|
||||
if [ -f "server/.env.local" ]; then
|
||||
echo "[Info] Backing up 'server/.env.local'."
|
||||
cp "server/.env.local" "$BACKUP_DIR/.env.local.backup.${timestamp}"
|
||||
cp "server/.env.local" "server/.env.local.tmp"
|
||||
fi
|
||||
# Backup .env (Fallback)
|
||||
if [ -f "server/.env" ]; then
|
||||
echo "[Info] Backing up 'server/.env'."
|
||||
echo "[Info] Backing up 'server/.env' to '$BACKUP_DIR/.env.backup.${timestamp}' and 'server/.env.tmp'."
|
||||
cp "server/.env" "$BACKUP_DIR/.env.backup.${timestamp}"
|
||||
cp "server/.env" "server/.env.tmp"
|
||||
else
|
||||
echo "[Warning] 'server/.env' not found. Skipping config backup."
|
||||
fi
|
||||
|
||||
echo "[Update] Syncing Source Code..."
|
||||
@ -762,13 +730,6 @@ fi
|
||||
echo "[Info] Git checkout to ${targetTag} successful."
|
||||
|
||||
echo "[Update] Restoring Config..."
|
||||
if [ -f "server/.env.local.tmp" ]; then
|
||||
cp "server/.env.local.tmp" "server/.env.local"
|
||||
rm "server/.env.local.tmp"
|
||||
elif [ -f "$BACKUP_DIR/.env.local.backup.${timestamp}" ]; then
|
||||
cp "$BACKUP_DIR/.env.local.backup.${timestamp}" "server/.env.local"
|
||||
fi
|
||||
|
||||
if [ -f "server/.env.tmp" ]; then
|
||||
cp "server/.env.tmp" "server/.env"
|
||||
rm "server/.env.tmp"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user