mirror of
https://github.com/MatrixSeven/file-transfer-go.git
synced 2026-05-23 14:47:36 +08:00
1 line
71 KiB
JavaScript
1 line
71 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{409:(e,t,s)=>{Promise.resolve().then(s.bind(s,5055))},5055:(e,t,s)=>{"use strict";s.d(t,{default:()=>eo});var a=s(5155),l=s(2115),r=s(5695),i=s(888),n=s(2596),o=s(9688);function c(){for(var e=arguments.length,t=Array(e),s=0;s<e;s++)t[s]=arguments[s];return(0,o.QP)((0,n.$)(t))}let d=i.bL,m=l.forwardRef((e,t)=>{let{className:s,...l}=e;return(0,a.jsx)(i.B8,{ref:t,className:c("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",s),...l})});m.displayName=i.B8.displayName;let x=l.forwardRef((e,t)=>{let{className:s,...l}=e;return(0,a.jsx)(i.l9,{ref:t,className:c("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",s),...l})});x.displayName=i.l9.displayName;let u=l.forwardRef((e,t)=>{let{className:s,...l}=e;return(0,a.jsx)(i.UC,{ref:t,className:c("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...l})});u.displayName=i.UC.displayName;var h=s(3470),p=s(4416);let f=h.bL;h.l9;let g=h.ZL;h.bm;let b=l.forwardRef((e,t)=>{let{className:s,...l}=e;return(0,a.jsx)(h.hJ,{ref:t,className:c("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...l})});b.displayName=h.hJ.displayName;let v=l.forwardRef((e,t)=>{let{className:s,children:l,...r}=e;return(0,a.jsxs)(g,{children:[(0,a.jsx)(b,{}),(0,a.jsxs)(h.UC,{ref:t,className:c("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...r,children:[l,(0,a.jsxs)(h.bm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,a.jsx)(p.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});v.displayName=h.UC.displayName;let j=e=>{let{className:t,...s}=e;return(0,a.jsx)("div",{className:c("flex flex-col space-y-1.5 text-center sm:text-left",t),...s})};j.displayName="DialogHeader";let w=e=>{let{className:t,...s}=e;return(0,a.jsx)("div",{className:c("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s})};w.displayName="DialogFooter";let N=l.forwardRef((e,t)=>{let{className:s,...l}=e;return(0,a.jsx)(h.hE,{ref:t,className:c("text-lg font-semibold leading-none tracking-tight",s),...l})});N.displayName=h.hE.displayName;let y=l.forwardRef((e,t)=>{let{className:s,...l}=e;return(0,a.jsx)(h.VY,{ref:t,className:c("text-sm text-muted-foreground",s),...l})});y.displayName=h.VY.displayName;var k=s(9708);let C=(0,s(2085).F)("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),S=l.forwardRef((e,t)=>{let{className:s,variant:l,size:r,asChild:i=!1,...n}=e,o=i?k.DX:"button";return(0,a.jsx)(o,{className:c(C({variant:l,size:r,className:s})),ref:t,...n})});S.displayName="Button";var A=s(9099);function z(){return(0,a.jsxs)("div",{className:"text-center mb-8 sm:mb-12 animate-fade-in-up",children:[(0,a.jsx)("h1",{className:"text-3xl sm:text-4xl md:text-5xl font-bold bg-gradient-to-r from-blue-600 via-purple-600 to-indigo-600 bg-clip-text text-transparent mb-4",children:"文件快传"}),(0,a.jsxs)("p",{className:"text-base sm:text-lg text-slate-600 max-w-2xl mx-auto leading-relaxed px-4 mb-4",children:["安全、快速、简单的传输服务",(0,a.jsx)("br",{}),(0,a.jsx)("span",{className:"text-sm sm:text-base text-slate-500",children:"支持文件、文字、桌面共享 - 无需注册,即传即用"})]}),(0,a.jsxs)("div",{className:"flex flex-col items-center space-y-2",children:[(0,a.jsxs)("a",{href:"https://github.com/MatrixSeven/file-transfer-go",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center space-x-2 px-4 py-2 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm rounded-lg transition-all duration-200 hover:scale-105 transform border border-slate-200 hover:border-slate-300",children:[(0,a.jsx)(A.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{children:"开源项目"})]}),(0,a.jsx)("a",{href:"https://github.com/MatrixSeven/file-transfer-go",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-slate-400 font-mono hover:text-slate-600 transition-colors duration-200 hover:underline",children:"https://github.com/MatrixSeven/file-transfer-go"})]})]})}var E=s(9869),R=s(1788),_=s(7213),F=s(9803),L=s(227),T=s(9022),D=s(7434);function U(e){let{selectedFiles:t,onFilesChange:s,onGenerateCode:r,pickupCode:i,pickupLink:n,onCopyCode:o,onCopyLink:c,onAddMoreFiles:d,onRemoveFile:m,onClearFiles:x,onReset:u,disabled:h=!1}=e,[f,g]=(0,l.useState)(!1),b=(0,l.useRef)(null),v=(0,l.useCallback)(e=>{e.preventDefault(),g(!0)},[]),j=(0,l.useCallback)(e=>{e.preventDefault(),e.currentTarget.contains(e.relatedTarget)||g(!1)},[]),w=(0,l.useCallback)(e=>{e.preventDefault(),g(!1);let a=Array.from(e.dataTransfer.files);a.length>0&&s([...t,...a])},[t,s]),N=(0,l.useCallback)(e=>{let a=Array.from(e.target.files||[]);a.length>0&&s([...t,...a])},[t,s]),y=(0,l.useCallback)(e=>{let a=t.filter((t,s)=>s!==e);s(a),m&&m(a)},[t,s,m]),k=(0,l.useCallback)(()=>{b.current&&b.current.click()},[]);return 0!==t.length||i?(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 animate-fade-in-up",children:[(0,a.jsx)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between mb-4 sm:mb-6 gap-4",children:(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(D.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg sm:text-xl font-semibold text-slate-800",children:"已选择文件"}),(0,a.jsxs)("p",{className:"text-slate-500 text-sm",children:[t.length," 个文件准备传输"]})]})]})}),(0,a.jsx)("div",{className:"space-y-3 mb-4 sm:mb-6",children:t.map((e,t)=>{var s;return(0,a.jsxs)("div",{className:"group flex items-center justify-between p-3 sm:p-4 bg-gradient-to-r from-slate-50 to-blue-50 border border-slate-200 rounded-xl hover:shadow-md transition-all duration-200",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 sm:space-x-4 min-w-0 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 sm:w-12 sm:h-12 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-lg flex items-center justify-center flex-shrink-0",children:(s=e.type).startsWith("image/")?(0,a.jsx)(_.A,{className:"w-5 h-5 text-white"}):s.startsWith("video/")?(0,a.jsx)(F.A,{className:"w-5 h-5 text-white"}):s.startsWith("audio/")?(0,a.jsx)(L.A,{className:"w-5 h-5 text-white"}):s.includes("zip")||s.includes("rar")?(0,a.jsx)(T.A,{className:"w-5 h-5 text-white"}):(0,a.jsx)(D.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-slate-800 truncate text-sm sm:text-base",children:e.name}),(0,a.jsx)("p",{className:"text-xs sm:text-sm text-slate-500",children:(e=>{if(0===e)return"0 Bytes";let t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]})(e.size)})]})]}),(0,a.jsx)(S,{variant:"ghost",size:"sm",onClick:()=>y(t),disabled:h,className:"opacity-0 group-hover:opacity-100 text-slate-400 hover:text-red-500 hover:bg-red-50 transition-all duration-200 flex-shrink-0 ml-2",children:(0,a.jsx)(p.A,{className:"w-4 h-4"})})]},"".concat(e.name,"-").concat(e.size,"-").concat(t))})}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[!i&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(S,{onClick:r,disabled:h||0===t.length,className:"button-primary text-white px-6 sm:px-8 py-3 rounded-xl font-medium flex-1 min-w-0 shadow-lg",children:[(0,a.jsx)(E.A,{className:"w-5 h-5 mr-2"}),"生成取件码"]}),(0,a.jsx)(S,{onClick:d,variant:"outline",disabled:h,className:"px-6 sm:px-8 py-3 rounded-xl font-medium",children:"添加文件"}),(0,a.jsx)(S,{onClick:u,variant:"outline",disabled:h,className:"text-red-600 hover:bg-red-50 px-6 sm:px-8 py-3 rounded-xl font-medium",children:"重新选择"})]}),i&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(S,{variant:"outline",onClick:d,disabled:h,className:"px-6 py-3 rounded-xl border-slate-300 text-slate-600 hover:bg-slate-50 flex-1",children:"添加更多文件"}),t.length>0&&x&&(0,a.jsx)(S,{variant:"outline",onClick:x,disabled:h,className:"px-6 py-3 rounded-xl border-orange-300 text-orange-600 hover:bg-orange-50",children:"清空文件"})]}),(0,a.jsx)(S,{variant:"outline",onClick:u,disabled:h,className:"px-6 py-3 rounded-xl border-red-300 text-red-600 hover:bg-red-50",children:"关闭房间"})]})]}),i&&(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 md:p-8 animate-fade-in-up",children:[(0,a.jsxs)("div",{className:"text-center mb-4 sm:mb-6",children:[(0,a.jsx)("div",{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-4 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)(D.A,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),(0,a.jsx)("h3",{className:"text-xl sm:text-2xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent mb-2",children:"取件码生成成功!"}),(0,a.jsx)("p",{className:"text-sm sm:text-base text-slate-600",children:"分享以下信息给接收方"})]}),(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-3",children:"取件码"}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,a.jsx)("div",{className:"flex-1 code-display rounded-xl p-4 sm:p-6 text-center",children:(0,a.jsx)("div",{className:"text-2xl sm:text-3xl font-bold font-mono bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent tracking-wider",children:i})}),(0,a.jsx)(S,{onClick:o,className:"px-4 sm:px-6 py-3 bg-emerald-500 hover:bg-emerald-600 text-white rounded-xl font-medium shadow-lg transition-all duration-200 hover:shadow-xl w-full sm:w-auto",children:"复制"})]})]}),n&&(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-3",children:"取件链接"}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,a.jsx)("div",{className:"flex-1 code-display rounded-xl p-3 sm:p-4",children:(0,a.jsx)("div",{className:"text-xs sm:text-sm text-slate-700 break-all font-mono",children:n})}),(0,a.jsx)(S,{onClick:c,className:"px-4 sm:px-6 py-3 bg-blue-500 hover:bg-blue-600 text-white rounded-xl font-medium shadow-lg transition-all duration-200 hover:shadow-xl w-full sm:w-auto",children:"复制"})]})]})]}),(0,a.jsx)("div",{className:"mt-4 sm:mt-6 p-3 sm:p-4 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl border border-blue-200",children:(0,a.jsxs)("p",{className:"text-xs sm:text-sm text-slate-600 text-center",children:["\uD83D\uDCA1 ",(0,a.jsx)("span",{className:"font-medium",children:"使用提示:"}),"接收方输入取件码或访问取件链接即可下载文件"]})})]})]}):(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"w-16 h-16 mx-auto mb-4 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)(E.A,{className:"w-8 h-8 text-white"})}),(0,a.jsx)("h2",{className:"text-2xl font-semibold text-slate-800 mb-2",children:"选择文件"}),(0,a.jsx)("p",{className:"text-slate-600",children:"拖拽文件到下方区域或点击选择文件"})]}),(0,a.jsxs)("div",{className:"upload-area rounded-xl p-6 sm:p-8 md:p-12 text-center cursor-pointer ".concat(f?"drag-active":""),onDragOver:v,onDragLeave:j,onDrop:w,onClick:k,children:[(0,a.jsxs)("div",{className:"transition-all duration-300 ".concat(f?"scale-110":""),children:[(0,a.jsx)("div",{className:"w-16 h-16 sm:w-20 sm:h-20 mx-auto mb-4 sm:mb-6 bg-gradient-to-br from-blue-100 to-indigo-100 rounded-full flex items-center justify-center",children:(0,a.jsx)(E.A,{className:"w-8 h-8 sm:w-10 sm:h-10 transition-colors duration-300 ".concat(f?"text-blue-600":"text-slate-400")})}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("p",{className:"text-lg sm:text-xl font-medium text-slate-700",children:f?"释放文件":"拖拽文件到这里"}),(0,a.jsxs)("p",{className:"text-sm sm:text-base text-slate-500",children:["或者 ",(0,a.jsx)("span",{className:"text-blue-600 font-medium underline",children:"点击选择文件"})]}),(0,a.jsx)("p",{className:"text-xs sm:text-sm text-slate-400 mt-4",children:"支持多个文件同时上传,无大小限制"})]})]}),(0,a.jsx)("input",{ref:b,type:"file",multiple:!0,className:"hidden",onChange:N,disabled:h})]})]})}let P=l.forwardRef((e,t)=>{let{className:s,type:l,...r}=e;return(0,a.jsx)("input",{type:l,className:c("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...r})});P.displayName="Input";let M=e=>{if(0===e)return"0 Bytes";let t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB"][t]};function W(e){let{onJoinRoom:t,files:s,onDownloadFile:r,transferProgresses:i,isConnected:n,isConnecting:o}=e,[c,d]=(0,l.useState)(""),m=(0,l.useCallback)(e=>{e.preventDefault(),6===c.length&&t(c.toUpperCase())},[c,t]),x=(0,l.useCallback)(e=>{let t=e.target.value.replace(/[^A-Z0-9]/g,"").toUpperCase();t.length<=6&&d(t)},[]);return(n||o)&&0===s.length?(0,a.jsx)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 md:p-8 animate-fade-in-up",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-4 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)(R.A,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),(0,a.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-slate-800 mb-2",children:"等待文件"}),(0,a.jsx)("p",{className:"text-sm sm:text-base text-slate-600 mb-6",children:n?"已连接到房间,等待发送方选择文件...":"正在连接到房间..."}),(0,a.jsx)("div",{className:"flex items-center justify-center space-x-4 mb-6",children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("div",{className:"w-3 h-3 rounded-full mr-2 ".concat(n?"bg-emerald-500 animate-pulse":"bg-orange-500 animate-spin")}),(0,a.jsx)("span",{className:"text-sm font-medium ".concat(n?"text-emerald-600":"text-orange-600"),children:n?"连接已建立":"连接中..."})]})}),(0,a.jsx)("div",{className:"flex justify-center space-x-1 mb-6",children:[void 0,void 0,void 0].map((e,t)=>(0,a.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce",style:{animationDelay:"".concat(.1*t,"s")}},t))}),(0,a.jsx)("div",{className:"p-4 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl border border-blue-200",children:(0,a.jsxs)("p",{className:"text-xs sm:text-sm text-slate-600 text-center",children:["\uD83D\uDCA1 ",(0,a.jsx)("span",{className:"font-medium",children:"提示:"}),"房间已连接,发送方清空文件列表后您会看到此界面,等待对方重新选择文件"]})})]})}):s.length>0?(0,a.jsx)("div",{className:"space-y-4 sm:space-y-6",children:(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 animate-fade-in-up",children:[(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between mb-4 sm:mb-6 gap-4",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(R.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg sm:text-xl font-semibold text-slate-800",children:"可下载文件"}),(0,a.jsx)("p",{className:"text-slate-500 text-sm",children:n?(0,a.jsx)("span",{className:"text-emerald-600",children:"✅ 已连接,可以下载文件"}):(0,a.jsx)("span",{className:"text-amber-600",children:"⏳ 正在建立连接..."})})]})]}),(0,a.jsx)("div",{className:"bg-gradient-to-r from-emerald-100 to-teal-100 px-3 sm:px-4 py-2 rounded-full self-start sm:self-center",children:(0,a.jsxs)("span",{className:"text-emerald-700 font-medium text-sm",children:[s.length," 个文件"]})})]}),(0,a.jsx)("div",{className:"space-y-3 sm:space-y-4",children:s.map(e=>{var t;let s=i.find(t=>t.originalFileId===e.id),l=s&&"downloading"===s.status,o=s&&"completed"===s.status;return(0,a.jsxs)("div",{className:"bg-gradient-to-r from-slate-50 to-blue-50 border border-slate-200 rounded-xl p-3 sm:p-4 hover:shadow-md transition-all duration-200",children:[(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between mb-3 gap-3",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 sm:space-x-4 flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"w-10 h-10 sm:w-12 sm:h-12 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-lg flex items-center justify-center flex-shrink-0",children:(t=e.type).startsWith("image/")?(0,a.jsx)(_.A,{className:"w-5 h-5 text-white"}):t.startsWith("video/")?(0,a.jsx)(F.A,{className:"w-5 h-5 text-white"}):t.startsWith("audio/")?(0,a.jsx)(L.A,{className:"w-5 h-5 text-white"}):t.includes("zip")||t.includes("rar")?(0,a.jsx)(T.A,{className:"w-5 h-5 text-white"}):(0,a.jsx)(D.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"font-medium text-slate-800 truncate text-sm sm:text-base",children:e.name}),(0,a.jsx)("p",{className:"text-sm text-slate-500",children:M(e.size)}),o&&(0,a.jsx)("p",{className:"text-xs text-emerald-600 font-medium",children:"✅ 下载完成"})]})]}),(0,a.jsxs)(S,{onClick:()=>r(e.id),disabled:!n||l||o,className:"px-6 py-2 rounded-lg font-medium shadow-lg transition-all duration-200 hover:shadow-xl ".concat(o?"bg-slate-300 text-slate-500 cursor-not-allowed":"bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white"),children:[(0,a.jsx)(R.A,{className:"w-4 h-4 mr-2"}),l?"下载中...":o?"已完成":"下载"]})]}),s&&("downloading"===s.status||"completed"===s.status)&&(0,a.jsxs)("div",{className:"mt-3 space-y-2",children:[(0,a.jsxs)("div",{className:"flex justify-between text-sm text-slate-600",children:[(0,a.jsx)("span",{children:"completed"===s.status?"下载完成":"正在下载..."}),(0,a.jsxs)("span",{className:"font-medium",children:[s.progress.toFixed(1),"%"]})]}),(0,a.jsx)("div",{className:"w-full bg-slate-200 rounded-full h-2",children:(0,a.jsx)("div",{className:"h-2 rounded-full transition-all duration-300 ".concat("completed"===s.status?"bg-gradient-to-r from-emerald-500 to-emerald-600":"bg-gradient-to-r from-emerald-500 to-teal-500"),style:{width:"".concat(s.progress,"%")}})}),(0,a.jsxs)("div",{className:"flex justify-between text-xs text-slate-500",children:[(0,a.jsxs)("span",{children:[M(s.receivedSize)," / ",M(s.totalSize)]}),"downloading"===s.status&&(0,a.jsxs)("span",{children:["预计还需 ",Math.ceil((s.totalSize-s.receivedSize)/1024/1024)," MB"]})]})]})]},e.id)})})]})}):(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 md:p-8 animate-fade-in-up",children:[(0,a.jsxs)("div",{className:"text-center mb-6 sm:mb-8",children:[(0,a.jsx)("div",{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-4 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)(R.A,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),(0,a.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-slate-800 mb-2",children:"输入取件码"}),(0,a.jsx)("p",{className:"text-sm sm:text-base text-slate-600",children:"请输入6位取件码来获取文件"})]}),(0,a.jsxs)("form",{onSubmit:m,className:"space-y-4 sm:space-y-6",children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(P,{value:c,onChange:x,placeholder:"请输入取件码",className:"text-center text-2xl sm:text-3xl tracking-[0.3em] sm:tracking-[0.5em] font-mono h-12 sm:h-16 border-2 border-slate-200 rounded-xl focus:border-emerald-500 focus:ring-emerald-500 bg-white/80 backdrop-blur-sm pb-2 sm:pb-4",maxLength:6,disabled:o}),(0,a.jsx)("div",{className:"absolute inset-x-0 -bottom-4 sm:-bottom-6 flex justify-center space-x-1 sm:space-x-2",children:[...Array(6)].map((e,t)=>(0,a.jsx)("div",{className:"w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full transition-all duration-200 ".concat(t<c.length?"bg-emerald-500":"bg-slate-300")},t))})]}),(0,a.jsx)("div",{className:"h-3 sm:h-4"}),(0,a.jsxs)("p",{className:"text-center text-xs sm:text-sm text-slate-500",children:[c.length,"/6 位"]})]}),(0,a.jsx)(S,{type:"submit",className:"w-full h-10 sm:h-12 bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white text-base sm:text-lg font-medium rounded-xl shadow-lg transition-all duration-200 hover:shadow-xl hover:scale-105 disabled:opacity-50 disabled:scale-100",disabled:6!==c.length||o,children:o?(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("div",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("span",{children:"连接中..."})]}):(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(R.A,{className:"w-5 h-5"}),(0,a.jsx)("span",{children:"开始接收"})]})})]}),(0,a.jsx)("div",{className:"mt-6 p-4 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl border border-blue-200",children:(0,a.jsxs)("p",{className:"text-sm text-slate-600 text-center",children:["\uD83D\uDCA1 ",(0,a.jsx)("span",{className:"font-medium",children:"提示:"}),"取件码由发送方提供,有效期为24小时"]})})]})}function B(e){let{selectedFiles:t,onFilesChange:s,onGenerateCode:i,pickupCode:n,pickupLink:o,onCopyCode:c,onCopyLink:d,onAddMoreFiles:m,onRemoveFile:x,onClearFiles:u,onReset:h,onJoinRoom:p,receiverFiles:f,onDownloadFile:g,transferProgresses:b,isConnected:v,isConnecting:j,disabled:w=!1}=e,N=(0,r.useSearchParams)(),y=(0,r.useRouter)(),[k,C]=(0,l.useState)("send");(0,l.useEffect)(()=>{let e=N.get("mode");"file"===N.get("type")&&e&&["send","receive"].includes(e)&&C(e)},[N]);let A=(0,l.useCallback)(e=>{C(e);let t=new URLSearchParams(N.toString());t.set("type","file"),t.set("mode",e),y.push("?".concat(t.toString()),{scroll:!1})},[N,y]);return(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsx)("div",{className:"flex justify-center mb-6",children:(0,a.jsxs)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-1 shadow-lg",children:[(0,a.jsxs)(S,{variant:"send"===k?"default":"ghost",onClick:()=>A("send"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(E.A,{className:"w-4 h-4 mr-2"}),"发送文件"]}),(0,a.jsxs)(S,{variant:"receive"===k?"default":"ghost",onClick:()=>A("receive"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(R.A,{className:"w-4 h-4 mr-2"}),"接收文件"]})]})}),"send"===k?(0,a.jsx)("div",{className:"animate-fade-in-up",children:(0,a.jsx)(U,{selectedFiles:t,onFilesChange:s,onGenerateCode:i,pickupCode:n,pickupLink:o,onCopyCode:c,onCopyLink:d,onAddMoreFiles:m,onRemoveFile:x,onClearFiles:u,onReset:h,disabled:w})}):(0,a.jsx)("div",{className:"animate-fade-in-up",children:(0,a.jsx)(W,{onJoinRoom:p,files:f,onDownloadFile:g,transferProgresses:b,isConnected:v,isConnecting:j})})]})}var O=s(2486),I=s(1497),J=s(7580),G=s(4357),V=s(8164),q=s(2657),X=s(6801);function H(e){let{onSendText:t,onReceiveText:s,websocket:i,isConnected:n=!1,currentRole:o,pickupCode:c,onCreateWebSocket:d}=e,m=(0,r.useSearchParams)(),x=(0,r.useRouter)(),[u,h]=(0,l.useState)("send"),[p,f]=(0,l.useState)(""),[g,b]=(0,l.useState)(""),[v,j]=(0,l.useState)(""),[w,N]=(0,l.useState)(!1),[y,k]=(0,l.useState)(!1),[C,A]=(0,l.useState)(0),[z,E]=(0,l.useState)([]),[F,L]=(0,l.useState)([]),[T,D]=(0,l.useState)(null),[U,M]=(0,l.useState)(null),[W,B]=(0,l.useState)(!1),{showToast:H}=(0,X.d)(),K=(0,l.useRef)(null),$=(0,l.useRef)(null),Y=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=m.get("mode");if("text"===m.get("type")&&e&&["send","receive"].includes(e)){h(e);let t=m.get("code");"receive"===e&&t&&6===t.length&&b(t.toUpperCase())}},[m]),(0,l.useEffect)(()=>{let e=e=>{var t,s,a,l,r,i;let n=e.detail;switch(console.log("TextTransfer收到WebSocket消息:",n),n.type){case"text-content":(null==(t=n.payload)?void 0:t.text)!==void 0&&(j(n.payload.text),"receiver"===o&&(f(n.payload.text),!W&&w&&(B(!0),H("成功加入文字房间!","success"))),Y.current&&(clearTimeout(Y.current),Y.current=null),w&&N(!1));break;case"text-update":(null==(s=n.payload)?void 0:s.text)!==void 0&&(j(n.payload.text),"receiver"===o&&f(n.payload.text));break;case"text-send":(null==(a=n.payload)?void 0:a.text)&&(j(n.payload.text),H("收到新的文字内容!","success"));break;case"image-send":(null==(l=n.payload)?void 0:l.imageData)&&(console.log("接收到图片数据:",n.payload.imageData.substring(0,100)+"..."),n.payload.imageData.startsWith("data:image/")?(L(e=>[...e,n.payload.imageData]),H("收到新的图片!","success")):(console.error("无效的图片数据格式:",n.payload.imageData.substring(0,50)),H("收到的图片格式不正确","error")));break;case"room-status":(null==(r=n.payload)?void 0:r.sender_count)!==void 0&&(null==(i=n.payload)?void 0:i.receiver_count)!==void 0&&A(n.payload.sender_count+n.payload.receiver_count)}},t=e=>{let{code:t,reason:s}=e.detail;console.log("WebSocket连接关闭:",t,s),w&&(N(!1),1e3!==t&&H("取件码不存在或已过期","error"))},s=e=>{console.error("WebSocket连接错误:",e.detail),w&&(N(!1),H("取件码不存在或已过期","error"))};return window.addEventListener("websocket-message",e),window.addEventListener("websocket-close",t),window.addEventListener("websocket-error",s),()=>{window.removeEventListener("websocket-message",e),window.removeEventListener("websocket-close",t),window.removeEventListener("websocket-error",s),Y.current&&clearTimeout(Y.current)}},[o,H,W,w]);let Z=(0,l.useCallback)(e=>{h(e);let t=new URLSearchParams(m.toString());t.set("type","text"),t.set("mode",e),x.push("?".concat(t.toString()),{scroll:!1})},[m,x]),Q=(0,l.useCallback)(e=>{i&&n&&($.current&&clearTimeout($.current),$.current=setTimeout(()=>{i.send(JSON.stringify({type:"text-update",payload:{text:e}}))},300))},[i,n]),ee=(0,l.useCallback)(e=>{let t=e.target.value;f(t),n&&i&&Q(t)},[n,i,Q]),et=(0,l.useCallback)(async()=>{if(!p.trim())return void H("请输入要传输的文字内容","error");N(!0);try{if(t){let e=await t(p);e&&(b(e),k(!0),H("房间创建成功!","success"),d&&d(e,"sender"))}}catch(e){console.error("创建房间失败:",e)}finally{N(!1)}},[p,t,d,H]),es=(0,l.useCallback)(async()=>{if(!g.trim()||6!==g.length)return void H("请输入正确的6位房间码","error");if(!w){N(!0),B(!1);try{let e=await fetch("/api/room-info?code=".concat(g)),t=await e.json();if(!e.ok||!t.success){H(t.message||"房间不存在或已过期","error"),N(!1);return}d&&(console.log("房间验证成功,手动加入房间:",g),d(g,"receiver"),Y.current=setTimeout(()=>{w&&(N(!1),H("取件码不存在或已过期","error"))},8e3))}catch(e){console.error("加入房间失败:",e),H("网络错误,请稍后重试","error"),N(!1)}}},[g,d,H,w]),ea=(0,l.useCallback)(()=>{i&&n&&p.trim()&&(i.send(JSON.stringify({type:"text-send",payload:{text:p}})),H("文字已发送!","success"))},[i,n,p,H]),el=(0,l.useCallback)(e=>new Promise((t,s)=>{let a=document.createElement("canvas"),l=a.getContext("2d"),r=document.createElement("img");if(!l)return void s(Error("无法创建Canvas上下文"));r.onload=()=>{try{let{width:e,height:s}=r;e>s?e>800&&(s=800*s/e,e=800):s>600&&(e=600*e/s,s=600),a.width=e,a.height=s,l.fillStyle="#FFFFFF",l.fillRect(0,0,e,s),l.drawImage(r,0,0,e,s);let i=a.toDataURL("image/jpeg",.8);console.log("图片压缩完成,数据长度:",i.length,"前100字符:",i.substring(0,100)),t(i)}catch(e){s(Error("图片压缩失败: "+e))}},r.onerror=()=>s(Error("图片加载失败"));let i=new FileReader;i.onload=e=>{var t;(null==(t=e.target)?void 0:t.result)?r.src=e.target.result:s(Error("文件读取失败"))},i.onerror=()=>s(Error("文件读取失败")),i.readAsDataURL(e)}),[]),er=(0,l.useCallback)(async e=>{var t;let s=null==(t=e.clipboardData)?void 0:t.items;if(s)for(let e=0;e<s.length;e++){let t=s[e];if(-1!==t.type.indexOf("image")){let e=t.getAsFile();if(e)try{H("正在处理图片...","info");let t=await el(e);E(e=>[...e,t]),i&&n&&(i.send(JSON.stringify({type:"image-send",payload:{imageData:t}})),H("图片已发送!","success"))}catch(e){console.error("图片处理失败:",e),H("图片处理失败,请重试","error")}}}},[i,n,H,el]),ei=(0,l.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),H("已复制到剪贴板!","success")}catch(e){H("复制失败","error")}},[H]),en=(0,l.useCallback)(async e=>{let t=window.location.origin+window.location.pathname,s="".concat(t,"?type=text&mode=receive&code=").concat(e);await ei(s)},[ei]),eo=(0,l.useCallback)((e,t)=>{let s=document.createElement("a");s.download="image_".concat(t+1,".jpg"),s.href=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),H("图片已下载!","success")},[H]);return(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsx)("div",{className:"flex justify-center mb-6",children:(0,a.jsxs)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-1 shadow-lg",children:[(0,a.jsxs)(S,{variant:"send"===u?"default":"ghost",onClick:()=>Z("send"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(O.A,{className:"w-4 h-4 mr-2"}),"发送文字"]}),(0,a.jsxs)(S,{variant:"receive"===u?"default":"ghost",onClick:()=>Z("receive"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(R.A,{className:"w-4 h-4 mr-2"}),"加入房间"]})]})}),"send"===u?(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 animate-fade-in-up",children:[(0,a.jsxs)("div",{className:"text-center mb-6",children:[(0,a.jsx)("div",{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-4 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)(I.A,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),(0,a.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-slate-800 mb-2",children:"传送文字"}),(0,a.jsx)("p",{className:"text-sm sm:text-base text-slate-600",children:y?"实时编辑,对方可以同步看到":"输入要传输的文本内容"}),(0,a.jsx)("div",{className:"mt-2 space-y-1",children:y&&(0,a.jsxs)("div",{className:"flex items-center justify-center space-x-4 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full mr-2 ".concat(n?"bg-emerald-500 animate-pulse":"bg-red-500")}),(0,a.jsx)("span",{className:n?"text-emerald-600":"text-red-600",children:n?"实时连接已建立":"连接断开"})]}),C>0&&(0,a.jsxs)("div",{className:"flex items-center text-blue-600",children:[(0,a.jsx)(J.A,{className:"w-4 h-4 mr-1"}),C," 人在线"]})]})})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("textarea",{ref:K,value:p,onChange:ee,onPaste:er,placeholder:"在这里输入要传输的文本内容... \uD83D\uDCA1 提示:支持实时同步编辑,可以直接粘贴图片 (Ctrl+V)",className:"w-full min-h-[150px] p-4 border-2 border-slate-200 rounded-xl focus:border-blue-500 focus:ring-blue-500 bg-white/80 backdrop-blur-sm resize-none",disabled:w}),y&&n&&(0,a.jsx)("div",{className:"absolute top-2 right-2",children:(0,a.jsxs)("div",{className:"flex items-center space-x-1 bg-emerald-100 text-emerald-700 px-2 py-1 rounded-lg text-xs",children:[(0,a.jsx)("div",{className:"w-2 h-2 bg-emerald-500 rounded-full animate-pulse"}),(0,a.jsx)("span",{children:"实时同步"})]})}),y&&!n&&(0,a.jsx)("div",{className:"absolute top-2 right-2",children:(0,a.jsxs)("div",{className:"flex items-center space-x-1 bg-orange-100 text-orange-700 px-2 py-1 rounded-lg text-xs",children:[(0,a.jsx)("div",{className:"w-2 h-2 bg-orange-500 rounded-full"}),(0,a.jsx)("span",{children:"连接中..."})]})})]}),(0,a.jsxs)("div",{className:"flex justify-between text-sm text-slate-500",children:[(0,a.jsxs)("span",{children:[p.length," 字符"]}),(0,a.jsx)("span",{children:"最大 50,000 字符"})]}),y?(0,a.jsx)("div",{className:"space-y-4",children:(0,a.jsx)("div",{className:"p-4 bg-gradient-to-r from-emerald-50 to-teal-50 rounded-xl border border-emerald-200",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("p",{className:"text-sm text-emerald-700 mb-2",children:"房间码"}),(0,a.jsx)("div",{className:"text-2xl font-bold font-mono text-emerald-600 mb-3",children:g}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2 justify-center",children:[(0,a.jsxs)(S,{onClick:()=>ei(g),size:"sm",className:"bg-emerald-500 hover:bg-emerald-600 text-white",children:[(0,a.jsx)(G.A,{className:"w-4 h-4 mr-2"}),"复制房间码"]}),(0,a.jsxs)(S,{onClick:()=>en(g),size:"sm",className:"bg-purple-500 hover:bg-purple-600 text-white",children:[(0,a.jsx)(V.A,{className:"w-4 h-4 mr-2"}),"复制链接"]}),(0,a.jsxs)(S,{onClick:ea,size:"sm",className:"bg-blue-500 hover:bg-blue-600 text-white",disabled:!p.trim(),children:[(0,a.jsx)(O.A,{className:"w-4 h-4 mr-2"}),"发送文字"]})]})]})})}):(0,a.jsx)(S,{onClick:et,disabled:!p.trim()||p.length>5e4||w,className:"w-full h-12 bg-gradient-to-r from-blue-500 to-indigo-500 hover:from-blue-600 hover:to-indigo-600 text-white text-lg font-medium rounded-xl shadow-lg",children:w?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"}),"创建房间..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(O.A,{className:"w-5 h-5 mr-2"}),"创建文字传输房间"]})}),"send"===u&&z.length>0&&(0,a.jsxs)("div",{className:"mt-6",children:[(0,a.jsxs)("h3",{className:"text-lg font-medium text-slate-800 mb-3 flex items-center",children:[(0,a.jsx)(_.A,{className:"w-5 h-5 mr-2"}),"已发送的图片 (",z.length,")"]}),(0,a.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:z.map((e,t)=>(0,a.jsxs)("div",{className:"relative group overflow-hidden",children:[(0,a.jsx)("img",{src:e,alt:"图片 ".concat(t+1),className:"w-full h-24 object-cover rounded-lg border-2 border-slate-200 hover:border-blue-400 transition-all duration-200 cursor-pointer bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-50",onClick:()=>M(e),onError:t=>{console.error("图片加载失败:",e),t.currentTarget.style.display="none"}}),(0,a.jsx)("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-20 transition-opacity rounded-lg"}),(0,a.jsxs)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity flex gap-1",children:[(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),M(e)},className:"p-1.5 bg-white bg-opacity-90 hover:bg-opacity-100 rounded-md shadow-sm transition-all hover:scale-105",title:"预览图片",children:(0,a.jsx)(q.A,{className:"w-3.5 h-3.5 text-slate-600"})}),(0,a.jsx)("button",{onClick:s=>{s.stopPropagation(),eo(e,t)},className:"p-1.5 bg-white bg-opacity-90 hover:bg-opacity-100 rounded-md shadow-sm transition-all hover:scale-105",title:"下载图片",children:(0,a.jsx)(R.A,{className:"w-3.5 h-3.5 text-slate-600"})})]}),(0,a.jsx)("div",{className:"absolute bottom-1 left-1 bg-black bg-opacity-50 text-white text-xs px-1.5 py-0.5 rounded",children:t+1})]},t))})]})]})]}):(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 animate-fade-in-up",children:[(0,a.jsxs)("div",{className:"text-center mb-6",children:[(0,a.jsx)("div",{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-4 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)(R.A,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),(0,a.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-slate-800 mb-2",children:"加入房间"}),(0,a.jsx)("p",{className:"text-sm sm:text-base text-slate-600",children:"输入6位房间码来获取文字内容"}),(v||p)&&(0,a.jsx)("div",{className:"mt-2 space-y-1",children:(0,a.jsxs)("div",{className:"flex items-center justify-center space-x-4 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full mr-2 ".concat(n?"bg-emerald-500 animate-pulse":"bg-red-500")}),(0,a.jsx)("span",{className:n?"text-emerald-600":"text-red-600",children:n?"实时连接已建立":"连接断开"})]}),C>0&&(0,a.jsxs)("div",{className:"flex items-center text-blue-600",children:[(0,a.jsx)(J.A,{className:"w-4 h-4 mr-1"}),C," 人在线"]})]})})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(P,{value:g,onChange:e=>b(e.target.value.toUpperCase().slice(0,6)),placeholder:"请输入房间码",className:"text-center text-2xl sm:text-3xl tracking-[0.3em] sm:tracking-[0.5em] font-mono h-12 sm:h-16 border-2 border-slate-200 rounded-xl focus:border-emerald-500 focus:ring-emerald-500 bg-white/80 backdrop-blur-sm",maxLength:6,disabled:w}),(0,a.jsx)(S,{onClick:es,disabled:6!==g.length||w,className:"w-full h-12 bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white text-lg font-medium rounded-xl shadow-lg",children:w?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"}),"连接中..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(R.A,{className:"w-5 h-5 mr-2"}),"加入房间"]})}),(v||p)&&(0,a.jsxs)("div",{className:"mt-6 space-y-4",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("textarea",{value:v||p,readOnly:"receiver"!==o,onChange:"receiver"===o?ee:void 0,className:"w-full min-h-[150px] p-4 border-2 border-emerald-200 rounded-xl bg-emerald-50/50 backdrop-blur-sm resize-none"}),"receiver"===o&&n&&(0,a.jsx)("div",{className:"absolute top-2 right-2",children:(0,a.jsxs)("div",{className:"flex items-center space-x-1 bg-emerald-100 text-emerald-700 px-2 py-1 rounded-lg text-xs",children:[(0,a.jsx)("div",{className:"w-2 h-2 bg-emerald-500 rounded-full animate-pulse"}),(0,a.jsx)("span",{children:"实时同步"})]})}),"receiver"===o&&!n&&(0,a.jsx)("div",{className:"absolute top-2 right-2",children:(0,a.jsxs)("div",{className:"flex items-center space-x-1 bg-orange-100 text-orange-700 px-2 py-1 rounded-lg text-xs",children:[(0,a.jsx)("div",{className:"w-2 h-2 bg-orange-500 rounded-full"}),(0,a.jsx)("span",{children:"连接中..."})]})})]}),(0,a.jsxs)(S,{onClick:()=>ei(v||p),className:"w-full h-12 bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white text-lg font-medium rounded-xl shadow-lg",children:[(0,a.jsx)(G.A,{className:"w-5 h-5 mr-2"}),"复制文字"]})]}),"receive"===u&&F.length>0&&(0,a.jsxs)("div",{className:"mt-6",children:[(0,a.jsxs)("h3",{className:"text-lg font-medium text-slate-800 mb-3 flex items-center",children:[(0,a.jsx)(_.A,{className:"w-5 h-5 mr-2"}),"接收到的图片 (",F.length,")"]}),(0,a.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:F.map((e,t)=>(0,a.jsxs)("div",{className:"relative group overflow-hidden",children:[(0,a.jsx)("img",{src:e,alt:"图片 ".concat(t+1),className:"w-full h-24 object-cover rounded-lg border-2 border-slate-200 hover:border-emerald-400 transition-all duration-200 cursor-pointer bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-50",onClick:()=>M(e),onLoad:e=>{console.log("图片 ".concat(t+1," 加载成功"))},onError:s=>{console.error("图片 ".concat(t+1," 加载失败:"),e.substring(0,100)),s.currentTarget.style.backgroundColor="#f1f5f9",s.currentTarget.style.display="flex",s.currentTarget.style.alignItems="center",s.currentTarget.style.justifyContent="center",s.currentTarget.innerHTML='<span style="color: #64748b; font-size: 12px;">图片加载失败</span>'}}),(0,a.jsx)("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-20 transition-opacity rounded-lg"}),(0,a.jsxs)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity flex gap-1",children:[(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),M(e)},className:"p-1.5 bg-white bg-opacity-90 hover:bg-opacity-100 rounded-md shadow-sm transition-all hover:scale-105",title:"预览图片",children:(0,a.jsx)(q.A,{className:"w-3.5 h-3.5 text-slate-600"})}),(0,a.jsx)("button",{onClick:s=>{s.stopPropagation(),eo(e,t)},className:"p-1.5 bg-white bg-opacity-90 hover:bg-opacity-100 rounded-md shadow-sm transition-all hover:scale-105",title:"下载图片",children:(0,a.jsx)(R.A,{className:"w-3.5 h-3.5 text-slate-600"})})]}),(0,a.jsx)("div",{className:"absolute bottom-1 left-1 bg-black bg-opacity-50 text-white text-xs px-1.5 py-0.5 rounded",children:t+1})]},t))})]})]})]}),U&&(0,a.jsx)(e=>{let{src:t,onClose:s}=e;return(0,a.jsx)("div",{className:"fixed inset-0 bg-slate-900/80 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fade-in",onClick:s,children:(0,a.jsx)("div",{className:"relative max-w-[90vw] max-h-[90vh] animate-scale-in",children:(0,a.jsxs)("div",{className:"relative bg-white rounded-2xl overflow-hidden shadow-2xl",children:[(0,a.jsx)("img",{src:t,alt:"预览",className:"max-w-full max-h-[80vh] object-contain block bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-50",onClick:e=>e.stopPropagation(),onError:e=>{console.error("预览图片加载失败:",t)}}),(0,a.jsx)("div",{className:"absolute top-0 left-0 right-0 bg-gradient-to-b from-slate-900/60 to-transparent p-4",children:(0,a.jsxs)("div",{className:"flex justify-between items-center",children:[(0,a.jsx)("h3",{className:"text-white font-medium text-lg",children:"图片预览"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{onClick:e=>{e.stopPropagation();let s=z.indexOf(t);-1===s&&(s=F.indexOf(t)),eo(t,s>=0?s:0)},className:"bg-white/20 hover:bg-white/30 backdrop-blur-sm text-white p-2 rounded-lg shadow-lg transition-all hover:scale-105",title:"下载图片",children:(0,a.jsx)(R.A,{className:"w-5 h-5"})}),(0,a.jsx)("button",{onClick:s,className:"bg-white/20 hover:bg-white/30 backdrop-blur-sm text-white p-2 rounded-lg shadow-lg transition-all hover:scale-105",title:"关闭预览",children:(0,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]})}),(0,a.jsx)("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-slate-900/60 to-transparent p-4",children:(0,a.jsx)("div",{className:"text-white text-sm opacity-80",children:"点击空白区域关闭预览"})})]})})})},{src:U,onClose:()=>M(null)})]})}var K=s(6683),$=s(4738),Y=s(5690),Z=s(8979);function Q(e){let{onStartSharing:t,onStopSharing:s,onJoinSharing:i}=e,n=(0,r.useSearchParams)(),o=(0,r.useRouter)(),[c,d]=(0,l.useState)("share"),[m,x]=(0,l.useState)(""),[u,h]=(0,l.useState)(""),[p,f]=(0,l.useState)(!1),[g,b]=(0,l.useState)(!1),[v,j]=(0,l.useState)(!1),{showToast:w}=(0,X.d)();(0,l.useEffect)(()=>{let e=n.get("mode");"desktop"===n.get("type")&&e&&("send"===e?d("share"):"receive"===e&&d("view"))},[n]);let N=(0,l.useCallback)(e=>{d(e);let t=new URLSearchParams(n.toString());t.set("type","desktop"),t.set("mode","share"===e?"send":"receive"),o.push("?".concat(t.toString()),{scroll:!1})},[n,o]),y=(0,l.useCallback)(async()=>{if(t){j(!0);try{let e=await t();x(e),f(!0),w("桌面共享已开始!","success")}catch(e){console.error("开始共享失败:",e),w("开始共享失败,请重试","error")}finally{j(!1)}}},[t,w]),k=(0,l.useCallback)(async()=>{if(s){j(!0);try{await s(),f(!1),x(""),w("桌面共享已停止","success")}catch(e){console.error("停止共享失败:",e),w("停止共享失败","error")}finally{j(!1)}}},[s,w]),C=(0,l.useCallback)(async()=>{if(u.trim()&&i){j(!0);try{await i(u),b(!0),w("已连接到桌面共享!","success")}catch(e){console.error("连接失败:",e),w("连接失败,请检查连接码","error")}finally{j(!1)}}},[u,i,w]),A=(0,l.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),w("已复制到剪贴板!","success")}catch(e){w("复制失败","error")}},[w]);return(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsx)("div",{className:"flex justify-center mb-6",children:(0,a.jsxs)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-1 shadow-lg",children:[(0,a.jsxs)(S,{variant:"share"===c?"default":"ghost",onClick:()=>N("share"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(K.A,{className:"w-4 h-4 mr-2"}),"共享桌面"]}),(0,a.jsxs)(S,{variant:"view"===c?"default":"ghost",onClick:()=>N("view"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)($.A,{className:"w-4 h-4 mr-2"}),"观看桌面"]})]})}),"share"===c?(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 animate-fade-in-up",children:[(0,a.jsxs)("div",{className:"text-center mb-6",children:[(0,a.jsx)("div",{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-4 bg-gradient-to-br from-purple-500 to-pink-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)(K.A,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),(0,a.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-slate-800 mb-2",children:"共享桌面"}),(0,a.jsx)("p",{className:"text-sm sm:text-base text-slate-600",children:p?"桌面共享进行中":"开始共享您的桌面屏幕"})]}),(0,a.jsx)("div",{className:"space-y-4",children:p?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("div",{className:"p-4 bg-gradient-to-r from-purple-50 to-pink-50 rounded-xl border border-purple-200",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("p",{className:"text-sm text-purple-700 mb-2",children:"连接码"}),(0,a.jsx)("div",{className:"text-2xl font-bold font-mono text-purple-600 mb-3",children:m}),(0,a.jsxs)(S,{onClick:()=>A(m),size:"sm",className:"bg-purple-500 hover:bg-purple-600 text-white",children:[(0,a.jsx)(G.A,{className:"w-4 h-4 mr-2"}),"复制连接码"]})]})}),(0,a.jsx)(S,{onClick:k,disabled:v,className:"w-full h-12 bg-gradient-to-r from-red-500 to-pink-500 hover:from-red-600 hover:to-pink-600 text-white text-lg font-medium rounded-xl shadow-lg",children:v?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"}),"停止中..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Z.A,{className:"w-5 h-5 mr-2"}),"停止共享"]})})]}):(0,a.jsx)(S,{onClick:y,disabled:v,className:"w-full h-12 bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 text-white text-lg font-medium rounded-xl shadow-lg",children:v?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"}),"启动中..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Y.A,{className:"w-5 h-5 mr-2"}),"开始共享桌面"]})})})]}):(0,a.jsxs)("div",{className:"glass-card rounded-2xl p-4 sm:p-6 animate-fade-in-up",children:[(0,a.jsxs)("div",{className:"text-center mb-6",children:[(0,a.jsx)("div",{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-4 bg-gradient-to-br from-indigo-500 to-purple-500 rounded-2xl flex items-center justify-center animate-float",children:(0,a.jsx)($.A,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),(0,a.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-slate-800 mb-2",children:"观看桌面"}),(0,a.jsx)("p",{className:"text-sm sm:text-base text-slate-600",children:g?"正在观看桌面共享":"输入连接码观看他人的桌面"})]}),(0,a.jsx)("div",{className:"space-y-4",children:g?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("div",{className:"aspect-video bg-slate-900 rounded-xl flex items-center justify-center text-white",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)($.A,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),(0,a.jsx)("p",{className:"text-sm opacity-75",children:"桌面共享画面"})]})}),(0,a.jsxs)(S,{onClick:()=>b(!1),className:"w-full h-12 bg-gradient-to-r from-red-500 to-pink-500 hover:from-red-600 hover:to-pink-600 text-white text-lg font-medium rounded-xl shadow-lg",children:[(0,a.jsx)(Z.A,{className:"w-5 h-5 mr-2"}),"断开连接"]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(P,{value:u,onChange:e=>h(e.target.value.toUpperCase().slice(0,6)),placeholder:"请输入连接码",className:"text-center text-2xl sm:text-3xl tracking-[0.3em] sm:tracking-[0.5em] font-mono h-12 sm:h-16 border-2 border-slate-200 rounded-xl focus:border-indigo-500 focus:ring-indigo-500 bg-white/80 backdrop-blur-sm",maxLength:6,disabled:v}),(0,a.jsx)(S,{onClick:C,disabled:6!==u.length||v,className:"w-full h-12 bg-gradient-to-r from-indigo-500 to-purple-500 hover:from-indigo-600 hover:to-purple-600 text-white text-lg font-medium rounded-xl shadow-lg",children:v?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"}),"连接中..."]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)($.A,{className:"w-5 h-5 mr-2"}),"连接桌面"]})})]})})]})]})}var ee=s(9509);let et=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";try{if(void 0!==ee&&ee.env)return ee.env[e]||t}catch(e){}return t},es={isDev:"development"===et("NODE_ENV"),isProd:"production"===et("NODE_ENV"),isStatic:!0,api:{backendUrl:et("GO_BACKEND_URL","http://localhost:8080"),baseUrl:et("NEXT_PUBLIC_API_BASE_URL","http://localhost:3000"),directBackendUrl:et("NEXT_PUBLIC_BACKEND_URL","http://localhost:8080"),wsUrl:et("NEXT_PUBLIC_WS_URL","ws://localhost:8080/ws")},timeout:{api:3e4,ws:6e4},retry:{max:3,delay:1e3}};var ea=s(9509);async function el(e){let t,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a="true"===ea.env.NEXT_EXPORT||!window.location.origin.includes("localhost:3000");return t=a?function(e){let t=es.api.directBackendUrl.replace(/\/$/,""),s=e.startsWith("/")?e:"/".concat(e);return"".concat(t).concat(s)}(e):function(e){let t=es.api.baseUrl.replace(/\/$/,""),s=e.startsWith("/")?e:"/".concat(e);return"".concat(t).concat(s)}(e),console.log("[API] 模式检查: isClient=".concat(!0,", isStatic=").concat(a)),console.log("[API] 调用: ".concat(e," -> ").concat(t)),fetch(t,{...s,headers:{"Content-Type":"application/json",...s.headers}})}async function er(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return el(e,{...t,method:"GET"})}async function ei(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return el(e,{...s,method:"POST",body:t?JSON.stringify(t):void 0})}function en(){let e=(0,r.useSearchParams)(),t=(0,r.useRouter)(),{websocket:s,isConnected:i,connect:n,disconnect:o,sendMessage:c}=function(){let[e,t]=(0,l.useState)(null),[s,a]=(0,l.useState)(!1),r=(0,l.useRef)(null),i=(0,l.useRef)(""),n=(0,l.useRef)("sender"),o=(0,l.useCallback)((s,l)=>{if(e&&(e.readyState===WebSocket.OPEN||e.readyState===WebSocket.CONNECTING)&&i.current===s&&n.current===l)return void console.log("WebSocket已连接或正在连接,跳过重复连接",{readyState:e.readyState,currentCode:i.current,newCode:s,currentRole:n.current,newRole:l});e&&(console.log("关闭现有WebSocket连接"),e.close()),i.current=s,n.current=l;let c=es.api.wsUrl,d="".concat(c,"/p2p?code=").concat(s,"&role=").concat(l);console.log("连接WebSocket:",d);let m=new WebSocket(d);m.onopen=()=>{console.log("WebSocket连接已建立"),a(!0),t(m);let e={type:"connect",payload:{code:s,role:l,timestamp:Date.now()}};m.send(JSON.stringify(e))},m.onmessage=e=>{try{let t=JSON.parse(e.data);console.log("收到WebSocket消息:",t);let s=new CustomEvent("websocket-message",{detail:t});window.dispatchEvent(s)}catch(e){console.error("解析WebSocket消息失败:",e)}},m.onclose=e=>{console.log("WebSocket连接关闭:",e.code,e.reason),a(!1),t(null);let s=new CustomEvent("websocket-close",{detail:{code:e.code,reason:e.reason}});window.dispatchEvent(s),1e3!==e.code&&i.current&&(console.log("尝试重新连接..."),r.current=setTimeout(()=>{o(i.current,n.current)},3e3))},m.onerror=e=>{console.error("WebSocket错误:",e);let t=new CustomEvent("websocket-error",{detail:{error:e}});window.dispatchEvent(t)}},[e]),c=(0,l.useCallback)(()=>{r.current&&clearTimeout(r.current),i.current="",e&&e.close(1e3,"User disconnected")},[e]),d=(0,l.useCallback)(t=>{e&&e.readyState===WebSocket.OPEN?e.send(JSON.stringify(t)):console.warn("WebSocket未连接,无法发送消息")},[e]);return(0,l.useEffect)(()=>()=>{r.current&&clearTimeout(r.current),e&&e.close()},[e]),{websocket:e,isConnected:s,connect:o,disconnect:c,sendMessage:d}}(),{showToast:h}=(0,X.d)(),[p,g]=(0,l.useState)("file"),[b,k]=(0,l.useState)(!1),[C,A]=(0,l.useState)("");(0,l.useEffect)(()=>{let t=e.get("type");e.get("mode"),t&&["file","text","desktop"].includes(t)&&g(t)},[e]);let R=(0,l.useCallback)((s,a)=>{let l=new URLSearchParams(e.toString());l.set("type",s),a&&l.set("mode",a),t.push("?".concat(l.toString()),{scroll:!1})},[e,t]),[_,F]=(0,l.useState)([]),[L,T]=(0,l.useState)(""),[D,U]=(0,l.useState)(""),[P,M]=(0,l.useState)("sender"),[W,O]=(0,l.useState)([]),[J,G]=(0,l.useState)([]),[V,q]=(0,l.useState)(!1),[K,Y]=(0,l.useState)(null),[Z,ee]=(0,l.useState)(new Map),[et,ea]=(0,l.useState)(new Set),el=(0,l.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success";console.log("[".concat(t.toUpperCase(),"] ").concat(e)),h(e,t)},[h]),en=(0,l.useCallback)(e=>{if((i||L||V)&&e!==p){A(e),k(!0);return}g(e),R(e)},[R,i,L,V,p]);(0,l.useEffect)(()=>{i&&V&&(q(!1),console.log("WebSocket连接已建立,重置连接状态"))},[i,V]);let eo=(0,l.useCallback)(()=>{if(C){let e=window.location.origin+window.location.pathname,t="".concat(e,"?type=").concat(C);window.open(t,"_blank"),k(!1),A("")}},[C]),ec=(0,l.useCallback)(()=>{k(!1),A("")},[]),ed=(0,l.useCallback)(e=>{console.log("初始化文件传输:",e);let t=e.file_id;ee(s=>{let a=new Map(s);return a.set(t,{fileId:e.file_id,chunks:[],totalSize:e.size,receivedSize:0,fileName:e.name,mimeType:e.mime_type,startTime:Date.now()}),console.log("添加文件传输记录:",t),a}),G(t=>{let s=t.map(t=>t.fileId===e.file_id?{...t,status:"downloading",totalSize:e.size}:t);return console.log("更新传输进度为下载中:",s),s})},[]),em=(0,l.useCallback)((e,t)=>{t.chunks.sort((e,t)=>e.offset-t.offset);let s=new Uint8Array(t.chunks.reduce((e,t)=>e+t.data.length,0)),a=0;t.chunks.forEach(e=>{s.set(e.data,a),a+=e.data.length});let l=new Blob([s],{type:t.mimeType}),r=URL.createObjectURL(l),i=document.createElement("a");i.href=r,i.download=t.fileName,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r),ee(t=>{let s=new Map(t);return s.delete(e),s}),G(t=>t.filter(t=>t.fileId!==e));let n=(Date.now()-t.startTime)/1e3,o=(t.totalSize/n/1024/1024).toFixed(2);el('文件 "'.concat(t.fileName,'" 下载完成!传输速度: ').concat(o," MB/s"))},[el]),ex=(0,l.useCallback)(e=>{console.log("接收文件数据块:",e);let t=e.file_id;ee(s=>{let a=new Map(s),l=a.get(t);if(l){if(l.receivedSize>=l.totalSize)return console.log("文件已完成,忽略额外的数据块"),a;let s=new Uint8Array(e.data);l.chunks.push({offset:e.offset,data:s}),l.receivedSize+=s.length,l.receivedSize>l.totalSize&&(l.receivedSize=l.totalSize);let r=l.receivedSize/l.totalSize*100;console.log("文件 ".concat(t," 进度: ").concat(r.toFixed(2),"%")),G(e=>{let s=e.map(e=>e.fileId===t?{...e,progress:r,receivedSize:l.receivedSize,totalSize:l.totalSize}:e);return console.log("更新进度状态:",s),s}),(e.is_last||l.receivedSize>=l.totalSize)&&(console.log("文件接收完成,准备下载"),G(e=>e.map(e=>e.fileId===t?{...e,status:"completed",progress:100,receivedSize:l.totalSize}:e)))}else console.warn("未找到对应的文件传输:",t);return a})},[]),eu=(0,l.useCallback)(e=>{if(console.log("文件传输完成,开始下载:",e),et.has(e))return void console.log("文件已经下载过,跳过重复下载:",e);ea(t=>new Set([...t,e]));let t=Z.get(e);t?(em(e,t),setTimeout(()=>{G(t=>t.filter(t=>t.fileId!==e))},2e3)):console.warn("未找到文件传输数据:",e)},[Z,em,et]),eh=(0,l.useCallback)(async e=>{let t=e.file_id,s=e.request_id,a=_[parseInt(t.replace("file_",""))];if(!a)return void console.error("未找到请求的文件:",t);console.log("开始发送文件:",a.name),el("开始发送文件: ".concat(a.name)),c({type:"file-info",payload:{file_id:s,name:a.name,size:a.size,mime_type:a.type,last_modified:a.lastModified}});let l=0,r=()=>{if(l>=a.size){c({type:"file-complete",payload:{file_id:s}}),el("文件发送完成: ".concat(a.name));return}let e=a.slice(l,l+65536),t=new FileReader;t.onload=e=>{var t;let i=null==(t=e.target)?void 0:t.result;c({type:"file-chunk",payload:{file_id:s,offset:l,data:Array.from(new Uint8Array(i)),is_last:l+i.byteLength>=a.size}}),l+=i.byteLength,setTimeout(r,10)},t.readAsArrayBuffer(e)};r()},[_,c,el]);(0,l.useEffect)(()=>{let e=e=>{let t=e.detail;switch(console.log("HomePage收到WebSocket消息:",t.type,t),t.type){case"file-list":console.log("处理file-list消息"),"receiver"===P&&(O(t.payload.files||[]),q(!1));break;case"file-list-updated":console.log("处理file-list-updated消息"),"receiver"===P&&(O(t.payload.files||[]),el("文件列表已更新,发现新文件!"));break;case"room-status":console.log("处理room-status消息"),Y(t.payload);break;case"file-info":console.log("处理file-info消息"),"receiver"===P&&ed(t.payload);break;case"file-chunk":console.log("处理file-chunk消息"),"receiver"===P&&ex(t.payload);break;case"file-complete":console.log("处理file-complete消息"),"receiver"===P&&eu(t.payload.file_id);break;case"file-request":console.log("处理file-request消息"),"sender"===P&&eh(t.payload)}};return window.addEventListener("websocket-message",e),()=>{window.removeEventListener("websocket-message",e)}},[P,el,ed,ex,eu,eh]);let ep=(0,l.useCallback)(async()=>{if(0===_.length)return;let e=_.map((e,t)=>({id:"file_"+t,name:e.name,size:e.size,type:e.type,lastModified:e.lastModified}));try{let t=await ei("/api/create-room",{files:e}),s=await t.json();if(s.success){let e=s.code;T(e),M("sender");let t=window.location.origin,a="".concat(t,"/?type=file&mode=receive&code=").concat(e);U(a),n(e,"sender"),el("取件码生成成功!")}else el("生成取件码失败: "+s.message,"error")}catch(e){console.error("生成取件码失败:",e),el("生成取件码失败,请重试","error")}},[_,n,el]),ef=(0,l.useCallback)(async e=>{if(V||i&&L===e)return void console.log("已在连接中或已连接,跳过重复请求");q(!0);try{let t=await er("/api/room-info?code=".concat(e)),s=await t.json();s.success?(T(e),M("receiver"),O(s.files||[]),n(e,"receiver"),el("连接成功!","success")):(el(s.message||"取件码不存在或已过期","error"),q(!1))}catch(e){console.error("API调用失败:",e),el("取件码不存在或已过期","error"),q(!1)}},[n,el,V,i,L]);(0,l.useEffect)(()=>{let t=e.get("code"),s=e.get("type"),a=e.get("mode");t&&6===t.length&&!i&&L!==t.toUpperCase()&&s&&"text"!==s&&"receive"===a&&(console.log("自动加入文件房间:",t.toUpperCase()),M("receiver"),ef(t.toUpperCase()))},[e]);let eg=(0,l.useCallback)(e=>{var t;if(console.log("开始下载文件:",e),!s||s.readyState!==WebSocket.OPEN)return void el("连接未建立,请重试","error");if(J.find(t=>t.originalFileId===e&&"completed"!==t.status)){console.log("文件已在下载中,跳过重复请求:",e),el("文件正在下载中...","info");return}let a="req_"+Date.now()+"_"+Math.random().toString(36).substr(2,9);console.log("生成请求ID:",a),c({type:"file-request",payload:{file_id:e,request_id:a}});let l={fileId:a,originalFileId:e,fileName:(null==(t=W.find(t=>t.id===e))?void 0:t.name)||e,progress:0,receivedSize:0,totalSize:0,status:"pending"};console.log("添加传输进度:",l),G(t=>[...t.filter(t=>t.originalFileId!==e),l])},[s,c,W,el,J]),eb=(0,l.useCallback)(e=>{if(!L||!s||s.readyState!==WebSocket.OPEN)return void console.log("无法更新文件列表: pickupCode=",L,"websocket状态=",null==s?void 0:s.readyState);let t=e.map((e,t)=>({id:"file_"+t,name:e.name,size:e.size,type:e.type,lastModified:e.lastModified}));console.log("通过WebSocket发送文件列表更新:",t),c({type:"update-file-list",payload:{files:t}}),el("文件列表已更新")},[L,s,c,el]),ev=(0,l.useCallback)(e=>{L&&eb(e)},[L,eb]),ej=(0,l.useCallback)(()=>{F([]),G([]),ee(new Map),L&&(eb([]),el("文件列表已清空,房间保持连接","success"))},[L,eb,el]),ew=(0,l.useCallback)(()=>{F([]),T(""),U(""),O([]),G([]),Y(null),ee(new Map),o(),el("已断开连接","info")},[o,el]),eN=(0,l.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),el(t,"success")}catch(e){console.error("复制失败:",e),el("复制失败,请手动复制","error")}},[el]);return(0,a.jsxs)("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-50",children:[(0,a.jsxs)("div",{className:"relative min-h-screen",children:[(0,a.jsxs)("div",{className:"absolute inset-0 pointer-events-none",children:[(0,a.jsx)("div",{className:"absolute -top-40 -right-40 w-80 h-80 bg-gradient-to-br from-blue-400/20 to-indigo-600/20 rounded-full blur-3xl"}),(0,a.jsx)("div",{className:"absolute -bottom-40 -left-40 w-80 h-80 bg-gradient-to-br from-purple-400/20 to-pink-400/20 rounded-full blur-3xl"})]}),(0,a.jsxs)("div",{className:"relative container mx-auto px-4 sm:px-6 py-8 max-w-6xl",children:[(0,a.jsx)(z,{}),(0,a.jsx)("div",{className:"max-w-4xl mx-auto",children:(0,a.jsxs)(d,{value:p,onValueChange:en,className:"w-full",children:[(0,a.jsxs)(m,{className:"grid w-full grid-cols-3 bg-white/80 backdrop-blur-sm border-0 shadow-lg h-12 sm:h-14 p-1 mb-6",children:[(0,a.jsxs)(x,{value:"file",className:"flex items-center justify-center space-x-2 text-sm sm:text-base font-medium data-[state=active]:bg-gradient-to-r data-[state=active]:from-blue-500 data-[state=active]:to-indigo-500 data-[state=active]:text-white data-[state=active]:shadow-lg transition-all duration-300",children:[(0,a.jsx)(E.A,{className:"w-4 h-4 sm:w-5 sm:h-5"}),(0,a.jsx)("span",{className:"hidden sm:inline",children:"传文件"}),(0,a.jsx)("span",{className:"sm:hidden",children:"文件"})]}),(0,a.jsxs)(x,{value:"text",className:"flex items-center justify-center space-x-2 text-sm sm:text-base font-medium data-[state=active]:bg-gradient-to-r data-[state=active]:from-emerald-500 data-[state=active]:to-teal-500 data-[state=active]:text-white data-[state=active]:shadow-lg transition-all duration-300",children:[(0,a.jsx)(I.A,{className:"w-4 h-4 sm:w-5 sm:h-5"}),(0,a.jsx)("span",{className:"hidden sm:inline",children:"传文字"}),(0,a.jsx)("span",{className:"sm:hidden",children:"文字"})]}),(0,a.jsxs)(x,{value:"desktop",className:"flex items-center justify-center space-x-2 text-sm sm:text-base font-medium data-[state=active]:bg-gradient-to-r data-[state=active]:from-purple-500 data-[state=active]:to-pink-500 data-[state=active]:text-white data-[state=active]:shadow-lg transition-all duration-300",children:[(0,a.jsx)($.A,{className:"w-4 h-4 sm:w-5 sm:h-5"}),(0,a.jsx)("span",{className:"hidden sm:inline",children:"共享桌面"}),(0,a.jsx)("span",{className:"sm:hidden",children:"桌面"})]})]}),(0,a.jsxs)(u,{value:"file",className:"mt-6 animate-fade-in-up",children:[(0,a.jsx)(B,{selectedFiles:_,onFilesChange:F,onGenerateCode:ep,pickupCode:L,pickupLink:D,onCopyCode:()=>eN(L,"取件码已复制到剪贴板!"),onCopyLink:()=>eN(D,"取件链接已复制到剪贴板!"),onAddMoreFiles:()=>{let e=document.createElement("input");e.type="file",e.multiple=!0,e.onchange=async e=>{let t=Array.from(e.target.files||[]),s=[..._,...t];F(s),L&&t.length>0&&eb(s)},e.click()},onRemoveFile:ev,onClearFiles:ej,onReset:ew,onJoinRoom:ef,receiverFiles:W,onDownloadFile:eg,transferProgresses:J,isConnected:i,isConnecting:V,disabled:V}),K&&"sender"===P&&(0,a.jsxs)("div",{className:"mt-6 glass-card rounded-2xl p-6 animate-fade-in-up",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold text-slate-800 mb-4 text-center",children:"实时状态"}),(0,a.jsxs)("div",{className:"grid grid-cols-3 gap-6",children:[(0,a.jsxs)("div",{className:"text-center p-4 bg-gradient-to-br from-blue-50 to-indigo-50 rounded-xl",children:[(0,a.jsx)("div",{className:"text-3xl font-bold bg-gradient-to-r from-blue-600 to-indigo-600 bg-clip-text text-transparent",children:((null==K?void 0:K.sender_count)||0)+((null==K?void 0:K.receiver_count)||0)}),(0,a.jsx)("div",{className:"text-sm text-slate-600 mt-1",children:"在线用户"})]}),(0,a.jsxs)("div",{className:"text-center p-4 bg-gradient-to-br from-emerald-50 to-teal-50 rounded-xl",children:[(0,a.jsx)("div",{className:"text-3xl font-bold text-emerald-600",children:(null==K?void 0:K.sender_count)||0}),(0,a.jsx)("div",{className:"text-sm text-slate-600 mt-1",children:"发送方"})]}),(0,a.jsxs)("div",{className:"text-center p-4 bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl",children:[(0,a.jsx)("div",{className:"text-3xl font-bold text-purple-600",children:(null==K?void 0:K.receiver_count)||0}),(0,a.jsx)("div",{className:"text-sm text-slate-600 mt-1",children:"接收方"})]})]})]})]}),(0,a.jsx)(u,{value:"text",className:"mt-6 animate-fade-in-up",children:(0,a.jsx)(H,{onSendText:async e=>{try{let t=await fetch("/api/create-text-room",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e})}),s=await t.json();if(!t.ok){let e=s.error||"创建文字传输房间失败";return el(e,"error"),""}return s.code}catch(e){return console.error("创建文字传输房间失败:",e),el("网络错误,请重试","error"),""}},onReceiveText:async e=>(console.log("onReceiveText被调用,但文字内容将通过WebSocket获取:",e),""),websocket:s,isConnected:i,currentRole:P,onCreateWebSocket:(e,t)=>{s&&o(),n(e,t)}})}),(0,a.jsx)(u,{value:"desktop",className:"mt-6 animate-fade-in-up",children:(0,a.jsx)(Q,{onStartSharing:async()=>(el("桌面共享功能开发中","info"),"DEF456"),onStopSharing:async()=>{el("桌面共享已停止","info")},onJoinSharing:async e=>{el("桌面共享功能开发中","info")}})})]})}),(0,a.jsx)("div",{className:"h-8 sm:h-16"})]})]}),(0,a.jsx)(f,{open:b,onOpenChange:k,children:(0,a.jsxs)(v,{className:"sm:max-w-[425px]",children:[(0,a.jsxs)(j,{children:[(0,a.jsx)(N,{children:"切换传输模式"}),(0,a.jsx)(y,{children:(()=>{let e="",t="";switch(p){case"file":e="文件传输";break;case"text":e="文字传输";break;case"desktop":e="桌面共享"}switch(C){case"file":t="文件传输";break;case"text":t="文字传输";break;case"desktop":t="桌面共享"}return"当前".concat(e,"会话进行中,是否要在新标签页中打开").concat(t,"?")})()})]}),(0,a.jsxs)(w,{children:[(0,a.jsx)(S,{variant:"outline",onClick:ec,children:"取消"}),(0,a.jsx)(S,{onClick:eo,children:"确认打开"})]})]})})]})}let eo=function(){return(0,a.jsx)(l.Suspense,{fallback:(0,a.jsx)("div",{className:"min-h-screen flex items-center justify-center",children:"加载中..."}),children:(0,a.jsx)(en,{})})}},6801:(e,t,s)=>{"use strict";s.d(t,{ToastProvider:()=>n,d:()=>i});var a=s(5155),l=s(2115);let r=(0,l.createContext)(void 0),i=()=>{let e=(0,l.useContext)(r);if(!e)throw Error("useToast must be used within a ToastProvider");return e},n=e=>{let{children:t}=e,[s,i]=(0,l.useState)([]),n=(0,l.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success",s=Date.now().toString(),a={id:s,message:e,type:t};i(e=>[...e,a]),setTimeout(()=>{i(e=>e.filter(e=>e.id!==s))},3e3)},[]),o=(0,l.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]);return(0,a.jsxs)(r.Provider,{value:{showToast:n},children:[t,(0,a.jsx)("div",{className:"fixed top-4 left-1/2 transform -translate-x-1/2 z-50 space-y-2",children:s.map(e=>(0,a.jsx)("div",{className:"\n max-w-sm p-4 rounded-xl shadow-lg backdrop-blur-sm transform transition-all duration-300 ease-in-out\n ".concat("success"===e.type?"bg-emerald-50/90 border border-emerald-200 text-emerald-800":"","\n ").concat("error"===e.type?"bg-red-50/90 border border-red-200 text-red-800":"","\n ").concat("info"===e.type?"bg-blue-50/90 border border-blue-200 text-blue-800":"","\n animate-slide-in-down\n "),onClick:()=>o(e.id),children:(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsxs)("div",{className:"flex-shrink-0",children:["success"===e.type&&(0,a.jsx)("div",{className:"w-6 h-6 bg-emerald-500 rounded-full flex items-center justify-center",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}),"error"===e.type&&(0,a.jsx)("div",{className:"w-6 h-6 bg-red-500 rounded-full flex items-center justify-center",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),"info"===e.type&&(0,a.jsx)("div",{className:"w-6 h-6 bg-blue-500 rounded-full flex items-center justify-center",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})})]}),(0,a.jsx)("p",{className:"text-sm font-medium",children:e.message})]})},e.id))})]})}}},e=>{e.O(0,[984,441,964,358],()=>e(e.s=409)),_N_E=e.O()}]); |