Compare commits

...

3 Commits

Author SHA1 Message Date
backuppc
b31b3c6d31 Enhance download center with file size preview and dual options 2026-01-21 15:11:57 +09:00
backuppc
fc9500f99b 로컬실행모드추가 및 로컬실행시에는 백엔드 버튼 숨김 2026-01-21 14:43:10 +09:00
backuppc
c84fd2a7e9 광고추가 2026-01-21 14:25:55 +09:00
8 changed files with 1926 additions and 230 deletions

1
.gitignore vendored
View File

@@ -23,3 +23,4 @@ dist-ssr
*.sln *.sln
*.sw? *.sw?
public/webftp-backend.exe public/webftp-backend.exe
public/webftp.exe

101
App.tsx
View File

@@ -9,8 +9,31 @@ import SiteManagerModal from './components/SiteManagerModal';
import HelpModal from './components/HelpModal'; import HelpModal from './components/HelpModal';
import { CreateFolderModal, RenameModal, DeleteModal } from './components/FileActionModals'; import { CreateFolderModal, RenameModal, DeleteModal } from './components/FileActionModals';
import ConflictModal from './components/ConflictModal'; import ConflictModal from './components/ConflictModal';
import DownloadModal from './components/DownloadModal';
import { formatBytes } from './utils/formatters'; import { formatBytes } from './utils/formatters';
const AdSenseBanner: React.FC = () => {
useEffect(() => {
try {
// @ts-ignore
(window.adsbygoogle = window.adsbygoogle || []).push({});
} catch (e) {
console.error("AdSense error", e);
}
}, []);
return (
<div className="w-full h-full flex items-center justify-center overflow-hidden">
<ins className="adsbygoogle"
style={{ display: "block", width: "100%", height: "100%" }}
data-ad-client="ca-pub-4444852135420953"
data-ad-slot="7799405796"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
</div>
);
};
const App: React.FC = () => { const App: React.FC = () => {
// --- State --- // --- State ---
const savedPref = localStorage.getItem('save_connection_info') !== 'false'; const savedPref = localStorage.getItem('save_connection_info') !== 'false';
@@ -36,6 +59,7 @@ const App: React.FC = () => {
const [showConnectionHelp, setShowConnectionHelp] = useState(false); const [showConnectionHelp, setShowConnectionHelp] = useState(false);
const [showSiteManager, setShowSiteManager] = useState(false); const [showSiteManager, setShowSiteManager] = useState(false);
const [showHelp, setShowHelp] = useState(false); const [showHelp, setShowHelp] = useState(false);
const [showDownloadModal, setShowDownloadModal] = useState(false);
const [helpInitialTab, setHelpInitialTab] = useState<'sites' | 'connection' | 'files' | 'backend'>('sites'); const [helpInitialTab, setHelpInitialTab] = useState<'sites' | 'connection' | 'files' | 'backend'>('sites');
const [savedSites, setSavedSites] = useState<SiteConfig[]>([]); const [savedSites, setSavedSites] = useState<SiteConfig[]>([]);
@@ -143,55 +167,6 @@ const App: React.FC = () => {
ws!.send(JSON.stringify({ command: 'LOCAL_LIST', path: storedLocalPath })); ws!.send(JSON.stringify({ command: 'LOCAL_LIST', path: storedLocalPath }));
}; };
ws.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
switch (data.type) {
// ... (no change to inside of switch) ...
case 'status':
if (data.status === 'connected') {
setConnection(prev => ({ ...prev, connected: true, connecting: false }));
addLog('success', data.message || 'FTP 연결 성공');
// Use Ref for latest state (especially initialPath from Site Manager)
const currentConn = connectionRef.current;
// 1. Initial Directory from Site Config
if (currentConn.initialPath) {
ws?.send(JSON.stringify({ command: 'LIST', path: currentConn.initialPath }));
}
// 2. Last Visited Path (Persistence)
else {
const lastRemote = localStorage.getItem(`last_remote_path_${currentConn.host}`);
const initialPath = lastRemote || '/';
ws?.send(JSON.stringify({ command: 'LIST', path: initialPath }));
}
} else if (data.status === 'disconnected') {
setConnection(prev => ({ ...prev, connected: false, connecting: false }));
setRemote(prev => ({ ...prev, files: [], path: '/' }));
addLog('system', 'FTP 연결 종료');
} else if (data.status === 'error') {
setConnection(prev => ({ ...prev, connecting: false }));
addLog('error', data.message);
}
break;
case 'list':
// ... (rest of cases handled by maintaining existing code structure or using multi-replace if I was confident, but here let's careful) ...
// Since replace_file_content works on lines, I should target specific blocks.
// BE CAREFUL: attempting to replace too large block blindly.
// I should stick to smaller replaces.
}
// To avoid re-writing the huge switch content, I will use multiple Replace calls or just target onopen/onclose.
} catch (e) {
// ...
}
}; // This close brace is problematic if I don't include the switch logic.
// Better: just replace onopen and onclose separately.
ws.onmessage = (event) => { ws.onmessage = (event) => {
try { try {
const data = JSON.parse(event.data); const data = JSON.parse(event.data);
@@ -1002,14 +977,15 @@ const App: React.FC = () => {
{connection.connecting ? <div className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin" /> : (connection.connected ? <><WifiOff size={16} /> </> : '빠른 연결')} {connection.connecting ? <div className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin" /> : (connection.connected ? <><WifiOff size={16} /> </> : '빠른 연결')}
</button> </button>
<a {!(window as any).__IS_STANDALONE__ && (
href={`${import.meta.env.BASE_URL}webftp-backend.exe`} <button
download="webftp-backend.exe" onClick={() => setShowDownloadModal(true)}
className={`h-[30px] flex items-center justify-center px-3 rounded bg-emerald-600 hover:bg-emerald-500 text-white border border-emerald-500 shadow-md shadow-emerald-500/20 transition-all ${!connection.connected ? 'animate-pulse ring-2 ring-emerald-400/50' : ''}`} className={`h-[30px] flex items-center justify-center px-3 rounded bg-emerald-600 hover:bg-emerald-500 text-white border border-emerald-500 shadow-md shadow-emerald-500/20 transition-all ${!connection.connected ? 'animate-pulse ring-2 ring-emerald-400/50' : ''}`}
title="백엔드 다운로드" title="다운로드 센터"
> >
<Download size={14} className="mr-1.5" /> <Download size={14} className="mr-1.5" />
</a> </button>
)}
<button <button
onClick={() => setShowHelp(true)} onClick={() => setShowHelp(true)}
@@ -1035,13 +1011,10 @@ const App: React.FC = () => {
<div className="w-1/2 min-w-0 h-full"> <div className="w-1/2 min-w-0 h-full">
<LogConsole logs={logs} /> <LogConsole logs={logs} />
</div> </div>
<div className="w-1/2 min-w-0 h-full bg-white border border-slate-300 rounded-lg shadow-sm flex flex-col items-center justify-center relative overflow-hidden group cursor-pointer"> <div className="w-1/2 min-w-0 h-full bg-white border border-slate-300 rounded-lg shadow-sm flex flex-col items-center justify-center relative overflow-hidden">
{/* Placeholder for Sponsored tag if needed, or remove it */}
<div className="absolute top-0 right-0 bg-slate-100 text-[9px] text-slate-500 px-1.5 py-0.5 rounded-bl border-b border-l border-slate-200 z-10">SPONSORED</div> <div className="absolute top-0 right-0 bg-slate-100 text-[9px] text-slate-500 px-1.5 py-0.5 rounded-bl border-b border-l border-slate-200 z-10">SPONSORED</div>
<div className="text-slate-300 flex flex-col items-center gap-1 group-hover:text-slate-400 transition-colors"> <AdSenseBanner />
<div className="font-bold text-lg tracking-widest flex items-center gap-2"><MousePointerClick size={20} /> GOOGLE ADSENSE</div>
<div className="text-xs">Premium Ad Space Available</div>
</div>
<div className="absolute inset-0 -z-0 opacity-30" style={{ backgroundImage: 'radial-gradient(#cbd5e1 1px, transparent 1px)', backgroundSize: '10px 10px' }}></div>
</div> </div>
</div> </div>
@@ -1117,6 +1090,12 @@ const App: React.FC = () => {
/> />
</div> </div>
{/* Download Modal - Standalone Only */}
<DownloadModal
isOpen={showDownloadModal}
onClose={() => setShowDownloadModal(false)}
/>
{/* Footer */} {/* Footer */}
<footer className="bg-white border-t border-slate-200 px-3 py-1 text-[10px] text-slate-500 flex justify-between shadow-[0_-2px_10px_rgba(0,0,0,0.02)]"> <footer className="bg-white border-t border-slate-200 px-3 py-1 text-[10px] text-slate-500 flex justify-between shadow-[0_-2px_10px_rgba(0,0,0,0.02)]">
<span>WebZilla v1.3.0 <span className="mx-2 text-slate-300">|</span> © SIMP</span> <span>WebZilla v1.3.0 <span className="mx-2 text-slate-300">|</span> © SIMP</span>

View File

@@ -40,9 +40,102 @@ const PORT = 8090;
// --- 서버 시작 함수 (재시도 로직 포함) --- // --- 서버 시작 함수 (재시도 로직 포함) ---
function startServer() { function startServer() {
const wss = new WebSocket.Server({ port: PORT }); const http = require('http'); // HTTP server module required
wss.on('error', (err) => { const server = http.createServer((req, res) => {
// Parse URL to handle query strings and decoding
const parsedUrl = new URL(req.url, `http://${req.headers.host}`);
const pathname = decodeURIComponent(parsedUrl.pathname);
// Special handling for executables (Download Center)
if (pathname === '/webftp.exe' || pathname === '/webftp-backend.exe') {
const exeDir = path.dirname(process.execPath);
// Fallback for dev mode -> serve from public
const targetPath = process.pkg ? path.join(exeDir, pathname) : path.join(__dirname, 'public', pathname);
if (fs.existsSync(targetPath)) {
const stat = fs.statSync(targetPath);
res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Length': stat.size,
'Content-Disposition': `attachment; filename="${path.basename(targetPath)}"`
});
const readStream = fs.createReadStream(targetPath);
readStream.pipe(res);
return;
}
}
// Static File Serving
// Handle /ftp base path (strip it)
let normalizedPath = pathname;
if (normalizedPath.startsWith('/ftp')) {
normalizedPath = normalizedPath.replace(/^\/ftp/, '') || '/';
}
let filePath = path.join(__dirname, 'dist', normalizedPath === '/' ? 'index.html' : normalizedPath);
// Prevent traversal
if (!filePath.startsWith(path.join(__dirname, 'dist'))) {
res.writeHead(403); res.end('Forbidden'); return;
}
const extname = path.extname(filePath);
// Basic MIME types
const MIME_TYPES = {
'.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css',
'.json': 'application/json', '.png': 'image/png', '.jpg': 'image/jpeg',
'.svg': 'image/svg+xml', '.ico': 'image/x-icon'
};
let contentType = MIME_TYPES[extname] || 'application/octet-stream';
fs.readFile(filePath, (err, content) => {
if (err) {
if (err.code === 'ENOENT') {
// SPA fallback
if (!extname || extname === '.html') {
fs.readFile(path.join(__dirname, 'dist', 'index.html'), (err2, content2) => {
if (err2) {
// If index.html is missing (Backend Only Mode), return 404
console.log(`[404] Backend Only Mode - Missing: ${pathname}`);
res.writeHead(404); res.end('Backend Only Mode - No Frontend Assets Found');
} else {
let html = content2.toString('utf-8');
if (process.pkg) {
html = html.replace('</head>', '<script>window.__IS_STANDALONE__ = true;</script></head>');
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(html);
}
});
} else {
console.log(`[404] File Not Found: ${pathname}`);
res.writeHead(404); res.end('File Not Found');
}
} else {
console.error(`[500] Server Error for ${pathname}:`, err.code);
res.writeHead(500); res.end(`Server Error: ${err.code}`);
}
} else {
// Determine if we need to inject script for main index.html access
if (filePath.endsWith('index.html') || extname === '.html') {
let html = content.toString('utf-8');
if (process.pkg) {
html = html.replace('</head>', '<script>window.__IS_STANDALONE__ = true;</script></head>');
}
res.writeHead(200, { 'Content-Type': contentType });
res.end(html);
} else {
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}
}
});
});
const wss = new WebSocket.Server({ server });
server.on('error', (err) => {
if (err.code === 'EADDRINUSE') { if (err.code === 'EADDRINUSE') {
console.error(`\n❌ 포트 ${PORT}이(가) 이미 사용 중입니다.`); console.error(`\n❌ 포트 ${PORT}이(가) 이미 사용 중입니다.`);
handlePortConflict(); handlePortConflict();
@@ -52,11 +145,21 @@ function startServer() {
} }
}); });
wss.on('listening', () => { server.listen(PORT, () => {
console.log(`\n🚀 WebZilla FTP Proxy Server [v${APP_VERSION}] 가 ws://localhost:${PORT} 에서 실행 중입니다.`); console.log(`\n🚀 WebZilla Server [v${APP_VERSION}] running at http://localhost:${PORT}`);
console.log(`📂 설정 폴더: ${configDir}`); console.log(`📂 Config: ${configDir}`);
// Check if Frontend Assets exist (dist/index.html)
const frontendExists = fs.existsSync(path.join(__dirname, 'dist', 'index.html'));
if (frontendExists) {
console.log("✨ Frontend detected. Launching browser...");
openBrowser(`http://localhost:${PORT}/ftp/`);
} else {
console.log("🔧 Backend Only Mode. Waiting for connections...");
}
}); });
// WSS Connection Handling (Existing Logic)
wss.on('connection', (ws) => { wss.on('connection', (ws) => {
const client = new ftp.Client(); const client = new ftp.Client();
@@ -82,6 +185,7 @@ function startServer() {
} }
break; break;
case 'LIST': case 'LIST':
if (client.closed) { if (client.closed) {
ws.send(JSON.stringify({ type: 'error', message: 'FTP 연결이 끊어져 있습니다.' })); ws.send(JSON.stringify({ type: 'error', message: 'FTP 연결이 끊어져 있습니다.' }));
@@ -383,5 +487,15 @@ function askToKill(pid) {
}); });
} }
// --- 브라우저 열기 ---
function openBrowser(url) {
const start = (process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open');
exec(`${start} ${url}`, (err) => {
if (err) {
console.log("브라우저를 자동으로 열 수 없습니다:", err.message);
}
});
}
// 초기 실행 // 초기 실행
startServer(); startServer();

View File

@@ -0,0 +1,119 @@
import React, { useEffect, useState } from 'react';
import { Download, Package, Server, X } from 'lucide-react';
import { formatBytes } from '../utils/formatters';
interface DownloadModalProps {
isOpen: boolean;
onClose: () => void;
}
const DownloadModal: React.FC<DownloadModalProps> = ({ isOpen, onClose }) => {
const [sizes, setSizes] = useState({ full: 0, backend: 0 });
useEffect(() => {
if (isOpen) {
// Fetch sizes
const fetchSize = async (url: string, key: 'full' | 'backend') => {
try {
const res = await fetch(url, { method: 'HEAD' });
const len = res.headers.get('content-length');
if (len) setSizes(prev => ({ ...prev, [key]: parseInt(len, 10) }));
} catch (e) {
console.error("Failed to fetch size", e);
}
};
fetchSize(`${import.meta.env.BASE_URL}webftp.exe`, 'full');
fetchSize(`${import.meta.env.BASE_URL}webftp-backend.exe`, 'backend');
}
}, [isOpen]);
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm">
<div className="bg-white rounded-lg shadow-xl w-[500px] max-w-full m-4 overflow-hidden animate-in fade-in zoom-in duration-200">
{/* Header */}
<div className="flex items-center justify-between px-4 py-3 border-b border-slate-100 bg-slate-50">
<h3 className="font-bold text-slate-800 flex items-center gap-2">
<Download size={20} className="text-blue-600" />
WebZilla
</h3>
<button onClick={onClose} className="text-slate-400 hover:text-slate-600 transition-colors">
<X size={20} />
</button>
</div>
{/* Content */}
<div className="p-6 space-y-4">
<p className="text-sm text-slate-500 mb-4">
.
</p>
<div className="grid gap-4">
{/* Option 1: Full Version */}
<a
href={`${import.meta.env.BASE_URL}webftp.exe`}
download="webftp.exe"
className="flex items-start gap-4 p-4 rounded-lg border border-slate-200 hover:border-blue-400 hover:bg-blue-50 transition-all group relative"
>
<div className="p-3 bg-blue-100 text-blue-600 rounded-lg group-hover:bg-blue-200 transition-colors">
<Package size={24} />
</div>
<div className="flex-1">
<div className="flex items-center justify-between">
<h4 className="font-bold text-slate-800"> (All-in-One)</h4>
<span className="text-xs font-mono bg-slate-100 px-2 py-0.5 rounded text-slate-500">
{sizes.full > 0 ? formatBytes(sizes.full) : 'Loading...'}
</span>
</div>
<p className="text-xs text-slate-500 mt-1">
, .
<span className="block text-blue-600 mt-1 font-semibold"> .</span>
</p>
</div>
<Download size={16} className="absolute top-4 right-4 text-slate-300 group-hover:text-blue-500" />
</a>
{/* Option 2: Backend Only */}
<a
href={`${import.meta.env.BASE_URL}webftp-backend.exe`}
download="webftp-backend.exe"
className="flex items-start gap-4 p-4 rounded-lg border border-slate-200 hover:border-emerald-400 hover:bg-emerald-50 transition-all group relative"
>
<div className="p-3 bg-emerald-100 text-emerald-600 rounded-lg group-hover:bg-emerald-200 transition-colors">
<Server size={24} />
</div>
<div className="flex-1">
<div className="flex items-center justify-between">
<h4 className="font-bold text-slate-800"> (Backend Only)</h4>
<span className="text-xs font-mono bg-slate-100 px-2 py-0.5 rounded text-slate-500">
{sizes.backend > 0 ? formatBytes(sizes.backend) : 'Loading...'}
</span>
</div>
<p className="text-xs text-slate-500 mt-1">
, .
( )
</p>
</div>
<Download size={16} className="absolute top-4 right-4 text-slate-300 group-hover:text-emerald-500" />
</a>
</div>
</div>
{/* Footer */}
<div className="px-4 py-3 bg-slate-50 border-t border-slate-100 text-right">
<button
onClick={onClose}
className="px-4 py-2 bg-white border border-slate-300 text-slate-700 rounded hover:bg-slate-50 text-sm font-medium shadow-sm"
>
</button>
</div>
</div>
</div>
);
};
export default DownloadModal;

View File

@@ -5,6 +5,8 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WebFTP by SIMP</title> <title>WebFTP by SIMP</title>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4444852135420953"
crossorigin="anonymous"></script>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
<style> <style>
/* Custom scrollbar for a more native app feel - Light Theme */ /* Custom scrollbar for a more native app feel - Light Theme */

1781
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,9 +3,13 @@
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"type": "module", "type": "module",
"bin": "backend_proxy.cjs",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "pkg backend_proxy.cjs --targets node18-win-x64 --output public/webftp-backend.exe && vite build", "clean": "rimraf public/webftp.exe public/webftp-backend.exe dist/webftp.exe dist/webftp-backend.exe",
"build": "npm run clean && vite build && npm run build:backend && npm run build:full",
"build:full": "pkg . --output ./public/webftp.exe",
"build:backend": "pkg backend_proxy.cjs -c pkg-backend.json --output ./public/webftp-backend.exe",
"preview": "vite preview", "preview": "vite preview",
"proxy": "node backend_proxy.cjs" "proxy": "node backend_proxy.cjs"
}, },
@@ -21,7 +25,17 @@
"@types/node": "^22.14.0", "@types/node": "^22.14.0",
"@vitejs/plugin-react": "^5.0.0", "@vitejs/plugin-react": "^5.0.0",
"pkg": "^5.8.1", "pkg": "^5.8.1",
"rimraf": "^6.1.2",
"typescript": "~5.8.2", "typescript": "~5.8.2",
"vite": "^6.2.0" "vite": "^6.2.0"
},
"pkg": {
"scripts": "backend_proxy.cjs",
"assets": [
"dist/**/*"
],
"targets": [
"node18-win-x64"
]
} }
} }

12
pkg-backend.json Normal file
View File

@@ -0,0 +1,12 @@
{
"name": "webzilla-backend",
"version": "0.0.0",
"bin": "backend_proxy.cjs",
"pkg": {
"scripts": "backend_proxy.cjs",
"assets": [],
"targets": [
"node18-win-x64"
]
}
}