diff --git a/apps/admin/src/pages/SocialData.tsx b/apps/admin/src/pages/SocialData.tsx index 87987ca..e591029 100644 --- a/apps/admin/src/pages/SocialData.tsx +++ b/apps/admin/src/pages/SocialData.tsx @@ -385,6 +385,18 @@ export default function SocialData() { {it.contact}
{cell(it.note, 80)}
+ {it.resumeUrl ? ( +
+ + 📎 {String(it.resumeName || '简历附件')} + +
+ ) : null} {it.at} diff --git a/apps/api/services/nomadro_pb/schemas.py b/apps/api/services/nomadro_pb/schemas.py index 4ffb24f..dd82dc0 100644 --- a/apps/api/services/nomadro_pb/schemas.py +++ b/apps/api/services/nomadro_pb/schemas.py @@ -309,6 +309,8 @@ SOCIAL_GIG_APPS = _base( _text("name"), _text("contact"), _text("note"), + _text("resume_url"), + _text("resume_name"), _text("request_id"), _text("created_at", True), ], diff --git a/apps/api/services/social_svc/pb_data.py b/apps/api/services/social_svc/pb_data.py index 730fa72..d5cf0e6 100644 --- a/apps/api/services/social_svc/pb_data.py +++ b/apps/api/services/social_svc/pb_data.py @@ -1798,6 +1798,9 @@ def add_gig_app( note: str, guest_id: str, request_id: str | None = None, + *, + resume_url: str = "", + resume_name: str = "", ) -> dict[str, Any]: import hashlib import json as _json @@ -1812,12 +1815,16 @@ def add_gig_app( _json.dumps([guest_id, gig_id, request_id]).encode() ).hexdigest()[:32] ) + resume_u = (resume_url or "").strip()[:800] + resume_n = (resume_name or "").strip()[:200] body = { "gig_id": gig_id, "guest_id": guest_id, "name": (name or "").strip()[:64], "contact": (contact or "").strip()[:120], "note": (note or "").strip()[:2000], + "resume_url": resume_u, + "resume_name": resume_n, "request_id": request_id or "", "created_at": now, } @@ -1828,10 +1835,21 @@ def add_gig_app( filter=f"request_id={pb_quote(request_id or '')} && guest_id={pb_quote(guest_id)} && gig_id={pb_quote(gig_id)}", ) if existing: - if ( - (existing.get("name"), existing.get("contact"), existing.get("note")) - != (body["name"], body["contact"], body["note"]) - ): + prev = ( + existing.get("name"), + existing.get("contact"), + existing.get("note") or "", + existing.get("resume_url") or "", + existing.get("resume_name") or "", + ) + cur = ( + body["name"], + body["contact"], + body["note"], + body["resume_url"], + body["resume_name"], + ) + if prev != cur: raise ValueError("同一请求标识不能用于不同申请") return { "id": existing.get("id"), @@ -1839,6 +1857,8 @@ def add_gig_app( "name": existing.get("name"), "contact": existing.get("contact"), "note": existing.get("note") or "", + "resumeUrl": existing.get("resume_url") or "", + "resumeName": existing.get("resume_name") or "", "guestId": guest_id, "at": existing.get("created_at") or now, } @@ -1849,6 +1869,8 @@ def add_gig_app( "name": body["name"], "contact": body["contact"], "note": body["note"], + "resumeUrl": body["resume_url"], + "resumeName": body["resume_name"], "guestId": guest_id, "at": now, } @@ -2087,6 +2109,8 @@ def admin_list_gig_apps( "name": r.get("name"), "contact": r.get("contact"), "note": r.get("note") or "", + "resumeUrl": r.get("resume_url") or "", + "resumeName": r.get("resume_name") or "", "guestId": r.get("guest_id"), "at": r.get("created_at"), } diff --git a/apps/api/services/social_svc/routers/api.py b/apps/api/services/social_svc/routers/api.py index 2343ed1..1f53140 100644 --- a/apps/api/services/social_svc/routers/api.py +++ b/apps/api/services/social_svc/routers/api.py @@ -145,6 +145,8 @@ 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) + resumeUrl: str = Field(default="", max_length=800) + resumeName: str = Field(default="", max_length=200) requestId: str | None = Field(default=None, min_length=1, max_length=80) @@ -423,19 +425,65 @@ async def upload_media( x_social_guest_id: str | None = Header(default=None), guest: str | None = Query(default=None), ): - """Guest-friendly image upload → SeaweedFS S3 (fallback local). + """Guest-friendly upload → SeaweedFS S3 (fallback local). - Avatar / roster / profile: optional face presence gate (InsightFace → OpenCV). + - purpose=avatar|roster|profile: image + optional face gate + - purpose=resume|cv|gig-resume: PDF/DOC/DOCX/图片简历,跳过人脸检测 """ peer = _guest(x_social_guest_id, guest) + purpose_norm = (purpose or "avatar")[:40] + is_resume = purpose_norm.lower() in {"resume", "cv", "gig-resume"} ctype = (file.content_type or "").lower() - if not ctype.startswith("image/"): - raise HTTPException(status_code=400, detail="仅支持图片") raw = await file.read() if not raw: raise HTTPException(status_code=400, detail="空文件") + + if is_resume: + name = (file.filename or "resume.pdf").strip() or "resume.pdf" + suffix = ("." + name.rsplit(".", 1)[-1].lower()) if "." in name else "" + ok_suffix = {".pdf", ".doc", ".docx", ".txt", ".rtf", ".png", ".jpg", ".jpeg", ".webp"} + if suffix and suffix not in ok_suffix and not ctype.startswith("image/"): + raise HTTPException( + status_code=400, + detail="简历仅支持 PDF / Word / 图片", + ) + max_bytes = min(SOCIAL_UPLOAD_MAX_BYTES, 10 * 1024 * 1024) + + def persist_resume(): + from social_svc.s3_upload import upload_bytes + + return upload_bytes( + raw, + filename=name, + content_type=file.content_type or "application/octet-stream", + purpose="resume", + guest_id=peer, + max_size=max_bytes, + ) + + try: + result = await run_in_threadpool(persist_resume) + except ValueError as exc: + raise HTTPException(status_code=400, detail=str(exc)) from exc + except Exception as exc: + raise HTTPException(status_code=503, detail=f"上传失败: {exc}") from exc + return { + "ok": True, + "success": True, + "url": result.url, + "object_key": result.object_key, + "size": result.size, + "content_type": result.content_type, + "storage": result.storage, + "name": name[:200], + "faceOk": False, + "faceCheckEnabled": False, + "livenessRequired": False, + } + + if not ctype.startswith("image/"): + raise HTTPException(status_code=400, detail="仅支持图片") max_avatar = min(SOCIAL_UPLOAD_MAX_BYTES, 8 * 1024 * 1024) - purpose_norm = (purpose or "avatar")[:40] def persist(): from social_svc.face_check import ( @@ -660,6 +708,20 @@ def get_local_liveness(name: str): return FileResponse(path) +@router.get("/files/resume/{name}") +def get_local_resume(name: str): + """Serve locally-fallback resume attachments when S3 is unavailable.""" + from social_svc.config import SOCIAL_UPLOAD_DIR + + safe = Path(name).name + if safe != name or ".." in name: + raise HTTPException(status_code=400, detail="非法文件名") + path = SOCIAL_UPLOAD_DIR / "resumes" / safe + if not path.is_file(): + raise HTTPException(status_code=404, detail="not found") + return FileResponse(path) + + @router.get("/liveness/audits") def liveness_audits( status: str = Query(default=""), @@ -1100,7 +1162,16 @@ def post_gig_apply( raise HTTPException(status_code=400, detail="请填写称呼和联系方式") store.init_db() try: - return store.add_gig_app(gig_id, body.name, body.contact, body.note, guest, body.requestId) + return store.add_gig_app( + gig_id, + body.name, + body.contact, + body.note, + guest, + body.requestId, + resume_url=body.resumeUrl, + resume_name=body.resumeName, + ) except ValueError as exc: raise HTTPException(status_code=409, detail=str(exc)) from exc diff --git a/apps/api/services/social_svc/s3_upload.py b/apps/api/services/social_svc/s3_upload.py index 3642302..c56dc7f 100644 --- a/apps/api/services/social_svc/s3_upload.py +++ b/apps/api/services/social_svc/s3_upload.py @@ -63,6 +63,24 @@ def _client(): return _boto +_RESUME_SUFFIX = {".pdf", ".doc", ".docx", ".txt", ".rtf", ".png", ".jpg", ".jpeg", ".webp"} +_RESUME_MIME = { + ".pdf": "application/pdf", + ".doc": "application/msword", + ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ".txt": "text/plain", + ".rtf": "application/rtf", + ".png": "image/png", + ".jpg": "image/jpeg", + ".jpeg": "image/jpeg", + ".webp": "image/webp", +} + + +def _allow_resume(purpose: str) -> bool: + return (purpose or "").strip().lower() in {"resume", "cv", "gig-resume"} + + def _object_key(filename: str, purpose: str, guest_id: str) -> str: suffix = Path(filename or "upload.bin").suffix.lower() or ".jpg" img_ok = {".jpg", ".jpeg", ".png", ".webp", ".gif"} @@ -73,12 +91,17 @@ def _object_key(filename: str, purpose: str, guest_id: str) -> str: "room-archive", "meetup-archive", } + allow_resume = _allow_resume(purpose) if suffix in img_ok: pass + elif allow_resume and suffix in _RESUME_SUFFIX: + pass elif allow_video and suffix in vid_ok: pass elif allow_video: suffix = ".webm" + elif allow_resume: + suffix = ".pdf" else: suffix = ".jpg" day = datetime.now(timezone.utc).strftime("%Y/%m/%d") @@ -119,9 +142,25 @@ def upload_bytes( "room-archive", "meetup-archive", } + allow_resume = _allow_resume(purpose) # Browser FormData Blob parts often arrive as application/octet-stream if ctype.startswith("image/"): pass + elif allow_resume and ( + suffix in _RESUME_SUFFIX + or ctype in { + "application/pdf", + "application/msword", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "application/rtf", + "text/plain", + "application/octet-stream", + } + ): + if suffix not in _RESUME_SUFFIX: + # octet-stream without extension → treat as pdf + suffix = ".pdf" + ctype = _RESUME_MIME.get(suffix) or guessed or "application/pdf" elif allow_video and ( ctype.startswith("video/") or suffix in {".webm", ".mp4", ".mov", ".mkv"} @@ -139,7 +178,11 @@ def upload_bytes( "image/jpeg" if suffix in {".jpg", ".jpeg", ""} else f"image/{suffix[1:]}" ) else: - raise ValueError("only images allowed" if not allow_video else "only images/videos allowed") + raise ValueError( + "only resume files allowed" + if allow_resume + else ("only images allowed" if not allow_video else "only images/videos allowed") + ) key = _object_key(filename, purpose, guest_id) @@ -162,21 +205,27 @@ def upload_bytes( # Local fallback (dev / S3 off / S3 error) # Live audit assets never land in avatars/ - sub = ( - "room-archive" - if (purpose or "") in {"room-archive", "meetup-archive"} - else ( - "liveness" - if allow_video - or ctype.startswith("video/") - or (purpose or "").startswith("liveness") - else "avatars" - ) - ) + if (purpose or "") in {"room-archive", "meetup-archive"}: + sub = "room-archive" + elif allow_resume: + sub = "resumes" + elif ( + allow_video + or ctype.startswith("video/") + or (purpose or "").startswith("liveness") + ): + sub = "liveness" + else: + sub = "avatars" path = SOCIAL_UPLOAD_DIR / sub / Path(key).name path.parent.mkdir(parents=True, exist_ok=True) path.write_bytes(data) - route = "liveness" if sub == "liveness" else "avatar" + if sub == "liveness": + route = "liveness" + elif sub == "resumes": + route = "resume" + else: + route = "avatar" return UploadResult( url=f"/api/social/v1/files/{route}/{path.name}", object_key=str(path), diff --git a/apps/api/services/social_svc/store.py b/apps/api/services/social_svc/store.py index c8dd106..584112d 100644 --- a/apps/api/services/social_svc/store.py +++ b/apps/api/services/social_svc/store.py @@ -1053,10 +1053,22 @@ def add_gig_app( note: str, guest_id: str, request_id: str | None = None, + *, + resume_url: str = "", + resume_name: str = "", ) -> dict[str, Any]: from social_svc import pb_data - return pb_data.add_gig_app(gig_id, name, contact, note, guest_id, request_id) + return pb_data.add_gig_app( + gig_id, + name, + contact, + note, + guest_id, + request_id, + resume_url=resume_url, + resume_name=resume_name, + ) def health() -> dict[str, Any]: diff --git a/src/modules/social/app/depth.css b/src/modules/social/app/depth.css index ec3a135..c3cbde2 100644 --- a/src/modules/social/app/depth.css +++ b/src/modules/social/app/depth.css @@ -1509,6 +1509,55 @@ html[data-theme="light"] .social-ambient { font-style: normal; font-weight: 650; } +.social-apply-resume-tag { + display: inline-flex; + align-items: center; + gap: 4px; + font-size: 12px; + color: var(--text-secondary, #94a3b8); +} +.social-apply-resume { + display: grid; + gap: 8px; + padding: 12px; + border-radius: 14px; + border: 1px dashed color-mix(in srgb, #fff 16%, transparent); + background: color-mix(in srgb, #fff 4%, transparent); +} +.social-apply-resume-label { + display: inline-flex; + align-items: center; + gap: 6px; + font-size: 13px; + font-weight: 650; +} +.social-apply-resume-input { + position: absolute; + width: 1px; + height: 1px; + opacity: 0; + pointer-events: none; +} +.social-apply-resume-file { + display: flex; + align-items: center; + gap: 8px; + flex-wrap: wrap; +} +.social-apply-resume-file a { + display: inline-flex; + align-items: center; + gap: 6px; + min-height: 40px; + color: #5ce1d6; + text-decoration: none; + font-size: 13px; + font-weight: 600; + word-break: break-all; +} +.social-apply-resume-file a:hover { + text-decoration: underline; +} .social-contribute-btn { margin-left: auto; } diff --git a/src/modules/social/components/RoleBoard.tsx b/src/modules/social/components/RoleBoard.tsx index 8612519..1c2ef13 100644 --- a/src/modules/social/components/RoleBoard.tsx +++ b/src/modules/social/components/RoleBoard.tsx @@ -1,17 +1,26 @@ "use client"; -import { useMemo, useRef, useState, type FormEvent } from "react"; +import { + useEffect, + useMemo, + useRef, + useState, + type FormEvent, +} from "react"; import Link from "next/link"; import { ArrowUpRight, BookOpen, BriefcaseBusiness, Check, + FileUp, Globe2, HeartHandshake, MapPin, + Paperclip, Send, Sparkles, + X, } from "lucide-react"; import SiteShell from "./SiteShell"; import { @@ -31,6 +40,10 @@ import { socialTx } from "@social/lib/socialTx"; import { useSocialI18n } from "@social/lib/useSocialI18n"; import { txGig } from "@social/lib/localizeEntity"; +const RESUME_ACCEPT = + ".pdf,.doc,.docx,.txt,.rtf,image/png,image/jpeg,image/webp,application/pdf"; +const RESUME_MAX_BYTES = 10 * 1024 * 1024; + const NOTE_PROMPTS = [ "做过类似项目…", "每周可投入…", @@ -49,6 +62,8 @@ function ApplicationForm({ gig }: { gig: SocialGig }) { name: "", contact: "", note: "", + resumeUrl: "", + resumeName: "", }); const [delivery, setDelivery] = useLocalState( `gig-delivery:${gig.id}`, @@ -56,21 +71,64 @@ function ApplicationForm({ gig }: { gig: SocialGig }) { ); const [status, setStatus] = useState(""); const [busy, setBusy] = useState(false); + const [uploading, setUploading] = useState(false); const lock = useRef(false); + const fileRef = useRef(null); const filled = Number(Boolean(draft.name.trim())) + Number(Boolean(draft.contact.trim())) + - Number(Boolean(draft.note.trim())); + Number(Boolean(draft.note.trim())) + + Number(Boolean((draft.resumeUrl || "").trim())); const update = (key: keyof typeof draft, value: string) => { setDraft((current) => ({ ...current, [key]: value })); setDelivery("draft"); setStatus(""); }; + const clearResume = () => { + setDraft((current) => ({ + ...current, + resumeUrl: "", + resumeName: "", + })); + setDelivery("draft"); + if (fileRef.current) fileRef.current.value = ""; + }; + const onPickResume = async (file: File | null) => { + if (!file || uploading || busy) return; + if (file.size > RESUME_MAX_BYTES) { + setStatus(socialTx("简历请小于 10MB")); + return; + } + setUploading(true); + setStatus(""); + try { + const uploaded = await socialApi.uploadResume(file); + if (!uploaded?.url) throw new Error("no url"); + setDraft((current) => ({ + ...current, + resumeUrl: uploaded.url, + resumeName: (uploaded.name || file.name).slice(0, 200), + })); + setDelivery("draft"); + setStatus(socialTx("简历已上传,可以提交申请了")); + } catch (err) { + const msg = err instanceof Error ? err.message : ""; + setStatus( + msg && !/^upload failed|^上传失败/i.test(msg) + ? msg + : socialTx("简历上传失败,请重试"), + ); + } finally { + setUploading(false); + if (fileRef.current) fileRef.current.value = ""; + } + }; const submit = async (event: FormEvent) => { event.preventDefault(); if ( lock.current || delivery === "sent" || + uploading || !draft.name.trim() || !draft.contact.trim() ) @@ -82,6 +140,8 @@ function ApplicationForm({ gig }: { gig: SocialGig }) { name: draft.name.trim(), contact: draft.contact.trim(), note: draft.note.trim(), + resumeUrl: (draft.resumeUrl || "").trim(), + resumeName: (draft.resumeName || "").trim(), }); setDelivery("sent"); setStatus("申请已提交。对方看到后会再联系你——先不急。"); @@ -105,6 +165,11 @@ function ApplicationForm({ gig }: { gig: SocialGig }) {
{socialTx(gig.title)} {socialTx(TEAM_KIND_LABEL[gig.kind || "parttime"])} + {draft.resumeName ? ( + + {draft.resumeName} + + ) : null}
@@ -148,17 +213,17 @@ function ApplicationForm({ gig }: { gig: SocialGig }) {
- + {filled === 0 ? socialTx("先简单介绍自己") - : filled < 3 - ? socialTx(`还差 ${3 - filled} 项(简介可选)`) - : socialTx("可以提交了")} + : filled < 2 + ? socialTx("还差称呼和联系方式") + : socialTx("可以提交了(简历可选)")}
@@ -166,7 +231,7 @@ function ApplicationForm({ gig }: { gig: SocialGig }) { className="social-form social-apply-form" onSubmit={(e) => void submit(e)} > -
+
+ +
+ + + {socialTx("上传简历(可选)")} + +

+ {socialTx("支持 PDF / Word / 图片,最大 10MB")} +

+ + void onPickResume(event.target.files?.[0] || null) + } + /> + {draft.resumeUrl ? ( + + ) : ( + + )} +