Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f2abb40987 | |||
| 3697344cd0 | |||
| 4aa0ff705f | |||
| dc482e614a | |||
| 448882cfef | |||
| 7f9cb33a40 |
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "picpeak-backend",
|
||||
"version": "1.0.112",
|
||||
"version": "1.0.115",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "picpeak-backend",
|
||||
"version": "1.0.112",
|
||||
"version": "1.0.115",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.850.0",
|
||||
"@aws-sdk/lib-storage": "^3.850.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "picpeak-backend",
|
||||
"version": "1.0.112",
|
||||
"version": "1.0.115",
|
||||
"description": "Backend for PicPeak event photo sharing platform",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,7 +1,28 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const knex = require('knex');
|
||||
const knexConfig = require('../../knexfile');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
// Ensure SQLite directory exists when using file-based DB (native installs)
|
||||
try {
|
||||
const isPostgres = knexConfig && knexConfig.client === 'pg';
|
||||
if (!isPostgres && knexConfig && knexConfig.connection) {
|
||||
const filename = typeof knexConfig.connection === 'object'
|
||||
? knexConfig.connection.filename
|
||||
: (typeof knexConfig.connection === 'string' ? knexConfig.connection : null);
|
||||
if (filename && typeof filename === 'string') {
|
||||
const dir = path.dirname(filename);
|
||||
if (dir && dir !== '.') {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Non-fatal: log and continue; SQLite will fail later if still missing
|
||||
try { logger.warn('SQLite directory ensure failed', { error: e.message }); } catch (_) {}
|
||||
}
|
||||
|
||||
// Create database connection with built-in retry logic
|
||||
const db = knex(knexConfig);
|
||||
|
||||
@@ -312,4 +333,4 @@ async function logActivity(activityType, metadata = {}, eventId = null, actor =
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { db, initializeDatabase, logActivity, withRetry };
|
||||
module.exports = { db, initializeDatabase, logActivity, withRetry };
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "picpeak-frontend",
|
||||
"version": "1.0.112",
|
||||
"version": "1.0.115",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "picpeak-frontend",
|
||||
"version": "1.0.112",
|
||||
"version": "1.0.115",
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.0.0",
|
||||
"@tiptap/extension-character-count": "^2.26.1",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "picpeak-frontend",
|
||||
"private": true,
|
||||
"version": "1.0.112",
|
||||
"version": "1.0.115",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
+53
-10
@@ -61,6 +61,23 @@ UNINSTALL_MODE=false
|
||||
# Helper Functions
|
||||
################################################################################
|
||||
|
||||
# Run a command as the application user, even if sudo is not available
|
||||
run_as_user() {
|
||||
local cmd="$*"
|
||||
if [[ "$(id -u)" -ne 0 ]]; then
|
||||
# Already non-root; just run
|
||||
bash -lc "$cmd"
|
||||
return $?
|
||||
fi
|
||||
if command_exists sudo; then
|
||||
sudo -H -u "$NATIVE_APP_USER" bash -lc "$cmd"
|
||||
elif command_exists runuser; then
|
||||
runuser -u "$NATIVE_APP_USER" -- bash -lc "$cmd"
|
||||
else
|
||||
su -s /bin/bash - "$NATIVE_APP_USER" -c "$cmd"
|
||||
fi
|
||||
}
|
||||
|
||||
print_banner() {
|
||||
echo -e "${PURPLE}"
|
||||
echo "╔════════════════════════════════════════════════════════════════════════╗"
|
||||
@@ -110,11 +127,16 @@ generate_jwt_secret() {
|
||||
}
|
||||
|
||||
get_available_ram_mb() {
|
||||
if command_exists free; then
|
||||
free -m | awk '/^Mem:/{print $2}'
|
||||
else
|
||||
echo "0"
|
||||
# Prefer /proc/meminfo (always available on Linux), fallback to free(1)
|
||||
if [[ -r /proc/meminfo ]]; then
|
||||
awk '/^MemTotal:/ { printf "%d\n", $2/1024 }' /proc/meminfo
|
||||
return
|
||||
fi
|
||||
if command_exists free; then
|
||||
free -m | awk '/^Mem:/ {print $2}'
|
||||
return
|
||||
fi
|
||||
echo "0"
|
||||
}
|
||||
|
||||
get_available_disk_gb() {
|
||||
@@ -552,14 +574,26 @@ setup_native_installation() {
|
||||
# Create application directory
|
||||
log_step "Creating application directory..."
|
||||
mkdir -p "$NATIVE_APP_DIR"/{app,events/{active,archived},logs,config}
|
||||
chown -R $NATIVE_APP_USER:$NATIVE_APP_USER "$NATIVE_APP_DIR"
|
||||
|
||||
# Clone repository
|
||||
log_step "Downloading PicPeak..."
|
||||
if [[ -d "$NATIVE_APP_DIR/app/.git" ]]; then
|
||||
cd "$NATIVE_APP_DIR/app"
|
||||
git pull
|
||||
# Ensure correct remote and update even if history was rewritten
|
||||
run_as_user "git config --global --add safe.directory $NATIVE_APP_DIR/app" || true
|
||||
run_as_user "git remote set-url origin $REPO_URL" || true
|
||||
run_as_user "git fetch --all --prune" || true
|
||||
# Prefer checking out remote main and hard resetting to avoid merge prompts
|
||||
if ! run_as_user "git checkout -B main origin/main"; then
|
||||
run_as_user "git checkout main" || true
|
||||
run_as_user "git reset --hard origin/main"
|
||||
fi
|
||||
else
|
||||
git clone "$REPO_URL" "$NATIVE_APP_DIR/app"
|
||||
run_as_user "git clone $REPO_URL $NATIVE_APP_DIR/app" || {
|
||||
run_as_user "git config --global --add safe.directory $NATIVE_APP_DIR/app"
|
||||
run_as_user "git clone $REPO_URL $NATIVE_APP_DIR/app"
|
||||
}
|
||||
fi
|
||||
|
||||
# Install dependencies
|
||||
@@ -569,6 +603,9 @@ setup_native_installation() {
|
||||
cd "$NATIVE_APP_DIR/app/backend"
|
||||
npm install --production
|
||||
|
||||
# Ensure SQLite data directory exists for native installs
|
||||
mkdir -p "$NATIVE_APP_DIR/app/backend/data"
|
||||
|
||||
# Generate secrets
|
||||
local jwt_secret=$(generate_jwt_secret)
|
||||
[[ -z "$ADMIN_PASSWORD" ]] && ADMIN_PASSWORD=$(generate_password)
|
||||
@@ -626,7 +663,7 @@ EOF
|
||||
# Run database migrations
|
||||
log_step "Initializing database..."
|
||||
cd "$NATIVE_APP_DIR/app/backend"
|
||||
sudo -u $NATIVE_APP_USER npm run migrate
|
||||
run_as_user "npm run migrate"
|
||||
|
||||
# Create systemd services
|
||||
create_systemd_services
|
||||
@@ -944,14 +981,20 @@ update_native_installation() {
|
||||
|
||||
# Pull latest code
|
||||
cd "$NATIVE_APP_DIR/app"
|
||||
sudo -u $NATIVE_APP_USER git pull
|
||||
run_as_user "git config --global --add safe.directory $NATIVE_APP_DIR/app" || true
|
||||
run_as_user "git remote set-url origin $REPO_URL" || true
|
||||
run_as_user "git fetch --all --prune"
|
||||
if ! run_as_user "git checkout -B main origin/main"; then
|
||||
run_as_user "git checkout main" || true
|
||||
run_as_user "git reset --hard origin/main"
|
||||
fi
|
||||
|
||||
# Update backend dependencies
|
||||
cd "$NATIVE_APP_DIR/app/backend"
|
||||
sudo -u $NATIVE_APP_USER npm install --production
|
||||
run_as_user "npm install --production"
|
||||
|
||||
# Run migrations
|
||||
sudo -u $NATIVE_APP_USER npm run migrate
|
||||
run_as_user "npm run migrate"
|
||||
|
||||
# Restart services
|
||||
systemctl start picpeak-backend picpeak-workers
|
||||
|
||||
Reference in New Issue
Block a user