From 6e15868e04b2d20a70d837bfc16a9a3abc66c796 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 1 Nov 2026 11:24:21 +0800 Subject: [PATCH] =?UTF-8?q?Add=20isolated=20=E6=B8=B8=E6=B0=91=E7=A4=BE?= =?UTF-8?q?=E5=8C=BA=20(/social)=20with=20social=5Fsvc=20and=20document=20?= =?UTF-8?q?test5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ship portal module + /api/social/v1 SQLite backend separate from /community; update README for MiroTalk CSP and test5 as the next development branch. Co-authored-by: Cursor --- README.md | 28 +- apps/api/app/main.py | 29 +- apps/api/services/community_svc/config.py | 8 +- apps/api/services/social_svc/__init__.py | 1 + apps/api/services/social_svc/config.py | 11 + .../services/social_svc/routers/__init__.py | 3 + apps/api/services/social_svc/routers/api.py | 139 +++ apps/api/services/social_svc/store.py | 330 +++++++ data/remote-config.json | 6 + data/social/.gitkeep | 0 deploy/social/README.md | 53 + next.config.ts | 6 + src/app/admin/verticals/page.tsx | 6 + src/app/hub.css | 9 +- src/app/layout.tsx | 2 +- src/app/social/chat/[id]/page.tsx | 8 + src/app/social/chat/page.tsx | 5 + src/app/social/coffeechat/page.tsx | 5 + src/app/social/date/page.tsx | 5 + src/app/social/ebook/page.tsx | 5 + src/app/social/feedback/page.tsx | 5 + src/app/social/gigs/page.tsx | 5 + src/app/social/join/page.tsx | 5 + src/app/social/layout.tsx | 21 + src/app/social/meetup/[id]/page.tsx | 8 + src/app/social/meetup/page.tsx | 5 + src/app/social/page.tsx | 5 + src/app/social/roster/page.tsx | 5 + src/app/social/videos/page.tsx | 5 + src/app/social/vip/page.tsx | 5 + src/components/sections/hero.tsx | 9 + src/lib/remote-config.ts | 8 + src/modules/social/README.md | 21 + src/modules/social/app/globals.css | 915 ++++++++++++++++++ .../social/components/ChatListClient.tsx | 33 + .../social/components/ChatRoomClient.tsx | 153 +++ .../social/components/CoffeechatClient.tsx | 190 ++++ src/modules/social/components/DateClient.tsx | 39 + src/modules/social/components/EbookClient.tsx | 38 + .../social/components/FeedbackClient.tsx | 85 ++ src/modules/social/components/GigsClient.tsx | 107 ++ src/modules/social/components/HomeClient.tsx | 361 +++++++ src/modules/social/components/JoinClient.tsx | 54 ++ .../social/components/MeetupClient.tsx | 43 + .../social/components/MeetupLiveClient.tsx | 236 +++++ .../social/components/ParticleCanvas.tsx | 121 +++ .../social/components/RosterClient.tsx | 150 +++ src/modules/social/components/SiteShell.tsx | 153 +++ .../social/components/VideosClient.tsx | 44 + src/modules/social/components/VipClient.tsx | 65 ++ src/modules/social/lib/api.ts | 85 ++ src/modules/social/lib/catalog.ts | 143 +++ src/modules/social/lib/seed.ts | 183 ++++ src/modules/social/lib/socialPath.ts | 21 + src/modules/social/lib/storage.ts | 27 + src/modules/social/lib/types.ts | 85 ++ tsconfig.json | 1 + 57 files changed, 4084 insertions(+), 14 deletions(-) create mode 100644 apps/api/services/social_svc/__init__.py create mode 100644 apps/api/services/social_svc/config.py create mode 100644 apps/api/services/social_svc/routers/__init__.py create mode 100644 apps/api/services/social_svc/routers/api.py create mode 100644 apps/api/services/social_svc/store.py create mode 100644 data/social/.gitkeep create mode 100644 deploy/social/README.md create mode 100644 src/app/social/chat/[id]/page.tsx create mode 100644 src/app/social/chat/page.tsx create mode 100644 src/app/social/coffeechat/page.tsx create mode 100644 src/app/social/date/page.tsx create mode 100644 src/app/social/ebook/page.tsx create mode 100644 src/app/social/feedback/page.tsx create mode 100644 src/app/social/gigs/page.tsx create mode 100644 src/app/social/join/page.tsx create mode 100644 src/app/social/layout.tsx create mode 100644 src/app/social/meetup/[id]/page.tsx create mode 100644 src/app/social/meetup/page.tsx create mode 100644 src/app/social/page.tsx create mode 100644 src/app/social/roster/page.tsx create mode 100644 src/app/social/videos/page.tsx create mode 100644 src/app/social/vip/page.tsx create mode 100644 src/modules/social/README.md create mode 100644 src/modules/social/app/globals.css create mode 100644 src/modules/social/components/ChatListClient.tsx create mode 100644 src/modules/social/components/ChatRoomClient.tsx create mode 100644 src/modules/social/components/CoffeechatClient.tsx create mode 100644 src/modules/social/components/DateClient.tsx create mode 100644 src/modules/social/components/EbookClient.tsx create mode 100644 src/modules/social/components/FeedbackClient.tsx create mode 100644 src/modules/social/components/GigsClient.tsx create mode 100644 src/modules/social/components/HomeClient.tsx create mode 100644 src/modules/social/components/JoinClient.tsx create mode 100644 src/modules/social/components/MeetupClient.tsx create mode 100644 src/modules/social/components/MeetupLiveClient.tsx create mode 100644 src/modules/social/components/ParticleCanvas.tsx create mode 100644 src/modules/social/components/RosterClient.tsx create mode 100644 src/modules/social/components/SiteShell.tsx create mode 100644 src/modules/social/components/VideosClient.tsx create mode 100644 src/modules/social/components/VipClient.tsx create mode 100644 src/modules/social/lib/api.ts create mode 100644 src/modules/social/lib/catalog.ts create mode 100644 src/modules/social/lib/seed.ts create mode 100644 src/modules/social/lib/socialPath.ts create mode 100644 src/modules/social/lib/storage.ts create mode 100644 src/modules/social/lib/types.ts diff --git a/README.md b/README.md index 4f653c3..675ad81 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ ``` src/ Next.js 门户(app 路由壳 + modules 业务) apps/miniprogram/ Taro:h5 SoT · weapp · tt · xhs -apps/api/ 统一 FastAPI(ebook + community + pay) +apps/api/ 统一 FastAPI(ebook + community + pay + social) apps/admin/ admin.nomadro.cn 管理 SPA(Vite) packages/ @nomadro/pay · pb · sdk -data/ 远程配置等运行时数据 +data/ 远程配置等运行时数据(含 social.db 独立库) scripts/ 本地开发 / 清理(dev-api · clean-artifacts) ``` @@ -18,7 +18,8 @@ scripts/ 本地开发 / 清理(dev-api · clean-artifacts) |------|----------|------| | 导航 | `/nav` | `src/modules/nav` · 远程 `navContent`(后台 `/wechat/nav` 可 CRUD) | | 小册 | `/book` | `src/modules/ebook` + `src/modules/ebook-content` | -| 社群 | `/community` | `src/modules/community` | +| 旅居社群 | `/community` | `src/modules/community`(Lounge / Ergo / MiroTalk;**勿改名**) | +| 游民社区 | `/social` | `src/modules/social` · API `/api/social/v1` · SQLite `data/social/`(可拆独立域) | | VIP | `/vip` | `src/modules/vip`(微信小程序原生页,见下) | | 后台 | admin.nomadro.cn | `apps/admin` | | API | api.nomadro.cn | `apps/api` | @@ -115,8 +116,13 @@ pnpm dev:api - **远程配置 + 离线兜底**:`/api/config` · `data/remote-config.json` · `/admin/config` - **禁止**再引入已删垂直树(见 `AGENTS.md`) - **发布流**:本地调试 → 当前开发分支 commit/push → 部署脚本上线 → 冒烟;配置与发版均以 git 为准 -- 审核冻结分支:`pre4`(**当前微信版本已提交上线审核,勿在本分支继续功能迭代**) -- 下一轮开发分支:`pre5`(从 `pre4` 拉出);发版前与 README / 远程对齐 +- 审核冻结分支:`pre4`(**微信审核包,勿在本分支继续功能迭代**) +- `pre5`:承接 pre4 之后的功能(含游民社区 `/social`) +- **当前开发分支:`test5`**(从 `pre5` 拉出);发版前与 README / 远程对齐 + +### 游民社区(`/social`) + +与旅居社群 `/community` **完全独立**:门户 `src/modules/social` + `src/app/social`;后端 `apps/api/services/social_svc`(前缀 `/api/social/v1`,库文件 `data/social/social.db`);`SOCIAL_ENABLED=false` 或挂载失败不影响 ebook / community / pay。门户首页主入口为「游民社区」;旅居社群仍保留。增量部署见 [`deploy/social/README.md`](deploy/social/README.md)。MiroTalk 站内嵌 CSP 在公网机 `107.173.30.245` 的 Caddy(须含 `nomadro.cn` 与本地 `:3000`)。 ## pre4 摘要(审核包) @@ -136,9 +142,17 @@ pnpm dev:api - VIP/加群开关联动;加群点击强制拉最新 `/api/config` - **P0/P1 加固**(`017008d`):VIP library 鉴权、Mine 登录、game stub、WAL/限流、CORS -## pre5(下一轮) +## pre5 摘要 -从 `pre4` 切出;**勿改动审核包行为**,仅做下一版本功能。建议方向:课时资料后台可视化编辑、桥接 UX 打磨、DevTools Timeout 排查(真机网络/域名)。 +从 `pre4` 切出;**勿改动审核包行为**。本轮落地: + +- **游民社区**:`/social` 全站能力(加入 / 文字厅 / 活动直播嵌 MiroTalk / coffeechat / 约会 / 花名册 / UGC / 接单 / 反馈 / VIP 入口) +- 隔离 API + SQLite;远程配置 `modules.social`;门户 hero 主入口切换为游民社区 +- 社区 Settings `extra="ignore"`,避免统一 `.env` 拖垮 community 启动 + +## test5(当前开发) + +从 `pre5` 切出。建议方向:social 线上增量部署与冒烟、课时资料后台可视化、桥接 UX、真机网络/域名排查。 ## pre3 摘要(已合入) diff --git a/apps/api/app/main.py b/apps/api/app/main.py index a808fe8..5427454 100644 --- a/apps/api/app/main.py +++ b/apps/api/app/main.py @@ -67,6 +67,19 @@ from pay_svc.routers import ( # noqa: E402 ) from pay_svc.routers.salon_meetup import router as salon_meetup_router # noqa: E402 +# 游民社区:可选挂载;失败绝不拖垮现网 ebook/community/pay +_social_router = None +try: + from social_svc.config import SOCIAL_ENABLED # noqa: E402 + from social_svc.routers import router as _social_router_mod # noqa: E402 + from social_svc.store import init_db as _social_init_db # noqa: E402 + + if SOCIAL_ENABLED: + _social_router = _social_router_mod +except Exception as _social_err: # pragma: no cover + print(f"[social_svc] skip mount: {_social_err}") + _social_router = None + try: from apscheduler.schedulers.asyncio import AsyncIOScheduler @@ -87,6 +100,12 @@ async def lifespan(_: FastAPI): get_pb_client() except Exception: pass + # social isolated sqlite (own file only) + if _social_router is not None: + try: + _social_init_db() + except Exception as e: + print(f"[social_svc] init_db failed (non-fatal): {e}") yield if scheduler is not None: scheduler.shutdown(wait=False) @@ -152,11 +171,18 @@ app.include_router(salon_meetup_router) app.include_router(chatbot_router) app.include_router(hackrobot_router) +# —— 游民社区(独立前缀 /api/social/v1,独立 SQLite)—— +if _social_router is not None: + app.include_router(_social_router, prefix="/api/social/v1") + @app.get("/health") @app.get("/api/ebook/health") async def health(): - return {"ok": True, "service": "nomadro-api", "modules": ["ebook", "community", "pay"]} + modules = ["ebook", "community", "pay"] + if _social_router is not None: + modules.append("social") + return {"ok": True, "service": "nomadro-api", "modules": modules} @app.get("/") @@ -166,4 +192,5 @@ async def root(): "docs": "/docs", "health": "/health", "community_health": "/api/v1/health", + "social_health": "/api/social/v1/health", } diff --git a/apps/api/services/community_svc/config.py b/apps/api/services/community_svc/config.py index bbb0ef1..445687b 100644 --- a/apps/api/services/community_svc/config.py +++ b/apps/api/services/community_svc/config.py @@ -1,7 +1,10 @@ -from pydantic_settings import BaseSettings +from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): + # 忽略 .env 中其它模块键,避免本地/统一 env 拖垮启动(不改业务字段) + model_config = SettingsConfigDict(env_file=".env", extra="ignore") + pocketbase_url: str = "http://127.0.0.1:8090" pocketbase_admin_email: str = "admin@nomadro.com" pocketbase_admin_password: str = "Xiao4669805" @@ -40,8 +43,5 @@ class Settings(BaseSettings): def cors_origin_list(self) -> list[str]: return [o.strip() for o in self.cors_origins.split(",") if o.strip()] - class Config: - env_file = ".env" - settings = Settings() diff --git a/apps/api/services/social_svc/__init__.py b/apps/api/services/social_svc/__init__.py new file mode 100644 index 0000000..b5ee826 --- /dev/null +++ b/apps/api/services/social_svc/__init__.py @@ -0,0 +1 @@ +"""游民社区独立后端 — 与 community/ebook/pay 数据完全隔离。""" diff --git a/apps/api/services/social_svc/config.py b/apps/api/services/social_svc/config.py new file mode 100644 index 0000000..d75ad9f --- /dev/null +++ b/apps/api/services/social_svc/config.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +import os +from pathlib import Path + +# 默认写在仓库 data/social,与 PocketBase / community 目录分离 +_ROOT = Path(__file__).resolve().parents[4] # nomadro/ +_DEFAULT_DB = _ROOT / "data" / "social" / "social.db" + +SOCIAL_DB_PATH = Path(os.getenv("SOCIAL_DB_PATH", str(_DEFAULT_DB))).resolve() +SOCIAL_ENABLED = os.getenv("SOCIAL_ENABLED", "true").lower() in {"1", "true", "yes", "on"} diff --git a/apps/api/services/social_svc/routers/__init__.py b/apps/api/services/social_svc/routers/__init__.py new file mode 100644 index 0000000..502d465 --- /dev/null +++ b/apps/api/services/social_svc/routers/__init__.py @@ -0,0 +1,3 @@ +from .api import router + +__all__ = ["router"] diff --git a/apps/api/services/social_svc/routers/api.py b/apps/api/services/social_svc/routers/api.py new file mode 100644 index 0000000..ecf651e --- /dev/null +++ b/apps/api/services/social_svc/routers/api.py @@ -0,0 +1,139 @@ +"""游民社区 API — 前缀 /api/social/v1,与 /api/v1 社群隔离。""" +from __future__ import annotations + +from fastapi import APIRouter, Header, HTTPException +from pydantic import BaseModel, Field + +from social_svc import store +from social_svc.config import SOCIAL_ENABLED + +router = APIRouter(tags=["social"]) + + +def _guest(x_social_guest_id: str | None) -> str: + gid = (x_social_guest_id or "").strip() + if not gid or len(gid) > 80: + raise HTTPException(status_code=400, detail="missing X-Social-Guest-Id") + return gid + + +class MessageIn(BaseModel): + author: str = Field(default="游民", max_length=48) + text: str = Field(min_length=1, max_length=2000) + + +class ReviewIn(BaseModel): + author: str = Field(default="游民", max_length=48) + score: int = Field(default=5, ge=1, le=5) + text: str = Field(min_length=1, max_length=2000) + photoNote: str = Field(default="", max_length=200) + + +class RosterIn(BaseModel): + name: str = Field(default="", max_length=64) + title: str = Field(default="", max_length=80) + city: str = Field(default="", max_length=64) + phone: str = Field(default="", max_length=32) + linktree: str = Field(default="", max_length=240) + skills: str = Field(default="", max_length=200) + bio: str = Field(default="", max_length=2000) + + +class FeedbackIn(BaseModel): + kind: str = Field(default="建议", max_length=8) + text: str = Field(min_length=1, max_length=4000) + contact: str = Field(default="", max_length=120) + + +class GigAppIn(BaseModel): + name: str = Field(min_length=1, max_length=64) + contact: str = Field(min_length=1, max_length=120) + note: str = Field(default="", max_length=2000) + + +@router.get("/health") +async def social_health(): + if not SOCIAL_ENABLED: + return {"ok": False, "module": "social", "enabled": False} + return store.health() + + +@router.get("/channels/{channel_id}/messages") +async def get_messages(channel_id: str, limit: int = 100): + store.init_db() + return {"items": store.list_messages(channel_id, limit)} + + +@router.post("/channels/{channel_id}/messages") +async def post_message( + channel_id: str, + body: MessageIn, + x_social_guest_id: str | None = Header(default=None), +): + guest = _guest(x_social_guest_id) + store.init_db() + if not body.text.strip(): + raise HTTPException(status_code=400, detail="empty text") + return store.add_message(channel_id, body.author, body.text, guest) + + +@router.get("/cafes/{cafe_id}/reviews") +async def get_reviews(cafe_id: str, limit: int = 50): + store.init_db() + return {"items": store.list_reviews(cafe_id, limit)} + + +@router.post("/cafes/{cafe_id}/reviews") +async def post_review( + cafe_id: str, + body: ReviewIn, + x_social_guest_id: str | None = Header(default=None), +): + guest = _guest(x_social_guest_id) + store.init_db() + return store.add_review( + cafe_id, + body.author, + body.score, + body.text, + body.photoNote, + guest, + ) + + +@router.get("/roster/me") +async def get_my_roster(x_social_guest_id: str | None = Header(default=None)): + guest = _guest(x_social_guest_id) + store.init_db() + return {"item": store.get_roster(guest)} + + +@router.put("/roster/me") +async def put_my_roster( + body: RosterIn, + x_social_guest_id: str | None = Header(default=None), +): + guest = _guest(x_social_guest_id) + store.init_db() + return store.upsert_roster(guest, body.model_dump()) + + +@router.post("/feedback") +async def post_feedback( + body: FeedbackIn, + x_social_guest_id: str | None = Header(default=None), +): + guest = _guest(x_social_guest_id) + store.init_db() + return store.add_feedback(body.kind, body.text, body.contact, guest) + + +@router.post("/gigs/{gig_id}/apply") +async def post_gig_apply( + gig_id: str, + body: GigAppIn, + x_social_guest_id: str | None = Header(default=None), +): + guest = _guest(x_social_guest_id) + store.init_db() + return store.add_gig_app(gig_id, body.name, body.contact, body.note, guest) diff --git a/apps/api/services/social_svc/store.py b/apps/api/services/social_svc/store.py new file mode 100644 index 0000000..728a015 --- /dev/null +++ b/apps/api/services/social_svc/store.py @@ -0,0 +1,330 @@ +"""Isolated SQLite store for 游民社区 — never touches community/PB tables.""" +from __future__ import annotations + +import json +import sqlite3 +import time +import uuid +from contextlib import contextmanager +from pathlib import Path +from typing import Any, Iterator + +from .config import SOCIAL_DB_PATH + +try: + from ebook_svc.core.sqlite_util import connect as _connect +except Exception: # pragma: no cover + def _connect(path: str | Path, *, timeout: float = 30.0) -> sqlite3.Connection: + p = Path(path) + p.parent.mkdir(parents=True, exist_ok=True) + c = sqlite3.connect(str(p), timeout=timeout) + c.row_factory = sqlite3.Row + c.execute("PRAGMA journal_mode=WAL") + return c + + +def _uid(prefix: str) -> str: + return f"{prefix}_{uuid.uuid4().hex[:12]}" + + +def _now() -> str: + return time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime()) + + +@contextmanager +def db() -> Iterator[sqlite3.Connection]: + SOCIAL_DB_PATH.parent.mkdir(parents=True, exist_ok=True) + conn = _connect(SOCIAL_DB_PATH) + try: + yield conn + conn.commit() + except Exception: + conn.rollback() + raise + finally: + conn.close() + + +def init_db() -> None: + with db() as conn: + conn.executescript( + """ + CREATE TABLE IF NOT EXISTS messages ( + id TEXT PRIMARY KEY, + channel_id TEXT NOT NULL, + author TEXT NOT NULL, + text TEXT NOT NULL, + guest_id TEXT NOT NULL, + created_at TEXT NOT NULL + ); + CREATE INDEX IF NOT EXISTS idx_messages_channel ON messages(channel_id, created_at); + + CREATE TABLE IF NOT EXISTS cafe_reviews ( + id TEXT PRIMARY KEY, + cafe_id TEXT NOT NULL, + author TEXT NOT NULL, + score INTEGER NOT NULL, + text TEXT NOT NULL, + photo_note TEXT, + guest_id TEXT NOT NULL, + created_at TEXT NOT NULL + ); + CREATE INDEX IF NOT EXISTS idx_reviews_cafe ON cafe_reviews(cafe_id, created_at); + + CREATE TABLE IF NOT EXISTS roster ( + guest_id TEXT PRIMARY KEY, + name TEXT NOT NULL, + title TEXT, + city TEXT, + phone TEXT, + linktree TEXT, + skills TEXT, + bio TEXT, + updated_at TEXT NOT NULL + ); + + CREATE TABLE IF NOT EXISTS feedback ( + id TEXT PRIMARY KEY, + kind TEXT NOT NULL, + text TEXT NOT NULL, + contact TEXT, + guest_id TEXT NOT NULL, + created_at TEXT NOT NULL + ); + + CREATE TABLE IF NOT EXISTS gig_apps ( + id TEXT PRIMARY KEY, + gig_id TEXT NOT NULL, + name TEXT NOT NULL, + contact TEXT NOT NULL, + note TEXT, + guest_id TEXT NOT NULL, + created_at TEXT NOT NULL + ); + """ + ) + + +def list_messages(channel_id: str, limit: int = 100) -> list[dict[str, Any]]: + with db() as conn: + rows = conn.execute( + """ + SELECT id, channel_id, author, text, guest_id, created_at + FROM messages + WHERE channel_id = ? + ORDER BY created_at ASC + LIMIT ? + """, + (channel_id, max(1, min(limit, 500))), + ).fetchall() + return [ + { + "id": r["id"], + "channelId": r["channel_id"], + "author": r["author"], + "text": r["text"], + "guestId": r["guest_id"], + "at": r["created_at"], + } + for r in rows + ] + + +def add_message(channel_id: str, author: str, text: str, guest_id: str) -> dict[str, Any]: + item = { + "id": _uid("msg"), + "channelId": channel_id, + "author": (author or "游民").strip()[:48] or "游民", + "text": text.strip()[:2000], + "guestId": guest_id, + "at": _now(), + } + with db() as conn: + conn.execute( + """ + INSERT INTO messages(id, channel_id, author, text, guest_id, created_at) + VALUES (?, ?, ?, ?, ?, ?) + """, + (item["id"], item["channelId"], item["author"], item["text"], guest_id, item["at"]), + ) + return item + + +def list_reviews(cafe_id: str, limit: int = 50) -> list[dict[str, Any]]: + with db() as conn: + rows = conn.execute( + """ + SELECT id, cafe_id, author, score, text, photo_note, guest_id, created_at + FROM cafe_reviews + WHERE cafe_id = ? + ORDER BY created_at DESC + LIMIT ? + """, + (cafe_id, max(1, min(limit, 200))), + ).fetchall() + return [ + { + "id": r["id"], + "cafeId": r["cafe_id"], + "author": r["author"], + "score": r["score"], + "text": r["text"], + "photoNote": r["photo_note"] or "", + "guestId": r["guest_id"], + "at": r["created_at"], + } + for r in rows + ] + + +def add_review( + cafe_id: str, + author: str, + score: int, + text: str, + photo_note: str, + guest_id: str, +) -> dict[str, Any]: + item = { + "id": _uid("rv"), + "cafeId": cafe_id, + "author": (author or "游民").strip()[:48] or "游民", + "score": max(1, min(int(score or 5), 5)), + "text": text.strip()[:2000], + "photoNote": (photo_note or "").strip()[:200], + "guestId": guest_id, + "at": _now(), + } + with db() as conn: + conn.execute( + """ + INSERT INTO cafe_reviews(id, cafe_id, author, score, text, photo_note, guest_id, created_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) + """, + ( + item["id"], + item["cafeId"], + item["author"], + item["score"], + item["text"], + item["photoNote"], + guest_id, + item["at"], + ), + ) + return item + + +def get_roster(guest_id: str) -> dict[str, Any] | None: + with db() as conn: + r = conn.execute("SELECT * FROM roster WHERE guest_id = ?", (guest_id,)).fetchone() + if not r: + return None + return { + "guestId": r["guest_id"], + "name": r["name"], + "title": r["title"] or "", + "city": r["city"] or "", + "phone": r["phone"] or "", + "linktree": r["linktree"] or "", + "skills": r["skills"] or "", + "bio": r["bio"] or "", + "updatedAt": r["updated_at"], + } + + +def upsert_roster(guest_id: str, payload: dict[str, Any]) -> dict[str, Any]: + updated = _now() + row = { + "guestId": guest_id, + "name": str(payload.get("name") or "").strip()[:64] or "游民", + "title": str(payload.get("title") or "").strip()[:80], + "city": str(payload.get("city") or "").strip()[:64], + "phone": str(payload.get("phone") or "").strip()[:32], + "linktree": str(payload.get("linktree") or "").strip()[:240], + "skills": str(payload.get("skills") or "").strip()[:200], + "bio": str(payload.get("bio") or "").strip()[:2000], + "updatedAt": updated, + } + with db() as conn: + conn.execute( + """ + INSERT INTO roster(guest_id, name, title, city, phone, linktree, skills, bio, updated_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) + ON CONFLICT(guest_id) DO UPDATE SET + name=excluded.name, + title=excluded.title, + city=excluded.city, + phone=excluded.phone, + linktree=excluded.linktree, + skills=excluded.skills, + bio=excluded.bio, + updated_at=excluded.updated_at + """, + ( + guest_id, + row["name"], + row["title"], + row["city"], + row["phone"], + row["linktree"], + row["skills"], + row["bio"], + updated, + ), + ) + return row + + +def add_feedback(kind: str, text: str, contact: str, guest_id: str) -> dict[str, Any]: + item = { + "id": _uid("fb"), + "kind": kind if kind in {"反馈", "建议"} else "建议", + "text": text.strip()[:4000], + "contact": (contact or "").strip()[:120], + "guestId": guest_id, + "at": _now(), + } + with db() as conn: + conn.execute( + """ + INSERT INTO feedback(id, kind, text, contact, guest_id, created_at) + VALUES (?, ?, ?, ?, ?, ?) + """, + (item["id"], item["kind"], item["text"], item["contact"], guest_id, item["at"]), + ) + return item + + +def add_gig_app(gig_id: str, name: str, contact: str, note: str, guest_id: str) -> dict[str, Any]: + item = { + "id": _uid("app"), + "gigId": gig_id, + "name": name.strip()[:64], + "contact": contact.strip()[:120], + "note": (note or "").strip()[:2000], + "guestId": guest_id, + "at": _now(), + } + with db() as conn: + conn.execute( + """ + INSERT INTO gig_apps(id, gig_id, name, contact, note, guest_id, created_at) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, + (item["id"], item["gigId"], item["name"], item["contact"], item["note"], guest_id, item["at"]), + ) + return item + + +def health() -> dict[str, Any]: + init_db() + exists = SOCIAL_DB_PATH.exists() + size = SOCIAL_DB_PATH.stat().st_size if exists else 0 + return { + "ok": True, + "module": "social", + "db": str(SOCIAL_DB_PATH), + "dbBytes": size, + "isolated": True, + } diff --git a/data/remote-config.json b/data/remote-config.json index e512ce3..cde8683 100644 --- a/data/remote-config.json +++ b/data/remote-config.json @@ -22,6 +22,12 @@ "title": "旅居社群", "tabLabel": "社群" }, + "social": { + "enabled": true, + "title": "游民社区", + "tabLabel": "社区", + "note": "门户 /social · 可拆独立域" + }, "destinations": { "enabled": true, "title": "目的地" diff --git a/data/social/.gitkeep b/data/social/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/deploy/social/README.md b/deploy/social/README.md new file mode 100644 index 0000000..cb28fe8 --- /dev/null +++ b/deploy/social/README.md @@ -0,0 +1,53 @@ +# 游民社区(social)增量部署 + +独立于旅居社群 `/community`、电子书、支付。 + +## 隔离保证 + +| 项 | 约定 | +|---|---| +| API 前缀 | `/api/social/v1/*`(不占用 `/api/v1`) | +| 存储 | `data/social/social.db`(可用 `SOCIAL_DB_PATH` 改路径) | +| 挂载 | `apps/api/app/main.py` 内 try/except;social 挂载失败不影响现网 | +| 开关 | `SOCIAL_ENABLED=false` 可整模块关闭 | +| 前端 | `/social` + `modules.social` 远程开关 | + +**禁止**改 PocketBase 现有 collection、禁止写 community/ebook/pay 表。 + +## 本地 + +```bash +# 终端 1 +pnpm dev:api + +# 终端 2(若已在跑可跳过) +pnpm dev +``` + +检查:`http://localhost:8080/api/social/v1/health`(端口以现网 API_URL 为准) + +## 线上增量(可重启 API) + +1. 拉代码(含 `apps/api/services/social_svc`、门户 `/social`) +2. 确认环境变量(可选): + - `SOCIAL_ENABLED=true` + - `SOCIAL_DB_PATH=/var/www/nomadro-data/social/social.db`(独立目录,勿放进 PB data) +3. 重启 **统一 API** 进程(systemd/pm2)——只加载新路由 + 新 sqlite 文件 +4. 构建/重启门户 Next(含 `/social` 与 rewrite `/api/social/*`) +5. 冒烟: + - `GET /api/social/v1/health` → `ok` + `isolated: true` + - `GET /api/v1/health` 与 `/health` 仍正常(现网未坏) + - 打开 `https://nomadro.cn/social` 发一条聊天 + +回滚:设 `SOCIAL_ENABLED=false` 或去掉 social 代码后重启 API;**不要删**现网 PB/其它库。social.db 可单独备份/删除,不影响其它业务。 + +## MiroTalk 站内嵌(CSP) + +公网 `mirotalk.nomadro.com` 解析在 **`107.173.30.245`**(Caddy 反代 `mirotalk.nomadro.cn`),`frame-ancestors` 写在: + +- `/etc/caddy/sites/mirotalk.nomadro.com.caddy` +- `/etc/caddy/sites/lounge.nomadro.com.caddy`(文字厅同源策略) + +须包含:`https://nomadro.cn` `https://www.nomadro.cn` `http://localhost:3000` `http://127.0.0.1:3000`(及可选 `:3001`)。改完后 `systemctl reload caddy`。 + +本地 `pnpm dev`(:3000)活动页应可 iframe;若仍被拒,`MeetupLiveClient` 会本页 `location.assign` 进入(不新开标签)。 diff --git a/next.config.ts b/next.config.ts index 65a4bd4..61acf8b 100644 --- a/next.config.ts +++ b/next.config.ts @@ -10,6 +10,7 @@ const API_URL = (process.env.API_URL || "http://127.0.0.1:8080").replace( const aliases = { "@ebook": path.resolve(__dirname, "src/modules/ebook"), "@community": path.resolve(__dirname, "src/modules/community"), + "@social": path.resolve(__dirname, "src/modules/social"), "@navmini": path.resolve(__dirname, "src/modules/nav"), "@vip": path.resolve(__dirname, "src/modules/vip"), "@nomadro/pay": path.resolve(__dirname, "packages/pay/src/index.ts"), @@ -42,6 +43,7 @@ const nextConfig: NextConfig = { resolveAlias: { "@ebook": "./src/modules/ebook", "@community": "./src/modules/community", + "@social": "./src/modules/social", "@navmini": "./src/modules/nav", "@vip": "./src/modules/vip", "@nomadro/pay": "./packages/pay/src/index.ts", @@ -74,6 +76,10 @@ const nextConfig: NextConfig = { source: "/api/v1/:path*", destination: `${API_URL}/api/v1/:path*`, }, + { + source: "/api/social/:path*", + destination: `${API_URL}/api/social/:path*`, + }, ]; }, async headers() { diff --git a/src/app/admin/verticals/page.tsx b/src/app/admin/verticals/page.tsx index 637526f..3e351a2 100644 --- a/src/app/admin/verticals/page.tsx +++ b/src/app/admin/verticals/page.tsx @@ -21,6 +21,12 @@ const VERTICALS = [ route: "/community", notes: ["门户 Next", "API apps/api"], }, + { + name: "游民社区", + code: "modules/social", + route: "/social", + notes: ["门户 Next", "可拆独立域 social.nomadro.cn"], + }, { name: "私域会员", code: "modules/vip", diff --git a/src/app/hub.css b/src/app/hub.css index 3d07ccb..f0cfd21 100644 --- a/src/app/hub.css +++ b/src/app/hub.css @@ -317,12 +317,19 @@ html.light .hub-navbar.scrolled, grid-area: portals; align-self: start; display: grid; - grid-template-columns: repeat(3, 1fr); + grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 520px; margin-top: 0; } +@media (min-width: 900px) { + .hub-portal-grid { + grid-template-columns: repeat(4, minmax(0, 1fr)); + max-width: 720px; + } +} + .hub-gradient-text { background: var(--hub-gradient-text); -webkit-background-clip: text; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 304d729..a0c96a1 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -26,7 +26,7 @@ export const viewport: Viewport = { export const metadata: Metadata = { metadataBase: new URL("https://nomadro.cn"), title: "nomadro", - description: "数字游民入口 · 出海导航 · 数字游民小册 · 旅居社群", + description: "数字游民入口 · 出海导航 · 数字游民小册 · 游民社区", applicationName: "nomadro", keywords: [ "数字游民", diff --git a/src/app/social/chat/[id]/page.tsx b/src/app/social/chat/[id]/page.tsx new file mode 100644 index 0000000..37d0fc7 --- /dev/null +++ b/src/app/social/chat/[id]/page.tsx @@ -0,0 +1,8 @@ +import ChatRoomClient from "@social/components/ChatRoomClient"; +import { SEED_CHANNELS } from "@social/lib/seed"; + +export default async function Page({ params }: { params: Promise<{ id: string }> }) { + const { id } = await params; + const channelId = SEED_CHANNELS.some((c) => c.id === id) ? id : SEED_CHANNELS[0].id; + return ; +} diff --git a/src/app/social/chat/page.tsx b/src/app/social/chat/page.tsx new file mode 100644 index 0000000..8eb32fc --- /dev/null +++ b/src/app/social/chat/page.tsx @@ -0,0 +1,5 @@ +import ChatListClient from "@social/components/ChatListClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/coffeechat/page.tsx b/src/app/social/coffeechat/page.tsx new file mode 100644 index 0000000..507afb0 --- /dev/null +++ b/src/app/social/coffeechat/page.tsx @@ -0,0 +1,5 @@ +import CoffeechatClient from "@social/components/CoffeechatClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/date/page.tsx b/src/app/social/date/page.tsx new file mode 100644 index 0000000..e6d08aa --- /dev/null +++ b/src/app/social/date/page.tsx @@ -0,0 +1,5 @@ +import DateClient from "@social/components/DateClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/ebook/page.tsx b/src/app/social/ebook/page.tsx new file mode 100644 index 0000000..403ccc3 --- /dev/null +++ b/src/app/social/ebook/page.tsx @@ -0,0 +1,5 @@ +import EbookClient from "@social/components/EbookClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/feedback/page.tsx b/src/app/social/feedback/page.tsx new file mode 100644 index 0000000..9e5167d --- /dev/null +++ b/src/app/social/feedback/page.tsx @@ -0,0 +1,5 @@ +import FeedbackClient from "@social/components/FeedbackClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/gigs/page.tsx b/src/app/social/gigs/page.tsx new file mode 100644 index 0000000..542ee26 --- /dev/null +++ b/src/app/social/gigs/page.tsx @@ -0,0 +1,5 @@ +import GigsClient from "@social/components/GigsClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/join/page.tsx b/src/app/social/join/page.tsx new file mode 100644 index 0000000..53ae9ab --- /dev/null +++ b/src/app/social/join/page.tsx @@ -0,0 +1,5 @@ +import JoinClient from "@social/components/JoinClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/layout.tsx b/src/app/social/layout.tsx new file mode 100644 index 0000000..31f4971 --- /dev/null +++ b/src/app/social/layout.tsx @@ -0,0 +1,21 @@ +import { ModuleBoundary } from "~/components/module-boundary"; +/* 视觉 SoT:对齐旅居社群;业务样式在 social globals */ +import "@community/app/globals.css"; +import "@social/app/globals.css"; + +export const metadata = { + title: "游民社区 · nomadro", + description: "数字游民社交:线上聊天 · Meetup · Coffeechat · 职业花名册 · UGC", +}; + +export default function SocialLayout({ + children, +}: { + children: React.ReactNode; +}) { + return ( + +
{children}
+
+ ); +} diff --git a/src/app/social/meetup/[id]/page.tsx b/src/app/social/meetup/[id]/page.tsx new file mode 100644 index 0000000..7de0061 --- /dev/null +++ b/src/app/social/meetup/[id]/page.tsx @@ -0,0 +1,8 @@ +import MeetupLiveClient from "@social/components/MeetupLiveClient"; +import { SEED_MEETUPS } from "@social/lib/seed"; + +export default async function Page({ params }: { params: Promise<{ id: string }> }) { + const { id } = await params; + const meetupId = SEED_MEETUPS.some((m) => m.id === id) ? id : SEED_MEETUPS[0].id; + return ; +} diff --git a/src/app/social/meetup/page.tsx b/src/app/social/meetup/page.tsx new file mode 100644 index 0000000..de081ff --- /dev/null +++ b/src/app/social/meetup/page.tsx @@ -0,0 +1,5 @@ +import MeetupClient from "@social/components/MeetupClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/page.tsx b/src/app/social/page.tsx new file mode 100644 index 0000000..17aa4d3 --- /dev/null +++ b/src/app/social/page.tsx @@ -0,0 +1,5 @@ +import HomeClient from "@social/components/HomeClient"; + +export default function SocialHomePage() { + return ; +} diff --git a/src/app/social/roster/page.tsx b/src/app/social/roster/page.tsx new file mode 100644 index 0000000..69cbe77 --- /dev/null +++ b/src/app/social/roster/page.tsx @@ -0,0 +1,5 @@ +import RosterClient from "@social/components/RosterClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/videos/page.tsx b/src/app/social/videos/page.tsx new file mode 100644 index 0000000..dec2517 --- /dev/null +++ b/src/app/social/videos/page.tsx @@ -0,0 +1,5 @@ +import VideosClient from "@social/components/VideosClient"; + +export default function Page() { + return ; +} diff --git a/src/app/social/vip/page.tsx b/src/app/social/vip/page.tsx new file mode 100644 index 0000000..f967ce5 --- /dev/null +++ b/src/app/social/vip/page.tsx @@ -0,0 +1,5 @@ +import VipClient from "@social/components/VipClient"; + +export default function Page() { + return ; +} diff --git a/src/components/sections/hero.tsx b/src/components/sections/hero.tsx index 52f421e..f16ccd5 100644 --- a/src/components/sections/hero.tsx +++ b/src/components/sections/hero.tsx @@ -15,6 +15,7 @@ const EXTERNAL_PORTALS = { nav: "https://nav.hackrobot.cn/", book: "https://nomadweb.nomadro.com/book", community: "https://nomadweb.nomadro.com", + social: "https://social.nomadro.cn", vip: "https://vip.hackrobot.cn/", } as const; @@ -22,6 +23,7 @@ const INTERNAL_PORTALS = { nav: "/nav", book: "/book", community: "/community", + social: "/social", vip: "/vip", } as const; @@ -46,6 +48,13 @@ const PORTALS = [ moduleKey: "community" as const, emoji: "🌏", name: "旅居社群", + main: false, + }, + { + id: "social" as const, + moduleKey: "social" as const, + emoji: "💬", + name: "游民社区", main: true, }, ]; diff --git a/src/lib/remote-config.ts b/src/lib/remote-config.ts index bd60584..9bf7ddf 100644 --- a/src/lib/remote-config.ts +++ b/src/lib/remote-config.ts @@ -92,6 +92,8 @@ export type NomadroRemoteConfig = { nav: ModuleToggle; book: ModuleToggle; community: ModuleToggle; + /** 游民社区(社交垂直;可拆独立域) */ + social: ModuleToggle; vip: ModuleToggle; meetups: ModuleToggle; destinations: ModuleToggle; @@ -300,6 +302,12 @@ export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = { tabLabel: "社群", note: "nomadweb", }, + social: { + enabled: true, + title: "游民社区", + tabLabel: "社区", + note: "门户 /social · 可拆独立域", + }, destinations: { enabled: true, title: "目的地" }, meetups: { enabled: true, title: "活动" }, vip: { enabled: false, title: "会员中心", note: "deep link only" }, diff --git a/src/modules/social/README.md b/src/modules/social/README.md new file mode 100644 index 0000000..8b7a683 --- /dev/null +++ b/src/modules/social/README.md @@ -0,0 +1,21 @@ +# 游民社区(social) + +门户:`/social` · SoT:`src/modules/social` · API:`/api/social/v1` +**与旅居社群 `/community` 完全独立。** + +## 隔离 + +- 后端:`apps/api/services/social_svc` → 独立 SQLite `data/social/social.db` +- 前缀:`/api/social/v1`(不占用 `/api/v1`) +- 挂载失败 / `SOCIAL_ENABLED=false` → 不影响 ebook / community / pay +- 前端失败自动降级 localStorage + +## 本地 + +```bash +pnpm dev:api +pnpm dev +curl http://127.0.0.1:8080/api/social/v1/health +``` + +部署说明见 [`deploy/social/README.md`](../../../deploy/social/README.md)。 diff --git a/src/modules/social/app/globals.css b/src/modules/social/app/globals.css new file mode 100644 index 0000000..06bb7d5 --- /dev/null +++ b/src/modules/social/app/globals.css @@ -0,0 +1,915 @@ +/* 游民社区首页 / 壳层 — 对齐旅居社群视觉语言 */ +.social-flow { + position: relative; + min-height: 100dvh; + background: var(--bg-primary, #0a0e17); + color: var(--text-primary, #f1f5f9); +} + +.social-hub-block { + margin-bottom: 40px; +} + +.social-hub-block-head { + margin-bottom: 16px; +} + +.social-hub-block-head h3 { + margin: 0 0 4px; + font-family: var(--font-display); + font-size: 1.25rem; + letter-spacing: -0.02em; +} + +.social-hub-block-head p { + margin: 0; + color: var(--text-secondary, #94a3b8); + font-size: 0.92rem; +} + +.social-hub-grid { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 14px; +} + +.social-hub-card { + display: flex; + flex-direction: column; + gap: 10px; + min-height: 168px; + padding: 20px 18px; + border-radius: var(--radius-xl, 24px); + border: var(--border-glass); + background: var(--bg-card); + backdrop-filter: blur(14px); + transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s; +} + +.social-hub-card:hover { + transform: translateY(-3px); + border-color: rgba(78, 205, 196, 0.35); + box-shadow: var(--shadow-glow); +} + +.social-hub-card-top { + display: flex; + align-items: center; + justify-content: space-between; +} + +.social-hub-emoji { + width: 44px; + height: 44px; + display: grid; + place-items: center; + border-radius: 14px; + background: var(--bg-glass); + border: var(--border-glass); + font-size: 1.25rem; +} + +.social-pill { + font-size: 0.72rem; + padding: 4px 10px; + border-radius: 999px; + border: var(--border-glass); + color: var(--text-muted, #64748b); +} + +.social-pill.live { + color: #4ecdc4; + border-color: rgba(78, 205, 196, 0.35); +} + +.social-hub-card h4 { + margin: 0; + font-family: var(--font-display); + font-size: 1.05rem; +} + +.social-hub-card p { + margin: 0; + flex: 1; + color: var(--text-secondary, #94a3b8); + font-size: 0.88rem; + line-height: 1.5; +} + +.social-hub-go { + color: var(--accent-3, #4ecdc4); + font-size: 0.85rem; + font-weight: 600; +} + +.social-next-grid { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 14px; +} + +.social-next-card { + display: grid; + grid-template-columns: auto 1fr auto; + gap: 14px; + align-items: center; + padding: 18px 16px; + border-radius: var(--radius-xl, 24px); + border: var(--border-glass); + background: var(--bg-card); + transition: transform 0.2s, border-color 0.2s; +} + +.social-next-card:hover { + transform: translateY(-2px); + border-color: rgba(255, 230, 109, 0.35); +} + +.social-next-card span { + font-size: 1.5rem; +} + +.social-next-card strong { + display: block; + font-family: var(--font-display); + margin-bottom: 4px; +} + +.social-next-card p { + margin: 0; + color: var(--text-secondary, #94a3b8); + font-size: 0.85rem; +} + +.social-next-card em { + font-style: normal; + color: var(--accent-2, #ffe66d); + font-size: 1.2rem; +} + +.social-flow .footer-inner { + display: grid; + grid-template-columns: 1.4fr 2fr; + gap: 32px; + padding: 48px 0 24px; +} + +.social-flow .footer-cols { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 20px; +} + +.social-flow .footer-cols h4 { + margin: 0 0 12px; + font-size: 0.9rem; +} + +.social-flow .footer-cols a { + display: block; + color: var(--text-secondary, #94a3b8); + font-size: 0.88rem; + margin-bottom: 8px; +} + +.social-flow .footer-cols a:hover { + color: var(--text-primary, #f1f5f9); +} + +.social-flow .footer-brand p { + margin-top: 12px; + color: var(--text-secondary, #94a3b8); + max-width: 28rem; +} + +.social-flow .footer-bottom { + display: flex; + justify-content: space-between; + gap: 12px; + padding: 16px 0 40px; + border-top: var(--border-glass); + color: var(--text-muted, #64748b); + font-size: 0.82rem; +} + +/* 子页:社区壳 + 内容区顶距 */ +.social-root { + /* keep legacy tokens for chat/forms pages */ +} + +.social-page-pad { + padding-top: calc(var(--nav-height, 72px) + 24px); + padding-bottom: 64px; +} + +@media (max-width: 960px) { + .social-hub-grid, + .social-next-grid { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + + .social-flow .footer-inner { + grid-template-columns: 1fr; + } +} + +@media (max-width: 640px) { + .social-hub-grid, + .social-next-grid, + .social-flow .footer-cols { + grid-template-columns: 1fr; + } + + .social-flow .nav-links { + display: none; + } +} + +.social-root { + --sc-bg: #0a0e17; + --sc-bg-card: rgba(17, 24, 39, 0.72); + --sc-bg-glass: rgba(255, 255, 255, 0.05); + --sc-text: #f1f5f9; + --sc-muted: #94a3b8; + --sc-accent-1: #ff6b6b; + --sc-accent-2: #ffe66d; + --sc-accent-3: #4ecdc4; + --sc-gradient: linear-gradient(135deg, #ff6b6b 0%, #ffe66d 50%, #4ecdc4 100%); + --sc-border: 1px solid rgba(255, 255, 255, 0.08); + --sc-radius: 16px; + --sc-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); + --sc-font-display: var(--font-outfit), var(--font-noto-sc), sans-serif; + --sc-font-body: var(--font-noto-sc), var(--font-outfit), sans-serif; + --sc-nav-h: 64px; + --sc-ease: 0.3s cubic-bezier(0.4, 0, 0.2, 1); + + min-height: 100dvh; + font-family: var(--sc-font-body); + background: + radial-gradient(ellipse 70% 45% at 50% -10%, rgba(78, 205, 196, 0.14), transparent), + radial-gradient(ellipse 50% 35% at 90% 20%, rgba(255, 107, 107, 0.1), transparent), + var(--sc-bg); + color: var(--sc-text); + line-height: 1.6; +} + +html.light .social-root, +[data-theme="light"] .social-root { + --sc-bg: #f8fafc; + --sc-bg-card: rgba(255, 255, 255, 0.88); + --sc-bg-glass: rgba(15, 23, 42, 0.04); + --sc-text: #0f172a; + --sc-muted: #64748b; + --sc-accent-1: #e11d48; + --sc-accent-2: #d97706; + --sc-accent-3: #0d9488; + --sc-gradient: linear-gradient(135deg, #e11d48 0%, #d97706 50%, #0d9488 100%); + --sc-border: 1px solid rgba(15, 23, 42, 0.08); + --sc-shadow: 0 8px 32px rgba(15, 23, 42, 0.08); + background: + radial-gradient(ellipse 70% 45% at 50% -10%, rgba(13, 148, 136, 0.1), transparent), + radial-gradient(ellipse 50% 35% at 90% 20%, rgba(225, 29, 72, 0.06), transparent), + var(--sc-bg); +} + +.social-root a { + color: inherit; + text-decoration: none; +} + +.social-nav { + position: sticky; + top: 0; + z-index: 40; + height: var(--sc-nav-h); + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 20px; + border-bottom: var(--sc-border); + background: color-mix(in srgb, var(--sc-bg) 82%, transparent); + backdrop-filter: blur(16px); +} + +.social-brand { + display: inline-flex; + align-items: center; + gap: 10px; + font-family: var(--sc-font-display); + font-weight: 800; + letter-spacing: -0.02em; +} + +.social-brand-mark { + width: 36px; + height: 36px; + border-radius: 12px; + display: grid; + place-items: center; + background: var(--sc-bg-glass); + border: var(--sc-border); + font-size: 1.1rem; +} + +.social-nav-back { + min-height: 44px; + padding: 0 14px; + border-radius: 999px; + border: var(--sc-border); + background: var(--sc-bg-glass); + color: var(--sc-muted); + font-size: 0.9rem; + display: inline-flex; + align-items: center; +} + +.social-nav-back:hover { + color: var(--sc-text); + border-color: rgba(78, 205, 196, 0.35); +} + +.social-main { + width: min(1080px, calc(100% - 32px)); + margin: 0 auto; + padding: 40px 0 80px; +} + +.social-hero { + margin-bottom: 48px; +} + +.social-hero-tag { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 6px 12px; + border-radius: 999px; + border: var(--sc-border); + background: var(--sc-bg-glass); + color: var(--sc-muted); + font-size: 0.82rem; + margin-bottom: 16px; +} + +.social-hero h1 { + margin: 0 0 12px; + font-family: var(--sc-font-display); + font-size: clamp(2rem, 5vw, 3.2rem); + font-weight: 800; + letter-spacing: -0.03em; + line-height: 1.1; +} + +.social-hero h1 span { + background: var(--sc-gradient); + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; + background-clip: text; +} + +.social-hero p { + margin: 0; + max-width: 36rem; + color: var(--sc-muted); + font-size: 1.05rem; +} + +.social-section { + margin-bottom: 40px; +} + +.social-section-head { + margin-bottom: 16px; +} + +.social-section-head h2 { + margin: 0 0 4px; + font-family: var(--sc-font-display); + font-size: 1.25rem; + font-weight: 800; + letter-spacing: -0.02em; +} + +.social-section-head p { + margin: 0; + color: var(--sc-muted); + font-size: 0.92rem; +} + +.social-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); + gap: 12px; +} + +.social-card { + display: flex; + flex-direction: column; + gap: 10px; + min-height: 140px; + padding: 18px 16px; + border-radius: var(--sc-radius); + border: var(--sc-border); + background: var(--sc-bg-card); + box-shadow: var(--sc-shadow); + backdrop-filter: blur(14px); + transition: transform var(--sc-ease), border-color var(--sc-ease), box-shadow var(--sc-ease); +} + +.social-card:hover { + transform: translateY(-3px); + border-color: rgba(78, 205, 196, 0.35); + box-shadow: 0 0 28px rgba(78, 205, 196, 0.12), var(--sc-shadow); +} + +.social-card-top { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; +} + +.social-card-ico { + width: 40px; + height: 40px; + border-radius: 12px; + display: grid; + place-items: center; + background: var(--sc-bg-glass); + border: var(--sc-border); + font-size: 1.15rem; +} + +.social-badge { + font-size: 0.72rem; + padding: 4px 8px; + border-radius: 999px; + border: var(--sc-border); + color: var(--sc-muted); +} + +.social-badge.live { + color: #4ecdc4; + border-color: rgba(78, 205, 196, 0.35); +} + +.social-card strong { + font-family: var(--sc-font-display); + font-size: 1.02rem; + letter-spacing: -0.02em; +} + +.social-card p { + margin: 0; + color: var(--sc-muted); + font-size: 0.88rem; +} + +.social-footer { + margin-top: 56px; + padding-top: 20px; + border-top: var(--sc-border); + color: var(--sc-muted); + font-size: 0.85rem; + display: flex; + flex-wrap: wrap; + gap: 8px 16px; + justify-content: space-between; +} + +.social-nav-links { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 6px; + justify-content: flex-end; +} + +.social-nav-link { + min-height: 44px; + padding: 0 10px; + display: inline-flex; + align-items: center; + color: var(--sc-muted); + font-size: 0.88rem; + border-radius: 999px; +} + +.social-nav-link:hover { + color: var(--sc-text); + background: var(--sc-bg-glass); +} + +.social-muted { + color: var(--sc-muted); + font-size: 0.9rem; +} + +.social-list { + display: flex; + flex-direction: column; + gap: 10px; +} + +.social-list-item { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + padding: 16px; + border-radius: var(--sc-radius); + border: var(--sc-border); + background: var(--sc-bg-card); + text-align: left; + width: 100%; +} + +.social-list-item strong { + display: block; + font-family: var(--sc-font-display); +} + +.social-list-item p { + margin: 4px 0 0; + color: var(--sc-muted); + font-size: 0.88rem; +} + +.social-list-item em { + font-style: normal; + color: var(--sc-accent-3); + font-size: 0.85rem; + white-space: nowrap; +} + +.social-list-stack { + flex-direction: column; + align-items: stretch; +} + +.social-card-btn { + cursor: pointer; + font: inherit; + color: inherit; + text-align: left; +} + +.social-card.active, +.social-list-item.active { + border-color: rgba(78, 205, 196, 0.45); + box-shadow: 0 0 0 1px rgba(78, 205, 196, 0.2); +} + +.social-panel { + margin-top: 28px; + padding: 20px; + border-radius: var(--sc-radius); + border: var(--sc-border); + background: var(--sc-bg-card); +} + +.social-panel h2 { + margin: 0 0 8px; + font-family: var(--sc-font-display); + font-size: 1.15rem; +} + +.social-form { + display: grid; + gap: 12px; + margin-top: 12px; +} + +.social-form label { + display: grid; + gap: 6px; + font-size: 0.9rem; + color: var(--sc-muted); +} + +.social-form input, +.social-form textarea, +.social-form select { + width: 100%; + min-height: 44px; + padding: 10px 12px; + border-radius: 12px; + border: var(--sc-border); + background: var(--sc-bg-glass); + color: var(--sc-text); + font: inherit; +} + +.social-form textarea { + min-height: 96px; + resize: vertical; +} + +.social-actions { + display: flex; + flex-wrap: wrap; + gap: 10px; +} + +.social-btn { + min-height: 44px; + padding: 0 16px; + border-radius: 999px; + border: var(--sc-border); + background: var(--sc-bg-glass); + color: var(--sc-text); + font: inherit; + font-weight: 600; + display: inline-flex; + align-items: center; + justify-content: center; + cursor: pointer; +} + +.social-btn.primary { + border: none; + color: #0a0e17; + background: var(--sc-gradient); +} + +.social-chat-head { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 12px 16px; + margin-bottom: 16px; +} + +.social-chat-nick { + margin-bottom: 12px; +} + +.social-chat-nick label { + display: inline-flex; + align-items: center; + gap: 8px; + color: var(--sc-muted); + font-size: 0.9rem; +} + +.social-chat-nick input { + min-height: 40px; + padding: 0 12px; + border-radius: 10px; + border: var(--sc-border); + background: var(--sc-bg-glass); + color: var(--sc-text); +} + +.social-chat-thread { + display: flex; + flex-direction: column; + gap: 10px; + max-height: min(55vh, 520px); + overflow: auto; + padding: 12px; + border-radius: var(--sc-radius); + border: var(--sc-border); + background: rgba(0, 0, 0, 0.15); + margin-bottom: 12px; +} + +.social-bubble { + max-width: min(92%, 520px); + padding: 10px 12px; + border-radius: 14px; + border: var(--sc-border); + background: var(--sc-bg-card); + align-self: flex-start; +} + +.social-bubble.mine { + align-self: flex-end; + background: linear-gradient(160deg, rgba(255, 107, 107, 0.16), rgba(78, 205, 196, 0.1)); +} + +.social-bubble header { + display: flex; + justify-content: space-between; + gap: 12px; + font-size: 0.78rem; + color: var(--sc-muted); + margin-bottom: 4px; +} + +.social-bubble p { + margin: 0; + white-space: pre-wrap; + word-break: break-word; +} + +.social-compose { + display: grid; + grid-template-columns: 1fr auto; + gap: 8px; +} + +.social-compose input { + min-height: 48px; + padding: 0 14px; + border-radius: 14px; + border: var(--sc-border); + background: var(--sc-bg-card); + color: var(--sc-text); + font: inherit; +} + +.social-compose button { + min-height: 48px; + min-width: 88px; + border: none; + border-radius: 14px; + font-weight: 700; + cursor: pointer; + color: #0a0e17; + background: var(--sc-gradient); +} + +/* Immersive Meetup live room — stay in-app, no new tab */ +.social-live-root { + min-height: 100dvh; + display: flex; + flex-direction: column; +} + +.social-live-bar { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 12px; + padding: 12px 16px; + border-bottom: var(--sc-border); + background: color-mix(in srgb, var(--sc-bg) 88%, transparent); + backdrop-filter: blur(14px); +} + +.social-live-bar-main { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 12px; +} + +.social-live-bar-main p { + margin: 2px 0 0; +} + +.social-live-tabs { + display: inline-flex; + gap: 6px; + padding: 4px; + border-radius: 999px; + border: var(--sc-border); + background: var(--sc-bg-glass); +} + +.social-live-tab { + min-height: 40px; + padding: 0 14px; + border: none; + border-radius: 999px; + background: transparent; + color: var(--sc-muted); + font: inherit; + font-weight: 600; + cursor: pointer; +} + +.social-live-tab.active { + color: #0a0e17; + background: var(--sc-gradient); +} + +.social-live-stage { + flex: 1; + min-height: 0; + display: grid; + gap: 0; +} + +.social-live-stage.layout-split { + grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr); +} + +.social-live-stage.layout-video, +.social-live-stage.layout-chat { + grid-template-columns: 1fr; +} + +.social-live-video, +.social-live-chat { + min-height: 0; + display: flex; + flex-direction: column; + border-left: var(--sc-border); +} + +.social-live-video { + border-left: none; + background: #05070c; +} + +.social-live-iframe { + flex: 1; + width: 100%; + min-height: min(70vh, 720px); + border: 0; + background: #000; +} + +.social-live-gate { + flex: 1; + display: grid; + place-content: center; + gap: 12px; + padding: 24px; + text-align: center; +} + +.social-live-gate h2 { + margin: 0; + font-family: var(--sc-font-display); +} + +.social-live-gate p { + margin: 0; + color: var(--sc-muted); +} + +.social-live-gate label { + display: grid; + gap: 6px; + justify-items: center; + color: var(--sc-muted); + font-size: 0.9rem; +} + +.social-live-gate input { + min-height: 44px; + width: min(280px, 100%); + padding: 0 12px; + border-radius: 12px; + border: var(--sc-border); + background: var(--sc-bg-glass); + color: var(--sc-text); +} + +.social-live-chat { + padding: 12px; + background: var(--sc-bg); +} + +.social-live-chat-head { + display: flex; + flex-direction: column; + gap: 2px; + margin-bottom: 10px; +} + +.social-live-thread { + flex: 1; + max-height: none; + min-height: 220px; +} + +@media (max-width: 900px) { + .social-live-stage.layout-split { + grid-template-columns: 1fr; + grid-template-rows: minmax(42vh, 1fr) minmax(38vh, 1fr); + } + + .social-live-chat { + border-left: none; + border-top: var(--sc-border); + } + + .social-live-iframe { + min-height: 42vh; + } +} + +@media (max-width: 640px) { + .social-main { + width: min(100%, calc(100% - 24px)); + padding-top: 28px; + } + + .social-hero { + margin-bottom: 32px; + } + + .social-nav-link { + display: none; + } + + .social-nav-link:nth-child(-n + 2), + .social-nav-back { + display: inline-flex; + } +} diff --git a/src/modules/social/components/ChatListClient.tsx b/src/modules/social/components/ChatListClient.tsx new file mode 100644 index 0000000..bf4f380 --- /dev/null +++ b/src/modules/social/components/ChatListClient.tsx @@ -0,0 +1,33 @@ +"use client"; + +import Link from "next/link"; +import SiteShell from "./SiteShell"; +import { SEED_CHANNELS } from "@social/lib/seed"; +import { socialPath } from "@social/lib/socialPath"; + +export default function ChatListClient() { + return ( + +
+
实时文字
+

+ 聊天室 +
+ 自研频道 · 可扩展小程序 +

+

消息保存在本机(localStorage),不依赖 Lounge / web-view。后续可接 FastAPI + WS。

+
+
+ {SEED_CHANNELS.map((c) => ( + +
+ {c.name} +

{c.topic}

+
+ {c.members} 人 + + ))} +
+
+ ); +} diff --git a/src/modules/social/components/ChatRoomClient.tsx b/src/modules/social/components/ChatRoomClient.tsx new file mode 100644 index 0000000..afc0c9f --- /dev/null +++ b/src/modules/social/components/ChatRoomClient.tsx @@ -0,0 +1,153 @@ +"use client"; + +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import Link from "next/link"; +import SiteShell from "./SiteShell"; +import { socialApi } from "@social/lib/api"; +import { SEED_CHANNELS, SEED_MESSAGES } from "@social/lib/seed"; +import { loadJson, saveJson } from "@social/lib/storage"; +import type { SocialChatMessage } from "@social/lib/types"; +import { socialPath } from "@social/lib/socialPath"; + +export default function ChatRoomClient({ channelId }: { channelId: string }) { + const channel = SEED_CHANNELS.find((c) => c.id === channelId) || SEED_CHANNELS[0]; + const storageKey = `chat:${channel.id}`; + const [messages, setMessages] = useState([]); + const [text, setText] = useState(""); + const [nick, setNick] = useState("游民"); + const [online, setOnline] = useState(true); + const [sending, setSending] = useState(false); + const bottomRef = useRef(null); + + const seedForRoom = useMemo( + () => SEED_MESSAGES.filter((m) => m.channelId === channel.id), + [channel.id], + ); + + const refresh = useCallback(async () => { + try { + const res = await socialApi.listMessages(channel.id); + const items = (res.items || []).map((m) => ({ + id: m.id, + channelId: m.channelId, + author: m.author, + text: m.text, + at: m.at, + })); + if (items.length) { + setMessages(items); + saveJson(storageKey, items); + } else { + const local = loadJson(storageKey, seedForRoom); + setMessages(local); + } + setOnline(true); + } catch { + setOnline(false); + setMessages(loadJson(storageKey, seedForRoom)); + } + }, [channel.id, seedForRoom, storageKey]); + + useEffect(() => { + setNick(loadJson("nick", "游民")); + void refresh(); + const id = window.setInterval(() => void refresh(), 4000); + return () => clearInterval(id); + }, [refresh]); + + useEffect(() => { + bottomRef.current?.scrollIntoView({ behavior: "smooth" }); + }, [messages]); + + const send = async () => { + const body = text.trim(); + if (!body || sending) return; + setSending(true); + const author = nick.trim() || "游民"; + try { + const saved = await socialApi.sendMessage(channel.id, author, body); + setText(""); + saveJson("nick", author); + await refresh(); + if (!saved?.id) { + /* refresh already applied */ + } + setOnline(true); + } catch { + setOnline(false); + const next: SocialChatMessage = { + id: `local_${Date.now()}`, + channelId: channel.id, + author, + text: body, + at: new Date().toISOString(), + mine: true, + }; + const merged = [...messages, next]; + setMessages(merged); + saveJson(storageKey, merged); + saveJson("nick", author); + setText(""); + } finally { + setSending(false); + } + }; + + return ( + +
+ + ← 频道列表 + +
+ {channel.name} +

+ {channel.topic} + {" · "} + {online ? "已同步服务器" : "离线本地模式"} +

+
+
+ +
+ +
+ +
+ {messages.map((m) => ( +
+
+ {m.author} + +
+

{m.text}

+
+ ))} +
+
+ +
+ setText(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") void send(); + }} + placeholder="说点什么…" + aria-label="消息内容" + /> + +
+ + ); +} diff --git a/src/modules/social/components/CoffeechatClient.tsx b/src/modules/social/components/CoffeechatClient.tsx new file mode 100644 index 0000000..23a05bc --- /dev/null +++ b/src/modules/social/components/CoffeechatClient.tsx @@ -0,0 +1,190 @@ +"use client"; + +import { useCallback, useEffect, useState } from "react"; +import SiteShell from "./SiteShell"; +import { socialApi } from "@social/lib/api"; +import { SEED_CAFES } from "@social/lib/seed"; +import { loadJson, saveJson } from "@social/lib/storage"; +import type { SocialCafeReview } from "@social/lib/types"; + +export default function CoffeechatClient() { + const [cafeId, setCafeId] = useState(SEED_CAFES[0]?.id || ""); + const [reviews, setReviews] = useState([]); + const [author, setAuthor] = useState("游民"); + const [score, setScore] = useState(5); + const [text, setText] = useState(""); + const [photoNote, setPhotoNote] = useState(""); + const [online, setOnline] = useState(true); + const [busy, setBusy] = useState(false); + + const cafe = SEED_CAFES.find((c) => c.id === cafeId) || SEED_CAFES[0]; + const cacheKey = `cafe-reviews:${cafeId}`; + + const refresh = useCallback(async () => { + if (!cafeId) return; + try { + const res = await socialApi.listReviews(cafeId); + const items = (res.items || []).map((r) => ({ + id: r.id, + cafeId: r.cafeId, + author: r.author, + score: r.score, + text: r.text, + photoNote: r.photoNote, + at: r.at, + })); + setReviews(items); + saveJson(cacheKey, items); + setOnline(true); + } catch { + setOnline(false); + setReviews(loadJson(cacheKey, [])); + } + }, [cafeId, cacheKey]); + + useEffect(() => { + setAuthor(loadJson("nick", "游民")); + void refresh(); + }, [refresh]); + + const submit = async () => { + if (!cafe || !text.trim() || busy) return; + setBusy(true); + const payload = { + author: author.trim() || "游民", + score, + text: text.trim(), + photoNote: photoNote.trim(), + }; + try { + await socialApi.postReview(cafe.id, payload); + saveJson("nick", payload.author); + setText(""); + setPhotoNote(""); + setOnline(true); + await refresh(); + } catch { + setOnline(false); + const item: SocialCafeReview = { + id: `local_${Date.now()}`, + cafeId: cafe.id, + ...payload, + at: new Date().toISOString(), + }; + const next = [item, ...reviews]; + setReviews(next); + saveJson(cacheKey, next); + saveJson("nick", payload.author); + setText(""); + setPhotoNote(""); + } finally { + setBusy(false); + } + }; + + return ( + +
+
线下 · 咖啡馆
+

+ Coffeechat +
+ 合作店 · 评价 · 合照备注 +

+

+ 评价写入独立 social 库(与旅居社群数据隔离)。 + {online ? " 当前已连后端。" : " 后端不可用时先存本机。"} +

+
+ +
+ {SEED_CAFES.map((c) => ( + + ))} +
+ + {cafe ? ( +
+

{cafe.name}

+

+ {cafe.vibe} · 电源:{cafe.power} · 评价 {reviews.length} 条 +

+ +
+ + +