From ed5fa15814ccce2c3c6738f8de80fa7b90a8e96d Mon Sep 17 00:00:00 2001 From: COMTREE Date: Mon, 25 Aug 2025 13:13:19 +0900 Subject: [PATCH] feat: enhance database environment handling and cleanup project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add environment-specific database selection (SQLite for local, MariaDB for NAS) - Remove edit button from admin detail view modal for cleaner UX - Clean up project files: remove redundant docs and test files - Update deployment script with improved SSH handling - Maintain backward compatibility while supporting both database types πŸ€– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .claude/settings.local.json | 5 +- CLAUDE.md | 164 ++++++------------------------------ README-MariaDB.md | 139 ------------------------------ README_AUTO_START.md | 101 ---------------------- admin/script.js | 1 - cookies.txt | 5 -- deploy-to-nas.sh | 27 ++++-- mariadb-setup.md | 130 ---------------------------- server.js | 18 +++- 9 files changed, 66 insertions(+), 524 deletions(-) delete mode 100644 README-MariaDB.md delete mode 100644 README_AUTO_START.md delete mode 100644 cookies.txt delete mode 100644 mariadb-setup.md diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 92f1163..c12c301 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -54,7 +54,10 @@ "mcp__context7__get-library-docs", "Bash(npm run init-mariadb:*)", "Bash(npm test)", - "Bash(npm run build:*)" + "Bash(npm run build:*)", + "Bash(npm run stop:*)", + "Bash(PORT=3007 node server.js)", + "Bash(HOST=119.64.1.86 PORT=3007 node server.js)" ], "deny": [], "ask": [], diff --git a/CLAUDE.md b/CLAUDE.md index 5c278c7..48898df 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,146 +1,34 @@ -# CLAUDE.md +--- +allowed-tools: [Read, Grep, Glob, Bash, Edit, MultiEdit] +description: "Clean up code, remove dead code, and optimize project structure" +--- -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. +# /sc:cleanup - Code and Project Cleanup -## Project Overview - -This is a web-based file management system (μžλ£Œμ‹€) with full CRUD functionality. It's a hybrid application built with vanilla HTML, CSS, and JavaScript that supports both Supabase cloud database and localStorage for data persistence, providing seamless offline/online capabilities. - -### Key Features -- Create, Read, Update, Delete operations for file records -- File upload with multiple file support (local + cloud storage) -- User authentication and authorization -- Search and filtering by title, description, tags, and category -- Categorization system (λ¬Έμ„œ, 이미지, λ™μ˜μƒ, ν”„λ ˆμ  ν…Œμ΄μ…˜, 기타) -- Tag-based organization -- Responsive design for mobile and desktop -- Modal-based editing interface -- Cloud database with real-time synchronization -- Offline support with localStorage fallback -- Cross-device data synchronization - -## File Structure +## Purpose +Systematically clean up code, remove dead code, optimize imports, and improve project structure. +## Usage ``` -μžλ£Œμ‹€/ -β”œβ”€β”€ index.html # Main HTML file with UI structure and auth components -β”œβ”€β”€ styles.css # Complete styling with responsive design and auth styles -β”œβ”€β”€ script.js # Core JavaScript with FileManager class and Supabase integration -β”œβ”€β”€ supabase-config.js # Supabase configuration and helper functions -β”œβ”€β”€ supabase-schema.sql # Database schema for Supabase setup -β”œβ”€β”€ setup-guide.md # Comprehensive Supabase setup guide -└── CLAUDE.md # This documentation file +/sc:cleanup [target] [--type code|imports|files|all] [--safe|--aggressive] [--dry-run] ``` -## Architecture +## Arguments +- `target` - Files, directories, or entire project to clean +- `--type` - Cleanup type (code, imports, files, all) +- `--safe` - Conservative cleanup (default) +- `--aggressive` - More thorough cleanup with higher risk +- `--dry-run` - Preview changes without applying them -### Core Components +## Execution +1. Analyze target for cleanup opportunities +2. Identify dead code, unused imports, and redundant files +3. Create cleanup plan with risk assessment +4. Execute cleanup operations with appropriate safety measures +5. Validate changes and report cleanup results -1. **FileManager Class** (`script.js`) - - Main application controller with hybrid storage support - - Handles all CRUD operations (Supabase + localStorage fallback) - - Manages user authentication and session state - - Contains event handling and UI updates - - Real-time synchronization capabilities - -2. **Supabase Integration** (`supabase-config.js`) - - Database configuration and connection management - - Authentication helper functions (signup, login, logout) - - CRUD helper functions for files and attachments - - Storage helper functions for file uploads/downloads - - Real-time subscription management - -3. **Data Model** - ```javascript - // Files table - { - id: UUID, // Primary key - title: string, // File title (required) - description: string, // Optional description - category: string, // Required category - tags: string[], // Array of tags - user_id: UUID, // Foreign key to auth.users - created_at: timestamp, - updated_at: timestamp - } - - // File attachments table - { - id: UUID, - file_id: UUID, // Foreign key to files - original_name: string, - storage_path: string, // Supabase Storage path - file_size: integer, - mime_type: string, - created_at: timestamp - } - ``` - -4. **UI Components** - - Authentication section (login/signup/logout) - - Sync status indicator - - Search and filter section - - Add new file form with cloud upload - - File list display with sorting - - Edit modal for updates - - Responsive card-based layout - - Offline mode notifications - -### Development Commands - -This is a hybrid web application supporting both online and offline modes: - -1. **Local Development** - ```bash - # Open index.html in a web browser - # OR use a simple HTTP server: - python -m http.server 8000 - # OR - npx serve . - ``` - -2. **Supabase Setup (Required for online features)** - ```bash - # 1. Follow setup-guide.md for complete setup - # 2. Create Supabase project and database - # 3. Run supabase-schema.sql in SQL Editor - # 4. Create Storage bucket named 'files' - # 5. Update supabase-config.js with your credentials - ``` - -3. **File Access** - - Open `index.html` directly in browser - - Works offline with localStorage (limited functionality) - - Full features available with Supabase configuration - -### Technical Implementation - -- **Database**: Supabase PostgreSQL with Row Level Security (RLS) -- **Storage**: Supabase Storage for files + localStorage fallback -- **Authentication**: Supabase Auth with email/password -- **Real-time**: Supabase Realtime for live synchronization -- **File Handling**: FileReader API + Supabase Storage API -- **UI Updates**: Vanilla JavaScript DOM manipulation -- **Styling**: CSS Grid and Flexbox for responsive layouts -- **Animations**: CSS transitions and keyframe animations -- **Offline Support**: Automatic fallback to localStorage when offline - -### Data Management - -- **Online Mode**: Files stored in Supabase PostgreSQL + Storage -- **Offline Mode**: Files stored as base64 strings in localStorage -- **Hybrid Sync**: Automatic synchronization when connection restored -- User-specific data isolation with RLS policies -- Search works across title, description, and tags -- Sorting available by date, title, or category -- Categories are predefined but can be extended -- Real-time updates across devices for same user - -### Browser Compatibility - -- Modern browsers with ES6+ support -- localStorage API support required -- FileReader API for file uploads -- Fetch API for Supabase communication -- WebSocket support for real-time features -- External dependency: Supabase JavaScript client library \ No newline at end of file +## Claude Code Integration +- Uses Glob for systematic file discovery +- Leverages Grep for dead code detection +- Applies MultiEdit for batch cleanup operations +- Maintains backup and rollback capabilities \ No newline at end of file diff --git a/README-MariaDB.md b/README-MariaDB.md deleted file mode 100644 index 6a43a60..0000000 --- a/README-MariaDB.md +++ /dev/null @@ -1,139 +0,0 @@ -# Jaryo File Manager - MariaDB 배포 κ°€μ΄λ“œ - -## κ°œμš” -Jaryo File Managerλ₯Ό μ‹œλ†€λ‘œμ§€ NAS의 MariaDB와 ν•¨κ»˜ λ°°ν¬ν•˜λŠ” κ°€μ΄λ“œμž…λ‹ˆλ‹€. - -## μ‹œμŠ€ν…œ μš”κ΅¬μ‚¬ν•­ - -### NAS ν™˜κ²½ -- μ‹œλ†€λ‘œμ§€ DSM 7.0+ -- Node.js 18+ (DSM νŒ¨ν‚€μ§€ μ„Όν„°μ—μ„œ μ„€μΉ˜) -- MariaDB 10+ (DSM νŒ¨ν‚€μ§€ μ„Όν„°μ—μ„œ μ„€μΉ˜) -- Git Server (DSM νŒ¨ν‚€μ§€ μ„Όν„°μ—μ„œ μ„€μΉ˜) - -### 개발 ν™˜κ²½ -- Node.js 18+ -- MariaDB/MySQL 5.7+ -- Git - -## NAS 배포 단계 - -### 1. λΉ λ₯Έ 배포 (ꢌμž₯) -```bash -# μžλ™ 배포 슀크립트 μ‹€ν–‰ -./deploy-to-nas.sh [NAS-IP] jaryo [PASSWORD] - -# μ˜ˆμ‹œ: -./deploy-to-nas.sh 192.168.1.100 jaryo mypassword -``` - -### 2. μˆ˜λ™ 배포 - -#### 2.1 MariaDB μ„€μ • -NAS SSH 접속 ν›„: -```sql -mysql -u root -p - -CREATE DATABASE IF NOT EXISTS jaryo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -CREATE USER 'jaryo_user'@'localhost' IDENTIFIED BY 'JaryoPass2024!@#'; -GRANT ALL PRIVILEGES ON jaryo.* TO 'jaryo_user'@'localhost'; -FLUSH PRIVILEGES; -EXIT; -``` - -#### 2.2 μŠ€ν‚€λ§ˆ μ„€μ • -```bash -mysql -u jaryo_user -p jaryo < database/mariadb-schema.sql -``` - -#### 2.3 μ„œλΉ„μŠ€ 배포 -```bash -# μ†ŒμŠ€ μ½”λ“œ 클둠 -cd /volume1/web -git clone [GITEA_URL] jaryo -cd jaryo - -# μ˜μ‘΄μ„± μ„€μΉ˜ -npm install - -# λ°μ΄ν„°λ² μ΄μŠ€ μ΄ˆκΈ°ν™” -npm run init-mariadb - -# μ„œλΉ„μŠ€ μ‹œμž‘ -./start-service.sh -``` - -## ν™˜κ²½λ³„ μ„€μ • - -### Windows 개발 ν™˜κ²½ -`.env` 파일 생성: -```env -DB_HOST=localhost -DB_PORT=3306 -DB_USER=root -DB_PASSWORD=your_password -DB_NAME=jaryo -HOST=0.0.0.0 -PORT=3000 -``` - -### NAS 운영 ν™˜κ²½ -ν™˜κ²½ λ³€μˆ˜λŠ” μžλ™μœΌλ‘œ μ„€μ •λ©λ‹ˆλ‹€: -- `NODE_ENV=production` -- `DEPLOY_ENV=nas` -- Unix Socket μ—°κ²°: `/run/mysqld/mysqld10.sock` - -## 관리 λͺ…λ Ήμ–΄ - -### μ„œλΉ„μŠ€ 관리 -```bash -# μ‹œμž‘ -./start-service.sh - -# 쀑지 -kill $(cat jaryo-nas.pid) - -# 둜그 확인 -tail -f logs/app.log -``` - -### λ°μ΄ν„°λ² μ΄μŠ€ 관리 -```bash -# μ΄ˆκΈ°ν™” -npm run init-mariadb - -# 직접 μ—°κ²° -mysql -u jaryo_user -p -S /run/mysqld/mysqld10.sock jaryo -``` - -## 접속 정보 - -### κΈ°λ³Έ κ΄€λ¦¬μž 계정 -- **이메일**: admin@jaryo.com -- **λΉ„λ°€λ²ˆν˜Έ**: Hee150603! - -### μ„œλΉ„μŠ€ URL -- **메인**: http://[NAS-IP]:3005 -- **κ΄€λ¦¬μž**: http://[NAS-IP]:3005/admin - -## 문제 ν•΄κ²° - -### μ—°κ²° 였λ₯˜ -1. MariaDB μ„œλΉ„μŠ€ μƒνƒœ 확인 -2. λ°μ΄ν„°λ² μ΄μŠ€ 및 μ‚¬μš©μž κΆŒν•œ 확인 -3. μ†ŒμΌ“ 파일 경둜 확인 -4. λ°©ν™”λ²½ μ„€μ • 확인 - -### 상세 κ°€μ΄λ“œ -더 μžμ„Έν•œ μ„€μ • 방법은 `mariadb-setup.md` νŒŒμΌμ„ μ°Έμ‘°ν•˜μ„Έμš”. - -## 기술 μŠ€νƒ -- **Backend**: Node.js + Express -- **Database**: MariaDB -- **Frontend**: Vanilla JavaScript -- **Deployment**: Shell Scripts - -## 지원 -- 둜그 파일: `/volume1/web/jaryo/logs/app.log` -- μ„€μ • 파일: `database/mariadb-helper.js` -- μŠ€ν‚€λ§ˆ: `database/mariadb-schema.sql` \ No newline at end of file diff --git a/README_AUTO_START.md b/README_AUTO_START.md deleted file mode 100644 index c61f907..0000000 --- a/README_AUTO_START.md +++ /dev/null @@ -1,101 +0,0 @@ -# Jaryo File Manager μžλ™ μ‹œμž‘ μ„€μ • κ°€μ΄λ“œ - -## πŸš€ μžλ™ μ‹œμž‘ μ„€μ • 방법 - -### 방법 1: 배치 파일 μ‹€ν–‰ (ꢌμž₯) - -1. **κ΄€λ¦¬μž κΆŒν•œμœΌλ‘œ μ‹€ν–‰** - - `install-auto-startup.bat` νŒŒμΌμ„ 마우슀 우클릭 - - "κ΄€λ¦¬μž κΆŒν•œμœΌλ‘œ μ‹€ν–‰" 선택 - - μ•ˆλ‚΄μ— 따라 μ§„ν–‰ - -2. **μ„€μ • μ™„λ£Œ ν›„** - - 컴퓨터 μž¬μ‹œμž‘ μ‹œ μžλ™μœΌλ‘œ μ„œλΉ„μŠ€ μ‹œμž‘ - - μ„œλΉ„μŠ€ URL: http://99.1.110.50:3005 - -### 방법 2: μˆ˜λ™ μž‘μ—… μŠ€μΌ€μ€„λŸ¬ μ„€μ • - -1. **μž‘μ—… μŠ€μΌ€μ€„λŸ¬ μ—΄κΈ°** - - Windows ν‚€ + R β†’ `taskschd.msc` μž…λ ₯ β†’ μ—”ν„° - -2. **κΈ°λ³Έ μž‘μ—… λ§Œλ“€κΈ°** - - 였λ₯Έμͺ½ νŒ¨λ„μ—μ„œ "κΈ°λ³Έ μž‘μ—… λ§Œλ“€κΈ°" 클릭 - - 이름: `JaryoFileManagerAutoStart` - - μ„€λͺ…: `Jaryo File Manager μžλ™ μ‹œμž‘` - -3. **트리거 μ„€μ •** - - "컴퓨터λ₯Ό μ‹œμž‘ν•  λ•Œ" 선택 - -4. **λ™μž‘ μ„€μ •** - - "ν”„λ‘œκ·Έλž¨ μ‹œμž‘" 선택 - - ν”„λ‘œκ·Έλž¨/슀크립트: `C:\Users\COMTREE\claude_code\jaryo\start-jaryo-service.bat` - - μ‹œμž‘ μœ„μΉ˜: `C:\Users\COMTREE\claude_code\jaryo` - -5. **κ³ κΈ‰ μ„€μ •** - - "κ°€μž₯ 높은 κΆŒν•œμœΌλ‘œ μ‹€ν–‰" 체크 - - "μž‘μ—…μ΄ 이미 μ‹€ν–‰ 쀑인 경우 κ·œμΉ™": "μƒˆ μΈμŠ€ν„΄μŠ€ μ‹œμž‘ μ•ˆ 함" - -## πŸ”§ μ„œλΉ„μŠ€ 관리 λͺ…λ Ήμ–΄ - -### μˆ˜λ™ μ„œλΉ„μŠ€ μ œμ–΄ -```batch -# μ„œλΉ„μŠ€ μ‹œμž‘ -start-jaryo-service.bat - -# μ„œλΉ„μŠ€ 쀑지 -stop-jaryo-service.bat -``` - -### μžλ™ μ‹œμž‘ 관리 -```batch -# μžλ™ μ‹œμž‘ μ„€μ • -install-auto-startup.bat (κ΄€λ¦¬μž κΆŒν•œ ν•„μš”) - -# μžλ™ μ‹œμž‘ ν•΄μ œ -uninstall-auto-startup.bat (κ΄€λ¦¬μž κΆŒν•œ ν•„μš”) -``` - -### μž‘μ—… μŠ€μΌ€μ€„λŸ¬ λͺ…λ Ήμ–΄ -```cmd -# μž‘μ—… μƒνƒœ 확인 -schtasks /query /tn "JaryoFileManagerAutoStart" - -# μž‘μ—… μˆ˜λ™ μ‹€ν–‰ -schtasks /run /tn "JaryoFileManagerAutoStart" - -# μž‘μ—… μ‚­μ œ -schtasks /delete /tn "JaryoFileManagerAutoStart" /f -``` - -## 🌐 접속 정보 - -- **κ΄€λ¦¬μž νŽ˜μ΄μ§€**: http://99.1.110.50:3005/admin/index.html -- **메인 νŽ˜μ΄μ§€**: http://99.1.110.50:3005/index.html -- **API**: http://99.1.110.50:3005/api/files -- **μƒνƒœ 확인**: http://99.1.110.50:3005/health - -## πŸ“ 둜그 확인 - -- **둜그 파일**: `C:\Users\COMTREE\claude_code\jaryo\logs\app.log` -- **둜그 보기**: `type "C:\Users\COMTREE\claude_code\jaryo\logs\app.log"` - -## ⚠️ 문제 ν•΄κ²° - -### μ„œλΉ„μŠ€κ°€ μ‹œμž‘λ˜μ§€ μ•ŠλŠ” 경우 -1. Node.jsκ°€ μ„€μΉ˜λ˜μ–΄ μžˆλŠ”μ§€ 확인: `node --version` -2. ν”„λ‘œμ νŠΈ 디렉토리가 μ˜¬λ°”λ₯Έμ§€ 확인 -3. 포트 3005κ°€ μ‚¬μš© 쀑인지 확인: `netstat -an | findstr :3005` -4. 둜그 파일 확인 - -### μžλ™ μ‹œμž‘μ΄ μž‘λ™ν•˜μ§€ μ•ŠλŠ” 경우 -1. μž‘μ—… μŠ€μΌ€μ€„λŸ¬μ—μ„œ μž‘μ—… μƒνƒœ 확인 -2. κ΄€λ¦¬μž κΆŒν•œμœΌλ‘œ μ„€μ •ν–ˆλŠ”μ§€ 확인 -3. 배치 파일 κ²½λ‘œκ°€ μ˜¬λ°”λ₯Έμ§€ 확인 - -## πŸ“ž 지원 - -λ¬Έμ œκ°€ λ°œμƒν•˜λ©΄ λ‹€μŒμ„ ν™•μΈν•΄μ£Όμ„Έμš”: -1. 둜그 파일 λ‚΄μš© -2. μž‘μ—… μŠ€μΌ€μ€„λŸ¬ μž‘μ—… μƒνƒœ -3. 포트 μ‚¬μš© ν˜„ν™© -4. Node.js μ„€μΉ˜ μƒνƒœ \ No newline at end of file diff --git a/admin/script.js b/admin/script.js index 8ef7403..4c9efd4 100644 --- a/admin/script.js +++ b/admin/script.js @@ -1330,7 +1330,6 @@ class AdminFileManager { diff --git a/cookies.txt b/cookies.txt deleted file mode 100644 index 5d47335..0000000 --- a/cookies.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Netscape HTTP Cookie File -# https://curl.se/docs/http-cookies.html -# This file was generated by libcurl! Edit at your own risk. - -#HttpOnly_localhost FALSE / FALSE 1755922561 connect.sid s%3AmN1rJMxZAee73L5t1g-59UL0tXQP36Vr.6GJ1M%2FUaWj68J9z6Ua9MBxCG54Sl8OuOsRUQNQFlLZE diff --git a/deploy-to-nas.sh b/deploy-to-nas.sh index 6dbadd9..26a9257 100644 --- a/deploy-to-nas.sh +++ b/deploy-to-nas.sh @@ -9,13 +9,22 @@ NAS_IP="${1:-119.64.1.86}" PROJECT_NAME="${2:-jaryo}" NAS_USER="vibsin9322" -NAS_PASS="${3:-vibsin9322}" # κΈ°λ³Έ λΉ„λ°€λ²ˆν˜Έ, ν™˜κ²½λ³€μˆ˜ NAS_PASS둜 μ˜€λ²„λΌμ΄λ“œ κ°€λŠ₯ +# NAS_PASS μš°μ„ μˆœμœ„: ν™˜κ²½λ³€μˆ˜ > 슀크립트 3번째 인자 > ν”„λ‘¬ν”„νŠΈ 방식 +if [ -n "$3" ]; then + NAS_PASS="$3" +else + NAS_PASS="${NAS_PASS:-}" +fi DEPLOY_DIR="/volume1/web/$PROJECT_NAME" SERVICE_PORT="3005" GITEA_URL="http://$NAS_IP:3000/vibsin9322/jaryo.git" -# SSH λͺ…λ Ήμ–΄ μ€€λΉ„ -SSH_CMD="ssh -p 2222 -o ConnectTimeout=10 -o StrictHostKeyChecking=no $NAS_USER@$NAS_IP" +# SSH λͺ…λ Ήμ–΄ μ€€λΉ„ (NAS_PASSκ°€ 있으면 plink둜 λΉ„λŒ€ν™”μ‹, μ—†μœΌλ©΄ ssh ν”„λ‘¬ν”„νŠΈ) +if [ -n "$NAS_PASS" ]; then + SSH_CMD="plink -P 2222 -batch -pw \"$NAS_PASS\" $NAS_USER@$NAS_IP" +else + SSH_CMD="ssh -p 2222 -o ConnectTimeout=10 -o StrictHostKeyChecking=no $NAS_USER@$NAS_IP" +fi echo "==========================================" echo "πŸš€ μ‹œλ†€λ‘œμ§€ NAS μžλ£Œμ‹€ 배포 μ‹œμž‘" @@ -31,8 +40,12 @@ echo "==========================================" echo "πŸ“‹ 1단계: 사전 μš”κ΅¬μ‚¬ν•­ 확인" # SSH 방식 확인 -echo "πŸ”§ SSH 접속 방식: λΉ„λ°€λ²ˆν˜Έ ν”„λ‘¬ν”„νŠΈ 방식" -echo "πŸ“ SSH μ—°κ²° μ‹œ λΉ„λ°€λ²ˆν˜Έ μž…λ ₯이 ν•„μš”ν•©λ‹ˆλ‹€." +if [ -n "$NAS_PASS" ]; then + echo "πŸ”§ SSH 접속 방식: λΉ„λ°€λ²ˆν˜Έ λΉ„λŒ€ν™”μ‹(plink)" +else + echo "πŸ”§ SSH 접속 방식: λΉ„λ°€λ²ˆν˜Έ ν”„λ‘¬ν”„νŠΈ 방식" + echo "πŸ“ SSH μ—°κ²° μ‹œ λΉ„λ°€λ²ˆν˜Έ μž…λ ₯이 ν•„μš”ν•©λ‹ˆλ‹€." +fi # SSH μ—°κ²° ν…ŒμŠ€νŠΈ (포트 2222) echo "πŸ”— SSH μ—°κ²° ν…ŒμŠ€νŠΈ 쀑... (μ‚¬μš©μž: $NAS_USER, 포트: 2222)" @@ -274,7 +287,7 @@ chmod +x '$DEPLOY_DIR/stop-nas-service.sh' echo "" echo "🎬 5단계: μ„œλΉ„μŠ€ μ‹œμž‘" -eval "$SSH_CMD '$DEPLOY_DIR/start-nas-service.sh" +eval "$SSH_CMD '$DEPLOY_DIR/start-nas-service.sh'" # 6단계: 접속 ν…ŒμŠ€νŠΈ echo "" @@ -303,5 +316,5 @@ if curl -s "http://$NAS_IP:$SERVICE_PORT" >/dev/null; then else echo "❌ μ„œλΉ„μŠ€ 접속 μ‹€νŒ¨" echo "둜그 확인:" - eval "$SSH_CMD 'tail -20 $DEPLOY_DIR/logs/app.log" + eval "$SSH_CMD 'tail -20 $DEPLOY_DIR/logs/app.log'" fi \ No newline at end of file diff --git a/mariadb-setup.md b/mariadb-setup.md deleted file mode 100644 index affdfc8..0000000 --- a/mariadb-setup.md +++ /dev/null @@ -1,130 +0,0 @@ -# μ‹œλ†€λ‘œμ§€ NAS MariaDB μ„€μ • κ°€μ΄λ“œ - -## 1. MariaDB νŒ¨ν‚€μ§€ μ„€μΉ˜ - -1. **DSM νŒ¨ν‚€μ§€ μ„Όν„°** μ—΄κΈ° -2. **MariaDB 10** 검색 및 μ„€μΉ˜ -3. μ„€μΉ˜ μ™„λ£Œ ν›„ **μ‹€ν–‰** - -## 2. MariaDB 초기 μ„€μ • - -### 2.1 MariaDB 관리 도ꡬ 접속 -- DSMμ—μ„œ **MariaDB 10** μ•± μ‹€ν–‰ -- λ˜λŠ” μ›Ή λΈŒλΌμš°μ €μ—μ„œ `http://NAS-IP:3307` 접속 - -### 2.2 κ΄€λ¦¬μž κ³„μ •μœΌλ‘œ 둜그인 -- μ‚¬μš©μž: `root` -- λΉ„λ°€λ²ˆν˜Έ: μ„€μΉ˜ μ‹œ μ„€μ •ν•œ λΉ„λ°€λ²ˆν˜Έ - -## 3. μžλ£Œμ‹€ λ°μ΄ν„°λ² μ΄μŠ€ μ„€μ • - -### 3.1 λ°μ΄ν„°λ² μ΄μŠ€ 생성 -```sql -CREATE DATABASE IF NOT EXISTS jaryo -CHARACTER SET utf8mb4 -COLLATE utf8mb4_unicode_ci; -``` - -### 3.2 μ „μš© μ‚¬μš©μž 생성 -```sql -CREATE USER 'jaryo_user'@'localhost' IDENTIFIED BY 'JaryoPass2024!@#'; -GRANT ALL PRIVILEGES ON jaryo.* TO 'jaryo_user'@'localhost'; -FLUSH PRIVILEGES; -``` - -### 3.3 ν…Œμ΄λΈ” 생성 (μŠ€ν‚€λ§ˆ 적용) -```bash -# NAS SSH 접속 ν›„ -cd /volume1/web/jaryo -mysql -u jaryo_user -p jaryo < database/mariadb-schema.sql -``` - -## 4. μ—°κ²° μ„€μ • 확인 - -### 4.1 Unix Socket 경둜 확인 -```bash -sudo find /run -name "*.sock" | grep mysql -# 일반적인 경둜: /run/mysqld/mysqld10.sock -``` - -### 4.2 μ—°κ²° ν…ŒμŠ€νŠΈ -```bash -mysql -u jaryo_user -p -S /run/mysqld/mysqld10.sock jaryo -``` - -## 5. NAS μžλ£Œμ‹€ μ„œλΉ„μŠ€ 배포 - -### 5.1 μžλ™ 배포 -```bash -./deploy-to-nas.sh [NAS-IP] jaryo [PASSWORD] -``` - -### 5.2 μˆ˜λ™ μ΄ˆκΈ°ν™” (ν•„μš”μ‹œ) -```bash -cd /volume1/web/jaryo -npm run init-mariadb -``` - -## 6. 문제 ν•΄κ²° - -### 6.1 μ—°κ²° 였λ₯˜ -- MariaDB μ„œλΉ„μŠ€ μƒνƒœ 확인: `sudo systemctl status mariadb` -- μ†ŒμΌ“ 파일 κΆŒν•œ 확인: `ls -la /run/mysqld/` -- λ°©ν™”λ²½ μ„€μ • 확인 - -### 6.2 κΆŒν•œ 였λ₯˜ -```sql --- κΆŒν•œ μž¬μ„€μ • -GRANT ALL PRIVILEGES ON jaryo.* TO 'jaryo_user'@'localhost'; -FLUSH PRIVILEGES; -``` - -### 6.3 ν•œκΈ€ 데이터 문제 -```sql --- λ¬Έμžμ…‹ 확인 -SHOW VARIABLES LIKE 'character_set%'; -SHOW VARIABLES LIKE 'collation%'; -``` - -## 7. μ„±λŠ₯ μ΅œμ ν™” - -### 7.1 인덱슀 확인 -```sql -USE jaryo; -SHOW INDEX FROM files; -SHOW INDEX FROM file_attachments; -``` - -### 7.2 쿼리 μ΅œμ ν™” -```sql --- 슬둜우 쿼리 둜그 ν™œμ„±ν™” -SET GLOBAL slow_query_log = 'ON'; -SET GLOBAL long_query_time = 2; -``` - -## 8. λ°±μ—… 및 볡원 - -### 8.1 λ°μ΄ν„°λ² μ΄μŠ€ λ°±μ—… -```bash -mysqldump -u jaryo_user -p jaryo > jaryo_backup_$(date +%Y%m%d).sql -``` - -### 8.2 λ°μ΄ν„°λ² μ΄μŠ€ 볡원 -```bash -mysql -u jaryo_user -p jaryo < jaryo_backup_YYYYMMDD.sql -``` - -## 9. λ³΄μ•ˆ μ„€μ • - -### 9.1 λΉ„λ°€λ²ˆν˜Έ λ³€κ²½ -```sql -ALTER USER 'jaryo_user'@'localhost' IDENTIFIED BY 'NEW_SECURE_PASSWORD'; -``` - -### 9.2 λΆˆν•„μš”ν•œ κΆŒν•œ 제거 -```sql --- ν…ŒμŠ€νŠΈ λ°μ΄ν„°λ² μ΄μŠ€ 제거 -DROP DATABASE IF EXISTS test; -DELETE FROM mysql.user WHERE User=''; -FLUSH PRIVILEGES; -``` \ No newline at end of file diff --git a/server.js b/server.js index 3a5f603..ac4ef33 100644 --- a/server.js +++ b/server.js @@ -6,12 +6,26 @@ const fs = require('fs'); const bcrypt = require('bcrypt'); const session = require('express-session'); const { v4: uuidv4 } = require('uuid'); -const DatabaseHelper = require('./database/db-helper'); +// ν™˜κ²½μ— λ”°λ₯Έ λ°μ΄ν„°λ² μ΄μŠ€ 헬퍼 선택 +const isNAS = process.env.NODE_ENV === 'production' || process.env.DEPLOY_ENV === 'nas'; +const isWindows = process.platform === 'win32' && !isNAS; + +let DatabaseHelper; +if (isNAS) { + DatabaseHelper = require('./database/mariadb-helper'); + console.log('πŸ—„οΈ NAS ν™˜κ²½: MariaDB μ‚¬μš©'); +} else if (isWindows) { + DatabaseHelper = require('./database/db-helper'); + console.log('πŸ—„οΈ 둜컬 Windows ν™˜κ²½: SQLite μ‚¬μš©'); +} else { + DatabaseHelper = require('./database/mariadb-helper'); + console.log('πŸ—„οΈ Linux ν™˜κ²½: MariaDB μ‚¬μš©'); +} const app = express(); const PORT = process.env.PORT || 3005; -// λ°μ΄ν„°λ² μ΄μŠ€ 헬퍼 μΈμŠ€ν„΄μŠ€ (SQLite - 둜컬 ν…ŒμŠ€νŠΈμš©) +// λ°μ΄ν„°λ² μ΄μŠ€ 헬퍼 μΈμŠ€ν„΄μŠ€ const db = new DatabaseHelper(); // 미듀웨어 μ„€μ •