Skip to content

Commit 9d99060

Browse files
committed
fix: logo display.
1 parent 38bbbdd commit 9d99060

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

backend/app/database.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -883,17 +883,44 @@ async def rebuild_all_backlinks(db):
883883

884884
async def seed_welcome_page(db):
885885
"""Create a welcome/guide page on first launch when no pages exist."""
886+
# Ensure logo.png exists in media directory (independent of whether pages exist)
887+
import shutil
888+
import os
889+
890+
# 1. Determine base directories
891+
# In Docker: /app/app/database.py -> app_dir is /app
892+
# In Local: backend/app/database.py -> app_dir is .../backend
893+
app_dir = Path(__file__).resolve().parent.parent
894+
project_root = app_dir.parent if app_dir.name == "backend" else app_dir
895+
896+
# 2. Try multiple possible source locations for the logo
897+
possible_sources = [
898+
app_dir / "docs" / "images" / "logo.png",
899+
project_root / "docs" / "images" / "logo.png",
900+
Path("/app/docs/images/logo.png"),
901+
Path("/app/backend/docs/images/logo.png"),
902+
]
903+
904+
logo_src = next((s for s in possible_sources if s.exists()), None)
905+
906+
# 3. Destination (Ensure absolute path)
907+
media_dir = Path(settings.MEDIA_DIR).resolve()
908+
media_dir.mkdir(parents=True, exist_ok=True)
909+
logo_dst = media_dir / "logo.png"
910+
911+
if logo_src and not logo_dst.exists():
912+
try:
913+
shutil.copy2(logo_src, logo_dst)
914+
# Make sure it's readable
915+
os.chmod(logo_dst, 0o644)
916+
print(f"Successfully seeded logo from {logo_src} to {logo_dst}")
917+
except Exception as e:
918+
print(f"Error seeding logo: {e}")
919+
886920
rows = await db.execute_fetchall("SELECT COUNT(*) as cnt FROM pages")
887921
if rows[0]["cnt"] > 0:
888922
return # Pages already exist
889923

890-
# Copy logo to media directory
891-
import shutil
892-
logo_src = Path(__file__).resolve().parent.parent.parent / "docs" / "images" / "logo.png"
893-
logo_dst = Path(settings.MEDIA_DIR) / "logo.png"
894-
if logo_src.exists() and not logo_dst.exists():
895-
shutil.copy2(logo_src, logo_dst)
896-
897924
# Get admin user id for created_by
898925
admin_rows = await db.execute_fetchall(
899926
"SELECT id FROM users WHERE role = 'admin' LIMIT 1"

0 commit comments

Comments
 (0)