QNAP 이전: 등록 서버를 컨테이너로(8089, Caddy teamat-admin.lala.dedyn.io), 사진 원본 보관, 웹 루트 직접 배포, Gitea 자동 푸시

This commit is contained in:
한땀 작업실 committed 2026-11-01 03:52:58 +00:00
1 parent 5c5ecef578
commit 984fe68c12
7 files changed
+165 -19

No files matched your search

+36 -3
View File
@@ -11,6 +11,7 @@ studio/server.py 가 import 해서 쓴다. 표준 라이브러리 + macOS 기본
from __future__ import annotations
import base64
import io
import json
import os
import re
@@ -25,13 +26,21 @@ from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Tuple
try: # 리눅스(QNAP 컨테이너)에서는 Pillow, macOS 기본 파이썬에는 없음
from PIL import Image, ImageOps
HAS_PIL = True
except ImportError: # pragma: no cover - macOS 폴백
HAS_PIL = False
BASE = Path(__file__).resolve().parent
ROOT = BASE.parent
PRODUCTS = ROOT / "content" / "products"
ASSETS = ROOT / "assets"
INBOX = BASE / "_inbox"
ARCHIVE = Path(os.environ.get("TEAMAT_ARCHIVE") or (BASE / "_archive"))
CONFIG_DIR = Path.home() / ".config" / "teamat-studio"
CONFIG_DIR = Path(os.environ.get("TEAMAT_CONFIG_DIR") or (Path.home() / ".config" / "teamat-studio"))
AI_CONFIG = CONFIG_DIR / "ai.json"
VISION_CONFIG = CONFIG_DIR / "vision.json"
AI_BASE_URL = "https://api.deepseek.com/v1"
@@ -122,7 +131,14 @@ def vision_status() -> Dict[str, Any]:
def _shrink(path: Path, limit: int = 900) -> bytes:
"""VLM 에 보낼 용량 줄이기. sips 는 macOS 기본 도구."""
"""VLM 에 보낼 용량 줄이기. Pillow(리눅스) 또는 sips(macOS)."""
if HAS_PIL:
with Image.open(path) as image:
image = ImageOps.exif_transpose(image).convert("RGB")
image.thumbnail((limit, limit), Image.LANCZOS)
buffer = io.BytesIO()
image.save(buffer, format="JPEG", quality=75, optimize=True)
return buffer.getvalue()
tmp = INBOX / (path.stem + f"-v{limit}.jpg")
ok = subprocess.run(["sips", "-Z", str(limit), "-s", "format", "jpeg",
"-s", "formatOptions", "75", str(path), "--out", str(tmp)],
@@ -314,6 +330,12 @@ def _orient(path: Path) -> None:
def _to_jpeg(source: Path, target: Path, limit: int = 1400) -> None:
if HAS_PIL:
with Image.open(source) as image:
image = ImageOps.exif_transpose(image).convert("RGB")
image.thumbnail((limit, limit), Image.LANCZOS)
image.save(target, format="JPEG", quality=82, optimize=True, progressive=True)
return
ok = subprocess.run(["sips", "-Z", str(limit), "-s", "format", "jpeg",
"-s", "formatOptions", "80", str(source), "--out", str(target)],
capture_output=True, timeout=120).returncode == 0
@@ -371,6 +393,13 @@ def publish(payload: Dict[str, Any], helpers: Dict[str, Any]) -> Dict[str, Any]:
_to_jpeg(source, image_dir / name)
gallery.append(f"assets/img/{slug}/{name}")
# 원본(찍은 그대로)은 저장소 밖 보관함에 남긴다 — 나중에 다시 자르거나 크게 볼 때 쓴다.
if ARCHIVE:
keep = ARCHIVE / slug
keep.mkdir(parents=True, exist_ok=True)
for index, source in enumerate(sources):
shutil.copyfile(source, keep / ("cover.jpg" if index == 0 else f"photo-{index:02d}.jpg"))
data: Dict[str, Any] = {
"slug": slug,
"title": title,
@@ -421,6 +450,10 @@ def publish(payload: Dict[str, Any], helpers: Dict[str, Any]) -> Dict[str, Any]:
drafts = _other_drafts(slug)
push_ok, push_log = True, ""
if os.environ.get("TEAMAT_PUSH", "").strip().lower() in ("1", "true", "yes") and helpers.get("push"):
push_ok, push_log = helpers["push"]()
deploy_ok, deploy_log = (True, "배포하지 않음")
if payload.get("deploy"):
if drafts and not payload.get("force_deploy"):
@@ -432,6 +465,6 @@ def publish(payload: Dict[str, Any], helpers: Dict[str, Any]) -> Dict[str, Any]:
return {"ok": True, "slug": slug, "title": title, "commit": commit_log,
"deployed": bool(payload.get("deploy")) and deploy_ok,
"other_drafts": drafts,
"other_drafts": drafts, "pushed": push_ok, "push_log": push_log[-200:],
"build_log": log, "deploy_log": deploy_log[-400:],
"url": f"/p/{slug}.html"}