Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
from fastapi import FastAPI, BackgroundTasks | |
from fastapi.responses import HTMLResponse, JSONResponse, Response | |
from fastapi.staticfiles import StaticFiles | |
import pathlib, os, uvicorn, base64, json | |
from typing import Dict, List, Any | |
import asyncio | |
import logging | |
# ๋ก๊น ์ค์ | |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
logger = logging.getLogger(__name__) | |
BASE = pathlib.Path(__file__).parent | |
app = FastAPI() | |
app.mount("/static", StaticFiles(directory=BASE), name="static") | |
# PDF ๋๋ ํ ๋ฆฌ ์ค์ | |
PDF_DIR = BASE / "pdf" | |
if not PDF_DIR.exists(): | |
PDF_DIR.mkdir(parents=True) | |
# ์บ์ ๋๋ ํ ๋ฆฌ ์ค์ | |
CACHE_DIR = BASE / "cache" | |
if not CACHE_DIR.exists(): | |
CACHE_DIR.mkdir(parents=True) | |
# ์ ์ญ ์บ์ ๊ฐ์ฒด | |
pdf_cache: Dict[str, Dict[str, Any]] = {} | |
# PDF ํ์ผ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ | |
def get_pdf_files(): | |
pdf_files = [] | |
if PDF_DIR.exists(): | |
pdf_files = [f for f in PDF_DIR.glob("*.pdf")] | |
return pdf_files | |
# PDF ์ธ๋ค์ผ ์์ฑ ๋ฐ ํ๋ก์ ํธ ๋ฐ์ดํฐ ์ค๋น | |
def generate_pdf_projects(): | |
projects_data = [] | |
pdf_files = get_pdf_files() | |
for pdf_file in pdf_files: | |
projects_data.append({ | |
"path": str(pdf_file), | |
"name": pdf_file.stem, | |
"cached": pdf_file.stem in pdf_cache | |
}) | |
return projects_data | |
# ์บ์ ํ์ผ ๊ฒฝ๋ก ์์ฑ | |
def get_cache_path(pdf_name: str): | |
return CACHE_DIR / f"{pdf_name}_cache.json" | |
# PDF ํ์ด์ง ์บ์ฑ ํจ์ | |
async def cache_pdf(pdf_path: str): | |
try: | |
import fitz # PyMuPDF | |
pdf_file = pathlib.Path(pdf_path) | |
pdf_name = pdf_file.stem | |
# ์ด๋ฏธ ์บ์ฑ ์ค์ด๊ฑฐ๋ ์บ์ฑ ์๋ฃ๋ PDF๋ ๊ฑด๋๋ฐ๊ธฐ | |
if pdf_name in pdf_cache and pdf_cache[pdf_name].get("status") in ["processing", "completed"]: | |
logger.info(f"PDF {pdf_name} ์ด๋ฏธ ์บ์ฑ ์๋ฃ ๋๋ ์งํ ์ค") | |
return | |
# ์บ์ ์ํ ์ ๋ฐ์ดํธ | |
pdf_cache[pdf_name] = {"status": "processing", "progress": 0, "pages": []} | |
# ์บ์ ํ์ผ์ด ์ด๋ฏธ ์กด์ฌํ๋์ง ํ์ธ | |
cache_path = get_cache_path(pdf_name) | |
if cache_path.exists(): | |
try: | |
with open(cache_path, "r") as cache_file: | |
cached_data = json.load(cache_file) | |
pdf_cache[pdf_name] = cached_data | |
pdf_cache[pdf_name]["status"] = "completed" | |
logger.info(f"์บ์ ํ์ผ์์ {pdf_name} ๋ก๋ ์๋ฃ") | |
return | |
except Exception as e: | |
logger.error(f"์บ์ ํ์ผ ๋ก๋ ์คํจ: {e}") | |
# ๊ณ์ ์งํํ์ฌ ์๋ก ์บ์ฑ | |
# PDF ํ์ผ ์ด๊ธฐ | |
doc = fitz.open(pdf_path) | |
total_pages = doc.page_count | |
# ๊ฐ ํ์ด์ง๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํํ๊ณ ์บ์ฑ | |
pages = [] | |
for page_num in range(total_pages): | |
# ์งํ ์ํ ์ ๋ฐ์ดํธ | |
progress = round((page_num + 1) / total_pages * 100) | |
pdf_cache[pdf_name]["progress"] = progress | |
# ํ์ด์ง ๋ ๋๋ง | |
page = doc[page_num] | |
pix = page.get_pixmap() # ๊ธฐ๋ณธ ํด์๋๋ก ๋ ๋๋ง | |
img_data = pix.tobytes("png") | |
# Base64 ์ธ์ฝ๋ฉ | |
b64_img = base64.b64encode(img_data).decode('utf-8') | |
img_src = f"data:image/png;base64,{b64_img}" | |
# ์ธ๋ค์ผ์ฉ ์์ ์ด๋ฏธ์ง (์ฒซ ํ์ด์ง๋ง) | |
if page_num == 0: | |
pix_thumb = page.get_pixmap(matrix=fitz.Matrix(0.3, 0.3)) # ๋ ์์ ์ธ๋ค์ผ | |
thumb_data = pix_thumb.tobytes("png") | |
b64_thumb = base64.b64encode(thumb_data).decode('utf-8') | |
thumb_src = f"data:image/png;base64,{b64_thumb}" | |
else: | |
thumb_src = "" # ์ฒซ ํ์ด์ง ์ธ์๋ ์ธ๋ค์ผ ์๋ต | |
# ํ์ด์ง ์ ๋ณด ์ ์ฅ | |
pages.append({ | |
"src": img_src, | |
"thumb": thumb_src if page_num == 0 else "" | |
}) | |
# ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ๋ฅผ ์ํด ์ค๊ฐ ์ ์ฅ (20ํ์ด์ง๋ง๋ค) | |
if (page_num + 1) % 20 == 0 or page_num == total_pages - 1: | |
pdf_cache[pdf_name]["pages"] = pages | |
# ์บ์ ํ์ผ ์ ์ฅ (์งํ ์ค) | |
try: | |
with open(cache_path, "w") as cache_file: | |
json.dump({ | |
"status": "processing", | |
"progress": progress, | |
"pages": pages, | |
"total_pages": total_pages | |
}, cache_file) | |
except Exception as e: | |
logger.error(f"์ค๊ฐ ์บ์ ์ ์ฅ ์คํจ: {e}") | |
# ์บ์ฑ ์๋ฃ | |
pdf_cache[pdf_name] = { | |
"status": "completed", | |
"progress": 100, | |
"pages": pages, | |
"total_pages": total_pages | |
} | |
# ์ต์ข ์บ์ ํ์ผ ์ ์ฅ | |
try: | |
with open(cache_path, "w") as cache_file: | |
json.dump(pdf_cache[pdf_name], cache_file) | |
logger.info(f"PDF {pdf_name} ์บ์ฑ ์๋ฃ, {total_pages}ํ์ด์ง") | |
except Exception as e: | |
logger.error(f"์ต์ข ์บ์ ์ ์ฅ ์คํจ: {e}") | |
except Exception as e: | |
import traceback | |
logger.error(f"PDF ์บ์ฑ ์ค๋ฅ: {str(e)}\n{traceback.format_exc()}") | |
if pdf_name in pdf_cache: | |
pdf_cache[pdf_name]["status"] = "error" | |
pdf_cache[pdf_name]["error"] = str(e) | |
# ์์ ์ ๋ชจ๋ PDF ํ์ผ ์บ์ฑ | |
async def init_cache_all_pdfs(): | |
logger.info("PDF ์บ์ฑ ์์ ์์") | |
pdf_files = get_pdf_files() | |
# ์ด๋ฏธ ์บ์๋ PDF ํ์ผ ๋ก๋ | |
for cache_file in CACHE_DIR.glob("*_cache.json"): | |
try: | |
pdf_name = cache_file.stem.replace("_cache", "") | |
with open(cache_file, "r") as f: | |
pdf_cache[pdf_name] = json.load(f) | |
pdf_cache[pdf_name]["status"] = "completed" | |
logger.info(f"๊ธฐ์กด ์บ์ ๋ก๋: {pdf_name}") | |
except Exception as e: | |
logger.error(f"์บ์ ํ์ผ ๋ก๋ ์ค๋ฅ: {str(e)}") | |
# ์บ์ฑ๋์ง ์์ PDF ํ์ผ ์ฒ๋ฆฌ | |
for pdf_file in pdf_files: | |
pdf_name = pdf_file.stem | |
if pdf_name not in pdf_cache or pdf_cache[pdf_name].get("status") != "completed": | |
try: | |
await cache_pdf(str(pdf_file)) | |
except Exception as e: | |
logger.error(f"PDF {pdf_name} ์บ์ฑ ์ค๋ฅ: {str(e)}") | |
# ๋ฐฑ๊ทธ๋ผ์ด๋ ์์ ์์ ํจ์ | |
async def startup_event(): | |
# ๋ฐฑ๊ทธ๋ผ์ด๋ ํ์คํฌ๋ก ์บ์ฑ ์คํ | |
asyncio.create_task(init_cache_all_pdfs()) | |
# API ์๋ํฌ์ธํธ: PDF ํ๋ก์ ํธ ๋ชฉ๋ก | |
async def get_pdf_projects_api(): | |
return generate_pdf_projects() | |
# API ์๋ํฌ์ธํธ: PDF ์ธ๋ค์ผ ์ ๊ณต | |
async def get_pdf_thumbnail(path: str): | |
try: | |
pdf_file = pathlib.Path(path) | |
pdf_name = pdf_file.stem | |
# ์บ์์์ ์ธ๋ค์ผ ๊ฐ์ ธ์ค๊ธฐ | |
if pdf_name in pdf_cache and pdf_cache[pdf_name].get("status") == "completed": | |
if pdf_cache[pdf_name]["pages"] and pdf_cache[pdf_name]["pages"][0].get("thumb"): | |
return {"thumbnail": pdf_cache[pdf_name]["pages"][0]["thumb"]} | |
# ์บ์์ ์์ผ๋ฉด ์์ฑ | |
import fitz | |
doc = fitz.open(path) | |
if doc.page_count > 0: | |
page = doc[0] | |
pix = page.get_pixmap(matrix=fitz.Matrix(0.5, 0.5)) | |
img_data = pix.tobytes("png") | |
b64_img = base64.b64encode(img_data).decode('utf-8') | |
# ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์บ์ฑ ์์ | |
asyncio.create_task(cache_pdf(path)) | |
return {"thumbnail": f"data:image/png;base64,{b64_img}"} | |
return {"thumbnail": None} | |
except Exception as e: | |
logger.error(f"์ธ๋ค์ผ ์์ฑ ์ค๋ฅ: {str(e)}") | |
return {"error": str(e), "thumbnail": None} | |
# API ์๋ํฌ์ธํธ: ์บ์ ์ํ ํ์ธ | |
async def get_cache_status(path: str = None): | |
if path: | |
pdf_file = pathlib.Path(path) | |
pdf_name = pdf_file.stem | |
if pdf_name in pdf_cache: | |
return pdf_cache[pdf_name] | |
return {"status": "not_cached"} | |
else: | |
return {name: {"status": info["status"], "progress": info.get("progress", 0)} | |
for name, info in pdf_cache.items()} | |
# API ์๋ํฌ์ธํธ: ์บ์๋ PDF ์ฝํ ์ธ ์ ๊ณต | |
async def get_cached_pdf(path: str, background_tasks: BackgroundTasks): | |
try: | |
pdf_file = pathlib.Path(path) | |
pdf_name = pdf_file.stem | |
# ์บ์ ํ์ธ | |
if pdf_name in pdf_cache and pdf_cache[pdf_name].get("status") == "completed": | |
return pdf_cache[pdf_name] | |
# ์บ์๊ฐ ์งํ์ค์ธ ๊ฒฝ์ฐ | |
if pdf_name in pdf_cache and pdf_cache[pdf_name].get("status") == "processing": | |
return {"status": "processing", "progress": pdf_cache[pdf_name].get("progress", 0)} | |
# ์บ์๊ฐ ์๋ ๊ฒฝ์ฐ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์บ์ฑ ์์ | |
background_tasks.add_task(cache_pdf, path) | |
return {"status": "started", "progress": 0} | |
except Exception as e: | |
logger.error(f"์บ์๋ PDF ์ ๊ณต ์ค๋ฅ: {str(e)}") | |
return {"error": str(e), "status": "error"} | |
# API ์๋ํฌ์ธํธ: PDF ์๋ณธ ์ฝํ ์ธ ์ ๊ณต(์บ์๊ฐ ์๋ ๊ฒฝ์ฐ) | |
async def get_pdf_content(path: str, background_tasks: BackgroundTasks): | |
try: | |
# ์บ์ฑ ์ํ ํ์ธ | |
pdf_file = pathlib.Path(path) | |
if not pdf_file.exists(): | |
return JSONResponse(content={"error": f"ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค: {path}"}, status_code=404) | |
pdf_name = pdf_file.stem | |
# ์บ์๋ ๊ฒฝ์ฐ ๋ฆฌ๋ค์ด๋ ํธ | |
if pdf_name in pdf_cache and pdf_cache[pdf_name].get("status") == "completed": | |
return JSONResponse(content={"redirect": f"/api/cached-pdf?path={path}"}) | |
# ํ์ผ ์ฝ๊ธฐ | |
with open(path, "rb") as pdf_file: | |
content = pdf_file.read() | |
# ํ์ผ๋ช ์ฒ๋ฆฌ | |
import urllib.parse | |
filename = pdf_file.name | |
encoded_filename = urllib.parse.quote(filename) | |
# ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์บ์ฑ ์์ | |
background_tasks.add_task(cache_pdf, path) | |
# ์๋ต ํค๋ ์ค์ | |
headers = { | |
"Content-Type": "application/pdf", | |
"Content-Disposition": f"inline; filename=\"{encoded_filename}\"; filename*=UTF-8''{encoded_filename}" | |
} | |
return Response(content=content, media_type="application/pdf", headers=headers) | |
except Exception as e: | |
import traceback | |
error_details = traceback.format_exc() | |
logger.error(f"PDF ์ฝํ ์ธ ๋ก๋ ์ค๋ฅ: {str(e)}\n{error_details}") | |
return JSONResponse(content={"error": str(e)}, status_code=500) | |
# HTML ํ์ผ ์ฝ๊ธฐ ํจ์ | |
def get_html_content(): | |
html_path = BASE / "flipbook_template.html" | |
if html_path.exists(): | |
with open(html_path, "r", encoding="utf-8") as f: | |
return f.read() | |
return HTML # ๊ธฐ๋ณธ HTML ์ฌ์ฉ | |
# HTML ๋ฌธ์์ด (์ด์ ์ ์ ๋ฐ์ดํธํ HTML ๋ด์ฉ) | |
HTML = """ | |
<!doctype html> | |
<html lang="ko"> | |
<head> | |
<meta charset="utf-8"> | |
<title>FlipBook Space</title> | |
<link rel="stylesheet" href="/static/flipbook.css"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
<script src="/static/three.js"></script> | |
<script src="/static/iscroll.js"></script> | |
<script src="/static/mark.js"></script> | |
<script src="/static/mod3d.js"></script> | |
<script src="/static/pdf.js"></script> | |
<script src="/static/flipbook.js"></script> | |
<script src="/static/flipbook.book3.js"></script> | |
<script src="/static/flipbook.scroll.js"></script> | |
<script src="/static/flipbook.swipe.js"></script> | |
<script src="/static/flipbook.webgl.js"></script> | |
<style> | |
/* ์ ์ฒด ์ฌ์ดํธ ํ์คํ ํค ํ ๋ง */ | |
:root { | |
--primary-color: #a5d8ff; /* ํ์คํ ๋ธ๋ฃจ */ | |
--secondary-color: #ffd6e0; /* ํ์คํ ํํฌ */ | |
--tertiary-color: #c3fae8; /* ํ์คํ ๋ฏผํธ */ | |
--accent-color: #d0bfff; /* ํ์คํ ํผํ */ | |
--bg-color: #f8f9fa; /* ๋ฐ์ ๋ฐฐ๊ฒฝ */ | |
--text-color: #495057; /* ๋ถ๋๋ฌ์ด ์ด๋์ด ์ */ | |
--card-bg: #ffffff; /* ์นด๋ ๋ฐฐ๊ฒฝ์ */ | |
--shadow-sm: 0 2px 8px rgba(0,0,0,0.05); | |
--shadow-md: 0 4px 12px rgba(0,0,0,0.08); | |
--shadow-lg: 0 8px 24px rgba(0,0,0,0.12); | |
--radius-sm: 8px; | |
--radius-md: 12px; | |
--radius-lg: 16px; | |
--transition: all 0.3s ease; | |
} | |
body { | |
margin: 0; | |
background: var(--bg-color); | |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
color: var(--text-color); | |
background-image: linear-gradient(120deg, var(--tertiary-color) 0%, var(--bg-color) 100%); | |
background-attachment: fixed; | |
} | |
header { | |
max-width: 1200px; | |
margin: 0 auto; | |
padding: 24px 30px; | |
display: flex; | |
align-items: center; | |
background: rgba(255, 255, 255, 0.8); | |
backdrop-filter: blur(8px); | |
border-radius: 0 0 var(--radius-md) var(--radius-md); | |
box-shadow: var(--shadow-sm); | |
position: relative; | |
z-index: 10; | |
} | |
#homeBtn { | |
display: none; | |
width: 48px; | |
height: 48px; | |
border: none; | |
border-radius: 50%; | |
cursor: pointer; | |
background: var(--primary-color); | |
color: white; | |
font-size: 22px; | |
margin-right: 16px; | |
box-shadow: var(--shadow-sm); | |
transition: var(--transition); | |
} | |
#homeBtn:hover { | |
background: #8bc5f8; | |
transform: scale(1.05); | |
box-shadow: var(--shadow-md); | |
} | |
h2 { | |
margin: 0; | |
font-size: 1.75rem; | |
font-weight: 600; | |
background: linear-gradient(120deg, #667eea 0%, #764ba2 100%); | |
-webkit-background-clip: text; | |
background-clip: text; | |
color: transparent; | |
letter-spacing: 0.5px; | |
} | |
#home, #viewerPage { | |
max-width: 1200px; | |
margin: 0 auto; | |
padding: 24px 30px 60px; | |
position: relative; | |
} | |
/* ์ ๋ก๋ ๋ฒํผ ์คํ์ผ */ | |
.upload-container { | |
display: flex; | |
margin-bottom: 30px; | |
justify-content: center; | |
} | |
button.upload { | |
all: unset; | |
cursor: pointer; | |
padding: 12px 20px; | |
border-radius: var(--radius-md); | |
background: white; | |
margin: 0 10px; | |
font-weight: 500; | |
display: flex; | |
align-items: center; | |
box-shadow: var(--shadow-sm); | |
transition: var(--transition); | |
position: relative; | |
overflow: hidden; | |
} | |
button.upload::before { | |
content: ''; | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
background: linear-gradient(120deg, var(--primary-color) 0%, var(--secondary-color) 100%); | |
opacity: 0.08; | |
z-index: -1; | |
} | |
button.upload:hover { | |
transform: translateY(-3px); | |
box-shadow: var(--shadow-md); | |
} | |
button.upload:hover::before { | |
opacity: 0.15; | |
} | |
button.upload i { | |
margin-right: 8px; | |
font-size: 20px; | |
} | |
/* ๊ทธ๋ฆฌ๋ ๋ฐ ์นด๋ ์คํ์ผ */ | |
.grid { | |
display: grid; | |
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); | |
gap: 24px; | |
margin-top: 36px; | |
} | |
.card { | |
background: var(--card-bg); | |
border-radius: var(--radius-md); | |
cursor: pointer; | |
box-shadow: var(--shadow-sm); | |
width: 100%; | |
height: 280px; | |
position: relative; | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
justify-content: center; | |
transition: var(--transition); | |
overflow: hidden; | |
} | |
.card::before { | |
content: ''; | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
background: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-color) 100%); | |
opacity: 0.06; | |
z-index: 1; | |
} | |
.card::after { | |
content: ''; | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 30%; | |
background: linear-gradient(to bottom, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0) 100%); | |
z-index: 2; | |
} | |
.card img { | |
width: 65%; | |
height: auto; | |
object-fit: contain; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -65%); | |
border: 1px solid rgba(0,0,0,0.05); | |
box-shadow: 0 4px 15px rgba(0,0,0,0.08); | |
z-index: 3; | |
transition: var(--transition); | |
} | |
.card:hover { | |
transform: translateY(-5px); | |
box-shadow: var(--shadow-md); | |
} | |
.card:hover img { | |
transform: translate(-50%, -65%) scale(1.03); | |
box-shadow: 0 8px 20px rgba(0,0,0,0.12); | |
} | |
.card p { | |
position: absolute; | |
bottom: 20px; | |
left: 50%; | |
transform: translateX(-50%); | |
background: rgba(255, 255, 255, 0.9); | |
padding: 8px 16px; | |
border-radius: 30px; | |
box-shadow: 0 2px 10px rgba(0,0,0,0.05); | |
width: 80%; | |
text-align: center; | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
font-size: 14px; | |
font-weight: 500; | |
color: var(--text-color); | |
z-index: 4; | |
transition: var(--transition); | |
} | |
.card:hover p { | |
background: rgba(255, 255, 255, 0.95); | |
box-shadow: 0 4px 12px rgba(0,0,0,0.08); | |
} | |
/* ์บ์ ์ํ ๋ฑ์ง */ | |
.cached-status { | |
position: absolute; | |
top: 10px; | |
right: 10px; | |
background: var(--accent-color); | |
color: white; | |
font-size: 11px; | |
padding: 3px 8px; | |
border-radius: 12px; | |
z-index: 5; | |
box-shadow: var(--shadow-sm); | |
} | |
/* ๋ทฐ์ด ์คํ์ผ */ | |
#viewer { | |
width: 90%; | |
height: 90vh; | |
max-width: 90%; | |
margin: 0; | |
background: var(--card-bg); | |
border: none; | |
border-radius: var(--radius-lg); | |
position: fixed; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
z-index: 1000; | |
box-shadow: var(--shadow-lg); | |
max-height: calc(90vh - 40px); | |
aspect-ratio: auto; | |
object-fit: contain; | |
overflow: hidden; | |
} | |
/* FlipBook ์ปจํธ๋กค๋ฐ ์คํ์ผ */ | |
.flipbook-container .fb3d-menu-bar { | |
z-index: 2000 !important; | |
opacity: 1 !important; | |
bottom: 0 !important; | |
background-color: rgba(255,255,255,0.9) !important; | |
backdrop-filter: blur(10px) !important; | |
border-radius: 0 0 var(--radius-lg) var(--radius-lg) !important; | |
padding: 12px 0 !important; | |
box-shadow: 0 -4px 20px rgba(0,0,0,0.1) !important; | |
} | |
.flipbook-container .fb3d-menu-bar > ul > li > img, | |
.flipbook-container .fb3d-menu-bar > ul > li > div { | |
opacity: 1 !important; | |
transform: scale(1.2) !important; | |
filter: drop-shadow(0 2px 3px rgba(0,0,0,0.1)) !important; | |
} | |
.flipbook-container .fb3d-menu-bar > ul > li { | |
margin: 0 12px !important; | |
} | |
/* ๋ฉ๋ด ํดํ ์คํ์ผ */ | |
.flipbook-container .fb3d-menu-bar > ul > li > span { | |
background-color: rgba(0,0,0,0.7) !important; | |
color: white !important; | |
border-radius: var(--radius-sm) !important; | |
padding: 8px 12px !important; | |
font-size: 13px !important; | |
bottom: 55px !important; | |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important; | |
letter-spacing: 0.3px !important; | |
} | |
/* ๋ทฐ์ด ๋ชจ๋์ผ ๋ ๋ฐฐ๊ฒฝ ์ค๋ฒ๋ ์ด */ | |
.viewer-mode { | |
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%) !important; | |
} | |
/* ๋ทฐ์ด ํ์ด์ง ๋ฐฐ๊ฒฝ */ | |
#viewerPage { | |
background: transparent; | |
} | |
/* ๋ก๋ฉ ์ ๋๋ฉ์ด์ */ | |
@keyframes spin { | |
0% { transform: rotate(0deg); } | |
100% { transform: rotate(360deg); } | |
} | |
.loading-spinner { | |
border: 4px solid rgba(255,255,255,0.3); | |
border-top: 4px solid var(--primary-color); | |
border-radius: 50%; | |
width: 50px; | |
height: 50px; | |
margin: 0 auto; | |
animation: spin 1.5s ease-in-out infinite; | |
} | |
.loading-container { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
text-align: center; | |
background: rgba(255, 255, 255, 0.85); | |
backdrop-filter: blur(10px); | |
padding: 30px; | |
border-radius: var(--radius-md); | |
box-shadow: var(--shadow-md); | |
z-index: 9999; | |
} | |
.loading-text { | |
margin-top: 20px; | |
font-size: 16px; | |
color: var(--text-color); | |
font-weight: 500; | |
} | |
/* ํ์ด์ง ์ ํ ์ ๋๋ฉ์ด์ */ | |
@keyframes fadeIn { | |
from { opacity: 0; } | |
to { opacity: 1; } | |
} | |
.fade-in { | |
animation: fadeIn 0.5s ease-out; | |
} | |
/* ์ถ๊ฐ ์คํ์ผ */ | |
.section-title { | |
font-size: 1.3rem; | |
font-weight: 600; | |
margin: 30px 0 15px; | |
color: var(--text-color); | |
} | |
.no-projects { | |
text-align: center; | |
margin: 40px 0; | |
color: var(--text-color); | |
font-size: 16px; | |
} | |
/* ํ๋ก๊ทธ๋ ์ค ๋ฐ */ | |
.progress-bar-container { | |
width: 100%; | |
height: 6px; | |
background-color: rgba(0,0,0,0.1); | |
border-radius: 3px; | |
margin-top: 15px; | |
overflow: hidden; | |
} | |
.progress-bar { | |
height: 100%; | |
background: linear-gradient(to right, var(--primary-color), var(--accent-color)); | |
border-radius: 3px; | |
transition: width 0.3s ease; | |
} | |
/* ๋ฐ์ํ ๋์์ธ */ | |
@media (max-width: 768px) { | |
.grid { | |
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); | |
gap: 16px; | |
} | |
.card { | |
height: 240px; | |
} | |
header { | |
padding: 20px; | |
} | |
h2 { | |
font-size: 1.5rem; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<button id="homeBtn" title="ํ์ผ๋ก"><i class="fas fa-home"></i></button> | |
<h2>My FlipBook Library</h2> | |
</header> | |
<section id="home" class="fade-in"> | |
<div class="upload-container"> | |
<button class="upload"> | |
<i class="fas fa-images"></i> ์ด๋ฏธ์ง ์ถ๊ฐ | |
<input id="imgInput" type="file" accept="image/*" multiple hidden> | |
</button> | |
<button class="upload"> | |
<i class="fas fa-file-pdf"></i> PDF ์ถ๊ฐ | |
<input id="pdfInput" type="file" accept="application/pdf" hidden> | |
</button> | |
</div> | |
<div class="section-title">๋ด ํ๋ก์ ํธ</div> | |
<div class="grid" id="grid"> | |
<!-- ์นด๋๊ฐ ์ฌ๊ธฐ์ ๋์ ์ผ๋ก ์ถ๊ฐ๋ฉ๋๋ค --> | |
</div> | |
<div id="noProjects" class="no-projects" style="display: none;"> | |
ํ๋ก์ ํธ๊ฐ ์์ต๋๋ค. ์ด๋ฏธ์ง๋ PDF๋ฅผ ์ถ๊ฐํ์ฌ ์์ํ์ธ์. | |
</div> | |
</section> | |
<section id="viewerPage" style="display:none"> | |
<div id="viewer"></div> | |
</section> | |
<script> | |
let projects=[], fb=null; | |
const grid=$id('grid'), viewer=$id('viewer'); | |
pdfjsLib.GlobalWorkerOptions.workerSrc='/static/pdf.worker.js'; | |
// ์๋ฒ์์ ๋ฏธ๋ฆฌ ๋ก๋๋ PDF ํ๋ก์ ํธ | |
let serverProjects = []; | |
/* ๐ ์ค๋์ค unlock โ ๋ด์ฅ Audio ์ ๊ฐ์ MP3 ๊ฒฝ๋ก ์ฌ์ฉ */ | |
['click','touchstart'].forEach(evt=>{ | |
document.addEventListener(evt,function u(){new Audio('static/turnPage2.mp3') | |
.play().then(a=>a.pause()).catch(()=>{});document.removeEventListener(evt,u,{capture:true});}, | |
{once:true,capture:true}); | |
}); | |
/* โโ ์ ํธ โโ */ | |
function $id(id){return document.getElementById(id)} | |
function addCard(i, thumb, title, isCached = false) { | |
const d = document.createElement('div'); | |
d.className = 'card fade-in'; | |
d.onclick = () => open(i); | |
// ์ ๋ชฉ ์ฒ๋ฆฌ | |
const displayTitle = title ? | |
(title.length > 15 ? title.substring(0, 15) + '...' : title) : | |
'ํ๋ก์ ํธ ' + (i+1); | |
// ์บ์ ์ํ ๋ฑ์ง ์ถ๊ฐ | |
const cachedBadge = isCached ? | |
'<div class="cached-status">์บ์๋จ</div>' : ''; | |
d.innerHTML = ` | |
<div class="card-inner"> | |
${cachedBadge} | |
<img src="${thumb}" alt="${displayTitle}"> | |
<p title="${title || 'ํ๋ก์ ํธ ' + (i+1)}">${displayTitle}</p> | |
</div> | |
`; | |
grid.appendChild(d); | |
// ํ๋ก์ ํธ๊ฐ ์์ผ๋ฉด 'ํ๋ก์ ํธ ์์' ๋ฉ์์ง ์จ๊ธฐ๊ธฐ | |
$id('noProjects').style.display = 'none'; | |
} | |
/* โโ ์ด๋ฏธ์ง ์ ๋ก๋ โโ */ | |
$id('imgInput').onchange=e=>{ | |
const files=[...e.target.files]; if(!files.length) return; | |
// ๋ก๋ฉ ํ์ ์ถ๊ฐ | |
showLoading("์ด๋ฏธ์ง ๋ก๋ฉ ์ค..."); | |
const pages=[],tot=files.length;let done=0; | |
files.forEach((f,i)=>{const r=new FileReader();r.onload=x=>{pages[i]={src:x.target.result,thumb:x.target.result}; | |
if(++done===tot) { | |
save(pages, '์ด๋ฏธ์ง ์ปฌ๋ ์ '); | |
hideLoading(); | |
} | |
};r.readAsDataURL(f);}); | |
}; | |
/* โโ PDF ์ ๋ก๋ โโ */ | |
$id('pdfInput').onchange=e=>{ | |
const file=e.target.files[0]; if(!file) return; | |
// ๋ก๋ฉ ํ์ ์ถ๊ฐ | |
showLoading("PDF ๋ก๋ฉ ์ค..."); | |
const fr=new FileReader(); | |
fr.onload=v=>{ | |
pdfjsLib.getDocument({data:v.target.result}).promise.then(async pdf=>{ | |
const pages=[]; | |
for(let p=1;p<=pdf.numPages;p++){ | |
// ๋ก๋ฉ ์ํ ์ ๋ฐ์ดํธ | |
updateLoading(`PDF ํ์ด์ง ๋ก๋ฉ ์ค... (${p}/${pdf.numPages})`); | |
const pg=await pdf.getPage(p), vp=pg.getViewport({scale:1}); | |
const c=document.createElement('canvas');c.width=vp.width;c.height=vp.height; | |
await pg.render({canvasContext:c.getContext('2d'),viewport:vp}).promise; | |
pages.push({src:c.toDataURL(),thumb:c.toDataURL()}); | |
} | |
hideLoading(); | |
save(pages, file.name.replace('.pdf', '')); | |
}).catch(error => { | |
console.error("PDF ๋ก๋ฉ ์ค๋ฅ:", error); | |
hideLoading(); | |
showError("PDF ๋ก๋ฉ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."); | |
}); | |
};fr.readAsArrayBuffer(file); | |
}; | |
/* โโ ํ๋ก์ ํธ ์ ์ฅ โโ */ | |
function save(pages, title, isCached = false){ | |
const id=projects.push(pages)-1; | |
addCard(id, pages[0].thumb, title, isCached); | |
} | |
/* โโ ์๋ฒ PDF ๋ก๋ ๋ฐ ์บ์ ์ํ ํ์ธ โโ */ | |
async function loadServerPDFs() { | |
try { | |
// ๋ก๋ฉ ํ์ ์ถ๊ฐ | |
if (document.querySelectorAll('.card').length === 0) { | |
showLoading("๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ก๋ฉ ์ค..."); | |
} | |
// ๋จผ์ ์บ์ ์ํ ํ์ธ | |
const cacheStatusRes = await fetch('/api/cache-status'); | |
const cacheStatus = await cacheStatusRes.json(); | |
// PDF ํ๋ก์ ํธ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ | |
const response = await fetch('/api/pdf-projects'); | |
serverProjects = await response.json(); | |
if (serverProjects.length === 0) { | |
hideLoading(); | |
$id('noProjects').style.display = 'block'; | |
return; | |
} | |
// ์๋ฒ PDF ๋ก๋ ๋ฐ ์ธ๋ค์ผ ์์ฑ | |
for(let i = 0; i < serverProjects.length; i++) { | |
updateLoading(`PDF ํ๋ก์ ํธ ๋ก๋ฉ ์ค... (${i+1}/${serverProjects.length})`); | |
const project = serverProjects[i]; | |
const pdfName = project.name; | |
const isCached = cacheStatus[pdfName] && cacheStatus[pdfName].status === "completed"; | |
// ์ธ๋ค์ผ ๊ฐ์ ธ์ค๊ธฐ | |
const response = await fetch(`/api/pdf-thumbnail?path=${encodeURIComponent(project.path)}`); | |
const data = await response.json(); | |
if(data.thumbnail) { | |
const pages = [{ | |
src: data.thumbnail, | |
thumb: data.thumbnail, | |
path: project.path, | |
cached: isCached | |
}]; | |
save(pages, project.name, isCached); | |
} | |
} | |
hideLoading(); | |
// ํ๋ก์ ํธ๊ฐ ์์ ๊ฒฝ์ฐ ๋ฉ์์ง ํ์ | |
if (document.querySelectorAll('.card').length === 0) { | |
$id('noProjects').style.display = 'block'; | |
} | |
} catch(error) { | |
console.error('์๋ฒ PDF ๋ก๋ ์คํจ:', error); | |
hideLoading(); | |
showError("๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ก๋ฉ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."); | |
} | |
} | |
/* โโ ์บ์ ์ํ ์ ๊ธฐ์ ์ผ๋ก ํ์ธ โโ */ | |
async function checkCacheStatus() { | |
try { | |
const response = await fetch('/api/cache-status'); | |
const cacheStatus = await response.json(); | |
// ํ์ฌ ์นด๋ ์ํ ์ ๋ฐ์ดํธ | |
const cards = document.querySelectorAll('.card'); | |
for(let i = 0; i < cards.length; i++) { | |
if(projects[i] && projects[i][0] && projects[i][0].path) { | |
const pdfPath = projects[i][0].path; | |
const pdfName = pdfPath.split('/').pop().replace('.pdf', ''); | |
// ์บ์ ์ํ ๋ฑ์ง ์ ๋ฐ์ดํธ | |
let badgeEl = cards[i].querySelector('.cached-status'); | |
if(cacheStatus[pdfName] && cacheStatus[pdfName].status === "completed") { | |
if(!badgeEl) { | |
badgeEl = document.createElement('div'); | |
badgeEl.className = 'cached-status'; | |
badgeEl.textContent = '์บ์๋จ'; | |
cards[i].querySelector('.card-inner')?.appendChild(badgeEl); | |
} | |
projects[i][0].cached = true; | |
} else if(cacheStatus[pdfName] && cacheStatus[pdfName].status === "processing") { | |
if(!badgeEl) { | |
badgeEl = document.createElement('div'); | |
badgeEl.className = 'cached-status'; | |
cards[i].querySelector('.card-inner')?.appendChild(badgeEl); | |
} | |
badgeEl.textContent = `${cacheStatus[pdfName].progress}%`; | |
badgeEl.style.background = 'var(--secondary-color)'; | |
} | |
} | |
} | |
} catch(error) { | |
console.error('์บ์ ์ํ ํ์ธ ์ค๋ฅ:', error); | |
} | |
} | |
/* โโ ์นด๋ โ FlipBook โโ */ | |
async function open(i) { | |
toggle(false); | |
const pages = projects[i]; | |
// ๊ธฐ์กด FlipBook ์ ๋ฆฌ | |
if(fb) { | |
fb.destroy(); | |
viewer.innerHTML = ''; | |
} | |
// ์๋ฒ PDF ๋๋ ๋ก์ปฌ ํ๋ก์ ํธ ์ฒ๋ฆฌ | |
if(pages[0].path) { | |
const pdfPath = pages[0].path; | |
// ์บ์ ์ฌ๋ถ ํ์ธ | |
if(pages[0].cached) { | |
// ์บ์๋ PDF ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ | |
showLoading("์บ์๋ PDF ๋ก๋ฉ ์ค..."); | |
try { | |
const response = await fetch(`/api/cached-pdf?path=${encodeURIComponent(pdfPath)}`); | |
const cachedData = await response.json(); | |
if(cachedData.status === "completed" && cachedData.pages) { | |
hideLoading(); | |
createFlipBook(cachedData.pages); | |
return; | |
} | |
} catch(error) { | |
console.error("์บ์ ๋ฐ์ดํฐ ๋ก๋ ์ค๋ฅ:", error); | |
// ์บ์ ๋ก๋ฉ ์คํจ ์ ์๋ณธ PDF๋ก ๋์ฒด | |
} | |
} | |
// ์บ์๊ฐ ์๊ฑฐ๋ ๋ก๋ฉ ์คํจ ์ ์๋ฒ PDF ๋ก๋ | |
showLoading("PDF ์ค๋น ์ค..."); | |
try { | |
const response = await fetch(`/api/pdf-content?path=${encodeURIComponent(pdfPath)}`); | |
const data = await response.json(); | |
// ์บ์๋ก ๋ฆฌ๋ค์ด๋ ํธ๋ ๊ฒฝ์ฐ | |
if(data.redirect) { | |
const redirectRes = await fetch(data.redirect); | |
const cachedData = await redirectRes.json(); | |
if(cachedData.status === "completed" && cachedData.pages) { | |
hideLoading(); | |
createFlipBook(cachedData.pages); | |
return; | |
} else if(cachedData.status === "processing") { | |
// ์บ์ฑ ์งํ ์ค์ธ ๊ฒฝ์ฐ ์งํ๋ฅ ํ์ | |
updateLoading(`PDF ์บ์ฑ ์ค: ${cachedData.progress}%`, cachedData.progress); | |
// ์บ์ฑ ์๋ฃ ํ์ธ์ ์ํ ํด๋ง | |
await waitForCaching(pdfPath); | |
return; | |
} | |
} | |
// ์๋ณธ PDF ๋ก๋ (ArrayBuffer ํํ) | |
const pdfResponse = await fetch(`/api/pdf-content?path=${encodeURIComponent(pdfPath)}`); | |
const pdfData = await pdfResponse.arrayBuffer(); | |
// PDF ๋ก๋ ๋ฐ ํ์ด์ง ๋ ๋๋ง | |
const pdf = await pdfjsLib.getDocument({data: pdfData}).promise; | |
const pdfPages = []; | |
for(let p = 1; p <= pdf.numPages; p++) { | |
updateLoading(`ํ์ด์ง ์ค๋น ์ค... (${p}/${pdf.numPages})`); | |
const pg = await pdf.getPage(p); | |
const vp = pg.getViewport({scale: 1}); | |
const c = document.createElement('canvas'); | |
c.width = vp.width; | |
c.height = vp.height; | |
await pg.render({canvasContext: c.getContext('2d'), viewport: vp}).promise; | |
pdfPages.push({src: c.toDataURL(), thumb: c.toDataURL()}); | |
} | |
hideLoading(); | |
createFlipBook(pdfPages); | |
} catch(error) { | |
console.error('PDF ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:', error); | |
hideLoading(); | |
showError("PDF๋ฅผ ๋ก๋ํ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."); | |
} | |
} else { | |
// ๋ก์ปฌ ์ ๋ก๋๋ ํ๋ก์ ํธ ์คํ | |
createFlipBook(pages); | |
} | |
} | |
/* โโ ์บ์ฑ ์๋ฃ ๋๊ธฐ ํจ์ โโ */ | |
async function waitForCaching(pdfPath) { | |
let retries = 0; | |
const maxRetries = 100; // ์ต๋ ํ์ธ ํ์ | |
const checkInterval = setInterval(async () => { | |
try { | |
const response = await fetch(`/api/cache-status?path=${encodeURIComponent(pdfPath)}`); | |
const status = await response.json(); | |
if(status.status === "completed") { | |
// ์บ์ฑ ์๋ฃ | |
clearInterval(checkInterval); | |
hideLoading(); | |
// ์บ์๋ ๋ฐ์ดํฐ๋ก FlipBook ์์ฑ | |
const cachedRes = await fetch(`/api/cached-pdf?path=${encodeURIComponent(pdfPath)}`); | |
const cachedData = await cachedRes.json(); | |
createFlipBook(cachedData.pages); | |
} else if(status.status === "processing") { | |
// ์งํ ์ํ ์ ๋ฐ์ดํธ | |
updateLoading(`PDF ์บ์ฑ ์ค: ${status.progress}%`, status.progress); | |
} else if(status.status === "error" || retries >= maxRetries) { | |
// ์ค๋ฅ ๋๋ ์๊ฐ ์ด๊ณผ | |
clearInterval(checkInterval); | |
hideLoading(); | |
showError("PDF ์บ์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์."); | |
} | |
retries++; | |
} catch(e) { | |
console.error("์บ์ ์ํ ํ์ธ ์ค๋ฅ:", e); | |
retries++; | |
if(retries >= maxRetries) { | |
clearInterval(checkInterval); | |
hideLoading(); | |
showError("PDF ์บ์ฑ ์ํ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค."); | |
} | |
} | |
}, 1000); // 1์ด๋ง๋ค ํ์ธ | |
} | |
function createFlipBook(pages) { | |
console.log('FlipBook ์์ฑ ์์. ํ์ด์ง ์:', pages.length); | |
try { | |
// ํ๋ฉด ๋น์จ ๊ณ์ฐ | |
const calculateAspectRatio = () => { | |
const windowWidth = window.innerWidth; | |
const windowHeight = window.innerHeight; | |
const aspectRatio = windowWidth / windowHeight; | |
// ๋๋น ๋๋ ๋์ด ๊ธฐ์ค์ผ๋ก ์ต๋ 90% ์ ํ | |
let width, height; | |
if (aspectRatio > 1) { // ๊ฐ๋ก ํ๋ฉด | |
height = Math.min(windowHeight * 0.9, windowHeight - 40); | |
width = height * aspectRatio * 0.8; // ๊ฐ๋ก ํ๋ฉด์์๋ ์ฝ๊ฐ ์ค์ | |
if (width > windowWidth * 0.9) { | |
width = windowWidth * 0.9; | |
height = width / (aspectRatio * 0.8); | |
} | |
} else { // ์ธ๋ก ํ๋ฉด | |
width = Math.min(windowWidth * 0.9, windowWidth - 40); | |
height = width / aspectRatio * 0.9; // ์ธ๋ก ํ๋ฉด์์๋ ์ฝ๊ฐ ๋๋ฆผ | |
if (height > windowHeight * 0.9) { | |
height = windowHeight * 0.9; | |
width = height * aspectRatio * 0.9; | |
} | |
} | |
// ์ต์ ์ฌ์ด์ฆ ๋ฐํ | |
return { | |
width: Math.round(width), | |
height: Math.round(height) | |
}; | |
}; | |
// ์ด๊ธฐ ํ๋ฉด ๋น์จ ๊ณ์ฐ | |
const size = calculateAspectRatio(); | |
viewer.style.width = size.width + 'px'; | |
viewer.style.height = size.height + 'px'; | |
fb = new FlipBook(viewer, { | |
pages: pages, | |
viewMode: 'webgl', | |
autoSize: true, | |
flipDuration: 800, | |
backgroundColor: '#fff', | |
/* ๐ ๋ด์ฅ ์ฌ์ด๋ */ | |
sound: true, | |
assets: {flipMp3: 'static/turnPage2.mp3', hardFlipMp3: 'static/turnPage2.mp3'}, | |
controlsProps: { | |
enableFullscreen: true, | |
enableToc: true, | |
enableDownload: false, | |
enablePrint: false, | |
enableZoom: true, | |
enableShare: false, | |
enableSearch: true, | |
enableAutoPlay: true, | |
enableAnnotation: false, | |
enableSound: true, | |
enableLightbox: false, | |
layout: 10, // ๋ ์ด์์ ์ต์ | |
skin: 'light', // ์คํจ ์คํ์ผ | |
autoNavigationTime: 3600, // ์๋ ๋๊น ์๊ฐ(์ด) | |
hideControls: false, // ์ปจํธ๋กค ์จ๊น ๋นํ์ฑํ | |
paddingTop: 10, // ์๋จ ํจ๋ฉ | |
paddingLeft: 10, // ์ข์ธก ํจ๋ฉ | |
paddingRight: 10, // ์ฐ์ธก ํจ๋ฉ | |
paddingBottom: 10, // ํ๋จ ํจ๋ฉ | |
pageTextureSize: 1024, // ํ์ด์ง ํ ์ค์ฒ ํฌ๊ธฐ | |
thumbnails: true, // ์ฌ๋ค์ผ ํ์ฑํ | |
autoHideControls: false, // ์๋ ์จ๊น ๋นํ์ฑํ | |
controlsTimeout: 8000 // ์ปจํธ๋กค ํ์ ์๊ฐ ์ฐ์ฅ | |
} | |
}); | |
// ํ๋ฉด ํฌ๊ธฐ ๋ณ๊ฒฝ ์ FlipBook ํฌ๊ธฐ ์กฐ์ | |
window.addEventListener('resize', () => { | |
if (fb) { | |
const newSize = calculateAspectRatio(); | |
viewer.style.width = newSize.width + 'px'; | |
viewer.style.height = newSize.height + 'px'; | |
fb.resize(); | |
} | |
}); | |
// FlipBook ์์ฑ ํ ์ปจํธ๋กค๋ฐ ๊ฐ์ ํ์ | |
setTimeout(() => { | |
try { | |
// ์ปจํธ๋กค๋ฐ ๊ด๋ จ ์์ ์ฐพ๊ธฐ ๋ฐ ์คํ์ผ ์ ์ฉ | |
const menuBars = document.querySelectorAll('.flipbook-container .fb3d-menu-bar'); | |
if (menuBars && menuBars.length > 0) { | |
menuBars.forEach(menuBar => { | |
menuBar.style.display = 'block'; | |
menuBar.style.opacity = '1'; | |
menuBar.style.visibility = 'visible'; | |
menuBar.style.zIndex = '9999'; | |
}); | |
} | |
} catch (e) { | |
console.warn('์ปจํธ๋กค๋ฐ ์คํ์ผ ์ ์ฉ ์ค ์ค๋ฅ:', e); | |
} | |
}, 1000); | |
console.log('FlipBook ์์ฑ ์๋ฃ'); | |
} catch (error) { | |
console.error('FlipBook ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:', error); | |
showError("FlipBook์ ์์ฑํ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."); | |
} | |
} | |
/* โโ ๋ค๋น๊ฒ์ด์ โโ */ | |
$id('homeBtn').onclick=()=>{ | |
if(fb) { | |
fb.destroy(); | |
viewer.innerHTML = ''; | |
fb = null; | |
} | |
toggle(true); | |
}; | |
function toggle(showHome){ | |
$id('home').style.display=showHome?'block':'none'; | |
$id('viewerPage').style.display=showHome?'none':'block'; | |
$id('homeBtn').style.display=showHome?'none':'inline-block'; | |
// ๋ทฐ์ด ๋ชจ๋์ผ ๋ ์คํ์ผ ๋ณ๊ฒฝ | |
if(!showHome) { | |
document.body.classList.add('viewer-mode'); | |
$id('homeBtn').style.position = 'fixed'; | |
$id('homeBtn').style.top = '20px'; | |
$id('homeBtn').style.left = '20px'; | |
$id('homeBtn').style.zIndex = '9999'; | |
$id('homeBtn').style.fontSize = ''; | |
$id('homeBtn').style.width = '52px'; | |
$id('homeBtn').style.height = '52px'; | |
$id('homeBtn').style.boxShadow = '0 4px 15px rgba(0,0,0,0.15)'; | |
} else { | |
document.body.classList.remove('viewer-mode'); | |
$id('homeBtn').style.position = ''; | |
$id('homeBtn').style.top = ''; | |
$id('homeBtn').style.left = ''; | |
$id('homeBtn').style.zIndex = ''; | |
$id('homeBtn').style.fontSize = ''; | |
$id('homeBtn').style.width = ''; | |
$id('homeBtn').style.height = ''; | |
$id('homeBtn').style.boxShadow = ''; | |
} | |
} | |
/* -- ๋ก๋ฉ ๋ฐ ์ค๋ฅ ํ์ -- */ | |
function showLoading(message, progress = -1) { | |
// ๊ธฐ์กด ๋ก๋ฉ ์ปจํ ์ด๋๊ฐ ์๋ค๋ฉด ์ ๊ฑฐ | |
hideLoading(); | |
const loadingContainer = document.createElement('div'); | |
loadingContainer.className = 'loading-container fade-in'; | |
loadingContainer.id = 'loadingContainer'; | |
let progressBarHtml = ''; | |
if (progress >= 0) { | |
progressBarHtml = ` | |
<div class="progress-bar-container"> | |
<div id="progressBar" class="progress-bar" style="width: ${progress}%;"></div> | |
</div> | |
`; | |
} | |
loadingContainer.innerHTML = ` | |
<div class="loading-spinner"></div> | |
<p class="loading-text" id="loadingText">${message || '๋ก๋ฉ ์ค...'}</p> | |
${progressBarHtml} | |
`; | |
document.body.appendChild(loadingContainer); | |
} | |
function updateLoading(message, progress = -1) { | |
const loadingText = $id('loadingText'); | |
if (loadingText) { | |
loadingText.textContent = message; | |
} | |
if (progress >= 0) { | |
let progressBar = $id('progressBar'); | |
if (!progressBar) { | |
const loadingContainer = $id('loadingContainer'); | |
if (loadingContainer) { | |
const progressContainer = document.createElement('div'); | |
progressContainer.className = 'progress-bar-container'; | |
progressContainer.innerHTML = `<div id="progressBar" class="progress-bar" style="width: ${progress}%;"></div>`; | |
loadingContainer.appendChild(progressContainer); | |
progressBar = $id('progressBar'); | |
} | |
} else { | |
progressBar.style.width = `${progress}%`; | |
} | |
} | |
} | |
function hideLoading() { | |
const loadingContainer = $id('loadingContainer'); | |
if (loadingContainer) { | |
loadingContainer.remove(); | |
} | |
} | |
function showError(message) { | |
// ๊ธฐ์กด ์ค๋ฅ ๋ฉ์์ง๊ฐ ์๋ค๋ฉด ์ ๊ฑฐ | |
const existingError = $id('errorContainer'); | |
if (existingError) { | |
existingError.remove(); | |
} | |
const errorContainer = document.createElement('div'); | |
errorContainer.className = 'loading-container fade-in'; | |
errorContainer.id = 'errorContainer'; | |
errorContainer.innerHTML = ` | |
<p class="loading-text" style="color: #e74c3c;">${message}</p> | |
<button id="errorCloseBtn" style="margin-top: 15px; padding: 8px 16px; background: #3498db; color: white; border: none; border-radius: 4px; cursor: pointer;">ํ์ธ</button> | |
`; | |
document.body.appendChild(errorContainer); | |
// ํ์ธ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ | |
$id('errorCloseBtn').onclick = () => { | |
errorContainer.remove(); | |
}; | |
// 5์ด ํ ์๋์ผ๋ก ๋ซ๊ธฐ | |
setTimeout(() => { | |
if ($id('errorContainer')) { | |
$id('errorContainer').remove(); | |
} | |
}, 5000); | |
} | |
// ํ์ด์ง ๋ก๋ ์ ์๋ฒ PDF ๋ก๋ | |
window.addEventListener('DOMContentLoaded', () => { | |
loadServerPDFs(); | |
// ์บ์ ์ํ๋ฅผ ์ฃผ๊ธฐ์ ์ผ๋ก ํ์ธ (5์ด๋ง๋ค) | |
setInterval(checkCacheStatus, 5000); | |
}); | |
</script> | |
</body> | |
</html> | |
""" | |
async def root(): | |
return get_html_content() | |
if __name__ == "__main__": | |
uvicorn.run("app:app", host="0.0.0.0", port=int(os.getenv("PORT", 7860))) |