Files
filecodebox/themes/2024/assets/SendFileView-pJ6s3lDi.js
T
2025-12-31 03:24:25 +08:00

2 lines
33 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{c as X,d as ae,u as oe,a as U,o as F,b as r,n,e as t,i as ne,t as M,r as P,f as Fe,w as Xe,_ as ge,g as E,C as Ze,h as se,j as K,k as We,l as S,m as Je,p as Ee,q as ee,P as J,s as Ke,F as we,v as te,T as ie,x as ke,y as de,z as Qe,A as Ye,B as Se,D as _e,E as ce,G as et,X as Ce,H as tt,I as rt,J as re}from"./index-PTyx6WsQ.js";import{u as st,P as at,S as Me,C as ot,c as nt,a as lt,Q as it,b as ue,E as dt}from"./PageHeader-CFxkas5k.js";import{F as Ie}from"./file-CvarIEZS.js";import{T as ct}from"./trash-DWQV8pOr.js";import"./box-DJjb2-qC.js";const ut=X("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);const pe=X("clipboard-copy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]);const pt=X("clock",[["path",{d:"M12 6v6l4 2",key:"mmk7yg"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const gt=X("cloud-upload",[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]]);const ht=X("loader",[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]]);const ft=X("send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);const vt=X("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),Te=A=>A>=1024*1024*1024?Math.round(A/(1024*1024*1024))+"GB":A>=1024*1024?Math.round(A/(1024*1024))+"MB":Math.round(A/1024)+"KB",mt={class:"flex justify-center space-x-4 mb-6"},yt=ae({__name:"SendTypeSelector",props:{selectedType:{}},emits:["update:selectedType"],setup(A,{emit:y}){const{t:I}=oe(),s=y,f=ne("isDarkMode"),p=_=>{s("update:selectedType",_)};return(_,h)=>(F(),U("div",mt,[r("button",{type:"button",onClick:h[0]||(h[0]=d=>p("file")),class:n(["px-4 py-2 rounded-lg transition-colors duration-300",_.selectedType==="file"?"bg-indigo-600 text-white":t(f)?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-200 text-gray-700 hover:bg-gray-300"])},M(t(I)("nav.sendFile")),3),r("button",{type:"button",onClick:h[1]||(h[1]=d=>p("text")),class:n(["px-4 py-2 rounded-lg transition-colors duration-300",_.selectedType==="text"?"bg-indigo-600 text-white":t(f)?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-200 text-gray-700 hover:bg-gray-300"])},M(t(I)("send.sendText")),3)]))}}),xt=ae({__name:"BorderProgressBar",props:{progress:{}},setup(A){const y=A,I=P(null),s=P(null);let f=null;const p=()=>{if(!f||!s.value||!I.value)return;const h=I.value.clientWidth,d=I.value.clientHeight;s.value.width=h,s.value.height=d;const c=4,o=8;f.lineWidth=c;const T=f.createLinearGradient(0,0,h,d);T.addColorStop(0,"#4f46e5"),T.addColorStop(.5,"#7c3aed"),T.addColorStop(1,"#db2777"),f.strokeStyle="rgba(229, 231, 235, 0.2)",_(f,c/2,c/2,h-c,d-c,o),f.stroke();const u=((h+d)*2-8*o+2*Math.PI*o)*y.progress/100;f.strokeStyle=T,f.lineCap="round",f.lineJoin="round",f.beginPath();let g=u;const C=c/2,$=h-c,V=d-c;if(g>0){const b=Math.min($-2*o,g);f.moveTo(o+C,C),f.lineTo(b+o+C,C),g-=b}if(g>0){const b=Math.min(Math.PI/2,g/o);f.arc($-o+C,o+C,o,-Math.PI/2,b-Math.PI/2,!1),g-=b*o}if(g>0){const b=Math.min(V-2*o,g);f.lineTo($+C,b+o+C),g-=b}if(g>0){const b=Math.min(Math.PI/2,g/o);f.arc($-o+C,V-o+C,o,0,b,!1),g-=b*o}if(g>0){const b=Math.min($-2*o,g);f.lineTo($-b-o+C,V+C),g-=b}if(g>0){const b=Math.min(Math.PI/2,g/o);f.arc(o+C,V-o+C,o,Math.PI/2,Math.PI/2+b,!1),g-=b*o}if(g>0){const b=Math.min(V-2*o,g);f.lineTo(C,V-b-o+C),g-=b}if(g>0){const b=Math.min(Math.PI/2,g/o);f.arc(o+C,o+C,o,Math.PI,Math.PI+b,!1)}f.stroke()};function _(h,d,c,o,T,x){h.beginPath(),h.moveTo(d+x,c),h.lineTo(d+o-x,c),h.arcTo(d+o,c,d+o,c+x,x),h.lineTo(d+o,c+T-x),h.arcTo(d+o,c+T,d+o-x,c+T,x),h.lineTo(d+x,c+T),h.arcTo(d,c+T,d,c+T-x,x),h.lineTo(d,c+x),h.arcTo(d,c,d+x,c,x),h.closePath()}return Fe(()=>{s.value&&(f=s.value.getContext("2d"),p())}),Xe(()=>y.progress,p),(h,d)=>(F(),U("div",{class:"border-progress-container",ref_key:"container",ref:I},[r("canvas",{ref_key:"canvas",ref:s,class:"border-progress-canvas"},null,512)],512))}}),bt=ge(xt,[["__scopeId","data-v-2fbf5085"]]),wt=["accept","disabled"],kt={key:0,class:"absolute inset-0 w-full h-full"},St={class:"block truncate"},_t={key:1,class:"mt-3 w-full"},Ct=ae({__name:"FileUploadArea",props:{selectedFile:{default:null},progress:{default:0},placeholder:{default:""},description:{default:""},acceptedTypes:{default:"*"},uploadStatus:{default:"idle"},uploadedBytes:{default:0},totalBytes:{default:0},errorMessage:{default:""},allowRetry:{type:Boolean,default:!0},retryText:{default:"重试"},showProgressDetails:{type:Boolean,default:!0}},emits:["fileSelected","fileDrop","retry"],setup(A,{emit:y}){const{t:I}=oe(),s=A,f=y,p=ne("isDarkMode"),_=E(()=>s.placeholder||I("send.uploadArea.placeholder")),h=E(()=>s.description||I("send.uploadArea.description")),d=P(null),c=E(()=>["uploading","initializing","confirming"].includes(s.uploadStatus)),o=E(()=>s.uploadStatus==="error"),T=E(()=>s.uploadStatus==="success"),x=E(()=>s.selectedFile?s.selectedFile.name:_.value),u=E(()=>c.value?ht:T.value?Ze:o.value?ut:gt),g=E(()=>c.value?p?"text-indigo-400 animate-spin":"text-indigo-600 animate-spin":T.value?p?"text-green-400":"text-green-600":o.value?p?"text-red-400":"text-red-600":p?"text-gray-400 group-hover:text-indigo-400":"text-gray-600 group-hover:text-indigo-600"),C=E(()=>o.value?p?"border-red-500/50":"border-red-300":T.value?p?"border-green-500/50":"border-green-300":""),$=E(()=>o.value&&s.errorMessage?s.errorMessage:s.uploadStatus==="initializing"?"正在初始化上传...":s.uploadStatus==="uploading"?"正在上传文件...":s.uploadStatus==="confirming"?"正在确认上传...":T.value?"上传成功!":h.value),V=E(()=>o.value?p?"text-red-400":"text-red-500":T.value?p?"text-green-400":"text-green-500":p?"text-gray-500":"text-gray-400"),b=m=>{if(m===0)return"0 B";const w=1024,B=["B","KB","MB","GB"],N=Math.floor(Math.log(m)/Math.log(w));return parseFloat((m/Math.pow(w,N)).toFixed(2))+" "+B[N]},Q=()=>{c.value||d.value?.click()},Y=m=>{const B=m.target.files?.[0];B&&f("fileSelected",B)},H=m=>{c.value||f("fileDrop",m)},v=()=>{f("retry")};return(m,w)=>(F(),U("div",{class:n(["rounded-xl p-8 flex flex-col items-center justify-center border-2 border-dashed transition-all duration-300 group cursor-pointer relative",[t(p)?"bg-gray-800 bg-opacity-50 border-gray-600 hover:border-indigo-500":"bg-gray-100 border-gray-300 hover:border-indigo-500",C.value]]),onClick:Q,onDragover:w[0]||(w[0]=se(()=>{},["prevent"])),onDrop:se(H,["prevent"])},[r("input",{ref_key:"fileInput",ref:d,type:"file",class:"hidden",onChange:Y,accept:m.acceptedTypes,disabled:c.value},null,40,wt),m.progress>0?(F(),U("div",kt,[S(bt,{progress:m.progress},null,8,["progress"])])):K("",!0),(F(),We(Je(u.value),{class:n(["w-16 h-16 transition-colors duration-300",g.value])},null,8,["class"])),r("p",{class:n(["mt-4 text-sm transition-colors duration-300 w-full text-center",t(p)?"text-gray-400 group-hover:text-indigo-400":"text-gray-600 group-hover:text-indigo-600"])},[r("span",St,M(x.value),1)],2),r("p",{class:n(["mt-2 text-xs",V.value])},M($.value),3),c.value&&m.showProgressDetails?(F(),U("div",_t,[r("div",{class:n(["flex justify-between text-xs mb-1",[t(p)?"text-gray-400":"text-gray-500"]])},[r("span",null,M(b(m.uploadedBytes))+" / "+M(b(m.totalBytes)),1),r("span",null,M(m.progress)+"%",1)],2)])):K("",!0),o.value&&m.allowRetry?(F(),U("button",{key:2,onClick:se(v,["stop"]),class:n(["mt-3 px-4 py-2 text-sm rounded-lg transition-colors duration-200",[t(p)?"bg-indigo-600 hover:bg-indigo-500 text-white":"bg-indigo-500 hover:bg-indigo-600 text-white"]])},M(m.retryText),3)):K("",!0)],34))}}),Mt={class:"flex flex-col"},It=["value","rows","placeholder"],Tt=ae({__name:"TextInputArea",props:{modelValue:{},rows:{default:7},placeholder:{default:"在此输入要发送的文本..."}},emits:["update:modelValue"],setup(A,{emit:y}){const{t:I}=oe(),s=A,f=y,p=ne("isDarkMode"),_=E(()=>s.placeholder||I("send.uploadArea.textInput")),h=d=>{const c=d.target;f("update:modelValue",c.value)};return(d,c)=>(F(),U("div",Mt,[r("textarea",{value:d.modelValue,onInput:h,rows:d.rows,placeholder:_.value,class:n(["flex-grow px-4 py-3 rounded-xl placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 transition duration-300 resize-none custom-scrollbar",t(p)?"bg-gray-800 bg-opacity-50 text-white":"bg-white text-gray-900 border border-gray-300"])},null,42,It)]))}}),At=ge(Tt,[["__scopeId","data-v-bebdfe92"]]),L={IDLE:"idle",INITIALIZING:"initializing",UPLOADING:"uploading",CONFIRMING:"confirming",SUCCESS:"success",ERROR:"error"},Ae=1,De="day";function Dt(){const A=Ee(),y=P(L.IDLE),I=P(null),s=P({loaded:0,total:0,percentage:0}),f=P(""),p=P(""),_=E(()=>y.value===L.INITIALIZING),h=E(()=>y.value===L.UPLOADING),d=E(()=>y.value===L.CONFIRMING),c=E(()=>y.value===L.SUCCESS),o=E(()=>y.value===L.ERROR),T=E(()=>I.value?.mode??null),x=v=>{if(v.size>we.MAX_FILE_SIZE){const m=Math.round(we.MAX_FILE_SIZE/1024/1024);return p.value=`文件大小不能超过 ${m}MB`,A.showAlert(p.value,"error"),!1}return!0},u=v=>m=>{s.value={loaded:Math.max(0,m.loaded),total:Math.max(0,m.total),percentage:Math.min(100,Math.max(0,m.percentage))},v&&v(s.value)},g=v=>{if(y.value=L.ERROR,Ke.isAxiosError(v)){const m=v.response?.status,w=v.response?.data?.detail;switch(m){case 400:p.value=w||"请求参数错误";break;case 403:p.value=w||"操作被禁止";break;case 404:p.value="上传会话不存在或已过期";break;case 500:p.value="服务器错误,请稍后重试";break;default:p.value=w||"上传失败,请重试"}}else v instanceof Error?p.value=v.message:p.value="未知错误";A.showAlert(p.value,"error")},C=async(v,m)=>{try{y.value=L.INITIALIZING;const w=await J.initUpload({file_name:v.name,file_size:v.size,expire_value:m?.expireValue??Ae,expire_style:m?.expireStyle??De});if(w.code===200&&w.detail)return I.value=w.detail,w.detail;throw new Error(w.message||"初始化上传失败")}catch(w){return g(w),null}},$=async(v,m,w)=>{try{y.value=L.UPLOADING;const B=u(w?.onProgress);if(!await J.directUploadToS3(m.upload_url,v,B))throw new Error("S3 上传失败");y.value=L.CONFIRMING;const Z=await J.confirmUpload(m.upload_id,{expire_value:w?.expireValue??Ae,expire_style:w?.expireStyle??De});if(Z.code===200&&Z.detail?.code)return y.value=L.SUCCESS,f.value=String(Z.detail.code),s.value={loaded:v.size,total:v.size,percentage:100},A.showAlert("文件上传成功!","success"),f.value;throw new Error(Z.message||"确认上传失败")}catch(B){return g(B),null}},V=async(v,m,w)=>{try{y.value=L.UPLOADING;const B=u(w?.onProgress),N=await J.proxyUpload(m.upload_id,v,B);if(N.code===200&&N.detail?.code)return y.value=L.SUCCESS,f.value=String(N.detail.code),s.value={loaded:v.size,total:v.size,percentage:100},A.showAlert("文件上传成功!","success"),f.value;throw new Error(N.message||"代理上传失败")}catch(B){return g(B),null}},b=async(v,m)=>{if(H(),!x(v))return y.value=L.ERROR,null;const w=await C(v,m);return w?w.mode==="direct"?await $(v,w,m):await V(v,w,m):null},Q=async()=>{if(I.value?.upload_id)try{await J.cancelUpload(I.value.upload_id),A.showAlert("上传已取消","info")}catch(v){console.warn("取消上传失败:",v)}finally{H()}},Y=async()=>{if(!I.value?.upload_id)return null;try{const v=await J.getUploadStatus(I.value.upload_id);return v.code===200&&v.detail?(v.detail.is_expired&&(p.value="上传会话已过期",A.showAlert(p.value,"warning")),v.detail):null}catch(v){return g(v),null}},H=()=>{y.value=L.IDLE,I.value=null,s.value={loaded:0,total:0,percentage:0},f.value="",p.value=""};return{presignStatus:ee(y),uploadSession:ee(I),uploadProgress:ee(s),uploadedCode:ee(f),errorMessage:ee(p),isInitializing:_,isUploading:h,isConfirming:d,isSuccess:c,isError:o,currentMode:T,uploadFile:b,cancelUpload:Q,getStatus:Y,reset:H}}const Ft={class:"p-8"},Et={key:"file",class:"grid grid-cols-1 gap-8"},Ut={key:"text",class:"grid grid-cols-1 gap-8"},zt={class:"flex flex-col space-y-3"},Pt={class:"relative flex-grow group"},Rt=["placeholder"],Bt=["value"],Lt={type:"submit",class:"w-full bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 text-white font-bold py-4 px-6 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50 transition-all duration-300 transform hover:scale-105 hover:shadow-lg relative overflow-hidden group"},$t={class:"relative z-10 flex items-center justify-center text-lg"},Vt={class:"mt-6 text-center"},jt={class:"flex-grow overflow-y-auto p-6"},Nt={class:"flex-shrink-0 mr-4"},Gt={class:"flex-grow min-w-0 mr-4"},Ht={class:"flex-shrink-0 flex space-x-2"},Ot=["onClick"],qt=["onClick"],Xt=["onClick"],Zt={key:0,class:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-3 sm:p-4 overflow-y-auto"},Wt={class:"flex items-center justify-between"},Jt={class:"p-4 sm:p-6"},Kt={class:"flex items-center mb-3 sm:mb-4"},Qt={class:"ml-3 sm:ml-4 min-w-0 flex-1"},Yt={class:"grid grid-cols-2 gap-3 sm:gap-4"},er={class:"flex items-center min-w-0"},tr={class:"flex items-center min-w-0"},rr={class:"grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6"},sr={class:"space-y-3 sm:space-y-4"},ar={class:"bg-gradient-to-br from-indigo-500 to-purple-600 rounded-xl p-4 sm:p-5 text-white"},or={class:"flex items-center justify-between mb-3 sm:mb-4"},nr={class:"text-2xl sm:text-3xl font-bold tracking-wider text-center break-all"},lr={class:"flex items-center justify-between mb-2 sm:mb-3"},ir={class:"bg-white p-3 sm:p-4 rounded-lg shadow-sm mb-3 sm:mb-4"},dr=ae({__name:"SendFileView",setup(A){const y=JSON.parse(localStorage.getItem("config")||"{}"),I=rt(),s=ne("isDarkMode"),f=st(),p=P("file"),_=P(null),h=P(""),d=P(y.expireStyle?.[0]||"day"),c=P("1"),o=P(0),T=P(!1),x=P(null),{t:u}=oe(),g=Ee(),C=E(()=>f.shareData),{uploadFile:$,reset:V}=Dt(),b=P(""),Q=async a=>{_.value=a,he()&&fe(a)&&(b.value=await v(a))},Y=async a=>{if(a.dataTransfer?.files&&a.dataTransfer.files.length>0){const e=a.dataTransfer.files[0];if(_.value=e,!me())return;b.value=await v(e)}},H=async a=>{const e=a.clipboardData?.items;if(e)for(let l=0;l<e.length;l++){const i=e[l];if(i.kind==="file"){const k=i.getAsFile();if(k){if(k.size===0){g.showAlert(u("send.messages.emptyFileError"),"error");return}if(_.value=k,!me())return;try{b.value=await v(k),g.showAlert(u("send.messages.fileAddedFromClipboard",{filename:k.name}),"success")}catch(D){g.showAlert(u("send.messages.fileProcessingFailed"),"error"),console.error("File hash calculation failed:",D)}break}}else p.value="text",e[0].getAsString(k=>{const D=k.trim();if(!D)return;const z=document.getElementById("text-content");if(!z){h.value+=D;return}const j=z.selectionStart,R=z.selectionEnd;if(j!==R){const G=h.value.substring(0,j),O=h.value.substring(R);h.value=G+D+O,setTimeout(()=>{const q=j+D.length;z.setSelectionRange(q,q),z.focus()},0)}else{const G=j,O=h.value.substring(0,G),q=h.value.substring(G);h.value=O+D+q,setTimeout(()=>{const le=G+D.length;z.setSelectionRange(le,le),z.focus()},0)}})}},v=async a=>{try{if(a.size<=10*1024*1024){const R=await a.arrayBuffer();if(window.isSecureContext){const W=await crypto.subtle.digest("SHA-256",R);return Array.from(new Uint8Array(W)).map(O=>O.toString(16).padStart(2,"0")).join("")}return m(a)}const e=5*1024*1024,l=a.slice(0,e),i=a.slice(-e),[k,D]=await Promise.all([l.arrayBuffer(),i.arrayBuffer()]),z=new Uint8Array(k.byteLength+D.byteLength+16);z.set(new Uint8Array(k),0),z.set(new Uint8Array(D),k.byteLength);const j=new TextEncoder().encode(a.size.toString());if(z.set(j,k.byteLength+D.byteLength),window.isSecureContext){const R=await crypto.subtle.digest("SHA-256",z);return Array.from(new Uint8Array(R)).map(G=>G.toString(16).padStart(2,"0")).join("")}return m(a)}catch(e){return console.error("File hash calculation failed:",e),m(a)}},m=a=>{const e=`${a.name}-${a.size}-${a.lastModified}`;let l=0;for(let i=0;i<e.length;i++){const k=e.charCodeAt(i);l=(l<<5)-l+k,l=l&l}return Math.abs(l).toString(16).padStart(64,"0")},w=(a=d.value)=>{switch(a){case"day":return u("send.expiration.placeholders.days");case"hour":return u("send.expiration.placeholders.hours");case"minute":return u("send.expiration.placeholders.minutes");case"count":return u("send.expiration.placeholders.count");case"forever":return u("send.expiration.placeholders.forever");default:return u("send.expiration.placeholders.default")}},B=(a=d.value)=>{switch(a){case"day":return u("send.expiration.units.days");case"hour":return u("send.expiration.units.hours");case"minute":return u("send.expiration.units.minutes");case"count":return u("send.expiration.units.times");case"forever":return u("send.expiration.units.forever");default:return""}},N=(a,e)=>{if(a==="forever")return u("send.expiration.units.forever");if(a==="count")return u("send.messages.expiresAfterCount",{count:e});const l=new Date,i=parseInt(e);switch(a){case"minute":l.setMinutes(l.getMinutes()+i);break;case"hour":l.setHours(l.getHours()+i);break;case"day":l.setDate(l.getDate()+i);break;default:return u("send.messages.expiresAfter",{value:e,unit:B(a)})}const k=l.getFullYear(),D=(l.getMonth()+1).toString().padStart(2,"0"),z=l.getDate().toString().padStart(2,"0"),j=l.getHours().toString().padStart(2,"0"),R=l.getMinutes().toString().padStart(2,"0");return u("send.messages.expiresAt",{date:`${k}-${D}-${z} ${j}:${R}`})},Z=async a=>{try{const e=await v(a);b.value=e,console.log("Calculated file hash:",e);const l=5*1024*1024,i=Math.ceil(a.size/l),k=await re.post("chunk/upload/init/",{file_name:a.name,file_size:a.size,chunk_size:l,file_hash:b.value});if(k.code!==200)throw new Error(u("send.messages.initChunkUploadFailed"));if(k.detail?.existed)return k;const D=k.detail?.upload_id,z=new Set(k.detail?.uploaded_chunks||[]);for(let R=0;R<i;R++){if(z.has(R))continue;const W=R*l,G=Math.min(W+l,a.size),O=a.slice(W,G),q=new FormData;if(q.append("chunk",new Blob([O],{type:a.type})),(await re.post(`chunk/upload/chunk/${D}/${R}`,q,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:je=>{const Ne=Array.from(z).reduce((He,be)=>{const Oe=Math.min((be+1)*l,a.size),qe=be*l;return He+(Oe-qe)},0),Ge=Math.round((Ne+R*l+je.loaded)*100/a.size);o.value=Math.min(Ge,99)}})).code!==200)throw new Error(u("send.messages.chunkUploadFailed",{index:R}))}const j=await re.post(`chunk/upload/complete/${D}`,{expire_value:c.value?parseInt(c.value):1,expire_style:d.value});if(j.code!==200)throw new Error(u("send.messages.completeUploadFailed"));return j}catch(e){if(console.error("切片上传失败:",e),e&&typeof e=="object"&&"response"in e){const l=e;l.response?.data?.detail&&g.showAlert(l.response.data.detail,"error")}else g.showAlert(u("send.messages.uploadFailed"),"error");throw e}},Ue=async a=>{const e=new FormData,l={headers:{"Content-Type":"multipart/form-data"},onUploadProgress:k=>{const D=Math.round(k.loaded*100/(k.total||1));o.value=D}};return e.append("file",a),e.append("expire_value",c.value),e.append("expire_style",d.value),await re.post("share/file/",e,l)},ze=async a=>{const e=await $(a,{expireValue:c.value?parseInt(c.value):1,expireStyle:d.value,onProgress:l=>{o.value=l.percentage}});if(e)return{code:200,detail:{code:e,name:a.name}};throw new Error(u("send.messages.uploadFailed"))},he=()=>y.openUpload===0&&localStorage.getItem("token")===null?(g.showAlert(u("send.messages.guestUploadDisabled"),"error"),!1):!0,fe=a=>a.size>y.uploadSize?(g.showAlert(u("send.messages.fileSizeExceeded",{size:Te(y.uploadSize)}),"error"),_.value=null,!1):!0,ve=(a,e)=>{if(a==="forever"||a==="count")return!0;const l=y.max_save_seconds||0;if(l===0)return!0;let i=0;switch(a){case"minute":i=parseInt(e)*60;break;case"hour":i=parseInt(e)*3600;break;case"day":i=parseInt(e)*86400;break;default:return!1}return i<=l},me=()=>!(!he()||!fe(_.value)||!ve(d.value,c.value)),Pe=async()=>{if(p.value==="file"&&!_.value){g.showAlert(u("send.messages.selectFile"),"error");return}if(p.value==="text"&&!h.value.trim()){g.showAlert(u("send.messages.enterText"),"error");return}if(d.value!=="forever"&&!c.value){g.showAlert(u("send.messages.enterExpirationValue"),"error");return}if(!ve(d.value,c.value)){const a=Math.floor(y.max_save_seconds/86400);g.showAlert(u("send.messages.expirationTooLong",{days:a}),"error");return}try{let a;if(p.value==="file")try{a=await ze(_.value)}catch{y.enableChunk?a=await Z(_.value):a=await Ue(_.value)}else{const e=new FormData;e.append("text",h.value),e.append("expire_value",c.value),e.append("expire_style",d.value),a=await re.post("share/text/",e,{headers:{"Content-Type":"multipart/form-data"}})}if(a&&a.code===200){const e=a.detail?.code||"",l=a.detail?.name||"",i={id:Date.now(),filename:l,date:new Date().toISOString().split("T")[0],size:p.value==="text"?`${(h.value.length/1024).toFixed(2)} KB`:`${(_.value.size/(1024*1024)).toFixed(1)} MB`,expiration:d.value==="forever"?u("send.expiration.forever"):N(d.value,c.value),retrieveCode:e};f.addShareDataRecord(i),g.showAlert(u("send.messages.sendSuccess",{code:e}),"success"),_.value=null,h.value="",o.value=0,V(),x.value=i,await ue(e)}else throw new Error(u("send.messages.serverError"))}catch(a){if(a&&typeof a=="object"&&"response"in a){const e=a;e.response?.data?.detail&&g.showAlert(e.response.data.detail,"error")}else g.showAlert(u("send.messages.sendFailed"),"error")}finally{o.value=0}},Re=()=>{I.push("/")},ye=()=>{T.value=!T.value},Be=a=>{x.value=a},Le=a=>{const e=f.shareData.findIndex(l=>l.id===a);e!==-1&&f.deleteShareData(e)},$e=window.location.origin+"/#/",Ve=a=>`${$e}?code=${a.retrieveCode}`,xe=a=>{const l=(parseInt(c.value)||0)+a;l>=1&&(c.value=l.toString())};return Fe(()=>{console.log("SendFileView mounted")}),(a,e)=>{const l=et("router-link");return F(),U("div",{class:"min-h-screen flex items-center justify-center p-4 overflow-hidden transition-colors duration-300",onPaste:se(H,["prevent"])},[r("div",{class:n(["rounded-3xl shadow-2xl overflow-hidden border w-full max-w-md transition-colors duration-300",[t(s)?"bg-white bg-opacity-10 backdrop-filter backdrop-blur-xl border-gray-700":"bg-white border-gray-200"]])},[r("div",Ft,[S(at,{title:t(y).name,onTitleClick:Re},null,8,["title"]),r("form",{onSubmit:se(Pe,["prevent"]),class:"space-y-8"},[S(yt,{"selected-type":p.value,"onUpdate:selectedType":e[0]||(e[0]=i=>p.value=i)},null,8,["selected-type"]),S(ie,{name:"fade",mode:"out-in"},{default:te(()=>[p.value==="file"?(F(),U("div",Et,[S(Ct,{"selected-file":_.value,progress:o.value,description:`支持各种常见格式最大${t(Te)(t(y).uploadSize)}`,onFileSelected:Q,onFileDrop:Y},null,8,["selected-file","progress","description"])])):(F(),U("div",Ut,[S(At,{modelValue:h.value,"onUpdate:modelValue":e[1]||(e[1]=i=>h.value=i),placeholder:t(u)("send.uploadArea.textInput")},null,8,["modelValue","placeholder"])]))]),_:1}),r("div",zt,[r("label",{class:n(["text-sm font-medium",t(s)?"text-gray-300":"text-gray-700"])},M(t(u)("send.expiration.label")),3),r("div",Pt,[r("div",{class:n(["relative h-12 rounded-2xl border transition-all duration-300 shadow-sm",t(s)?"bg-gray-800/60 border-gray-700/60 group-hover:border-gray-600/80 group-hover:shadow-lg group-hover:shadow-gray-900/20":"bg-white border-gray-200 group-hover:border-gray-300 group-hover:shadow-md group-hover:shadow-gray-200/50"])},[d.value!=="forever"?(F(),U(de,{key:0},[ke(r("input",{"onUpdate:modelValue":e[2]||(e[2]=i=>c.value=i),type:"number",placeholder:w(),min:"1",class:n(["w-full h-full px-5 pr-32 rounded-2xl placeholder-gray-400 transition-all duration-300","focus:outline-none focus:ring-2 focus:ring-offset-0","[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none","bg-transparent",t(s)?"text-gray-100 focus:ring-indigo-500/80 placeholder-gray-500":"text-gray-900 focus:ring-indigo-500/60 placeholder-gray-400"])},null,10,Rt),[[Qe,c.value]]),r("div",{class:n(["absolute right-28 top-0 h-full flex flex-col border-l",[t(s)?"border-gray-700/60":"border-gray-200"]])},[r("button",{type:"button",onClick:e[3]||(e[3]=i=>xe(1)),class:n(["flex-1 px-2 flex items-center justify-center transition-all duration-200",[t(s)?"hover:bg-gray-700/60 text-gray-400 hover:text-gray-200":"hover:bg-gray-50 text-gray-500 hover:text-gray-700"]])},[...e[10]||(e[10]=[r("svg",{class:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 15l7-7 7 7"})],-1)])],2),r("button",{type:"button",onClick:e[4]||(e[4]=i=>xe(-1)),class:n(["flex-1 px-2 flex items-center justify-center transition-all duration-200",[t(s)?"hover:bg-gray-700/60 text-gray-400 hover:text-gray-200":"hover:bg-gray-50 text-gray-500 hover:text-gray-700"]])},[...e[11]||(e[11]=[r("svg",{class:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"})],-1)])],2)],2)],64)):K("",!0),ke(r("select",{"onUpdate:modelValue":e[5]||(e[5]=i=>d.value=i),class:n(["absolute right-0 top-0 h-full appearance-none cursor-pointer transition-all duration-300","focus:outline-none focus:ring-2 focus:ring-offset-0",d.value==="forever"?"w-full px-5 rounded-2xl":"w-28 pl-4 pr-9 border-l rounded-r-2xl",t(s)?"text-gray-100 border-gray-700/60 focus:ring-indigo-500/80 bg-gray-800/60":"text-gray-900 border-gray-200 focus:ring-indigo-500/60 bg-white"]),style:Se({color:t(s)?"#f3f4f6":"#111827",backgroundColor:t(s)?"rgba(31, 41, 55, 0.5)":"#ffffff"})},[(F(!0),U(de,null,_e(t(y).expireStyle,i=>(F(),U("option",{value:i,key:i,class:n([t(s)?"bg-gray-800 text-gray-100":"bg-white text-gray-900"]),style:Se({color:t(s)?"#f3f4f6":"#111827",backgroundColor:t(s)?"#1f2937":"#ffffff"})},M(B(i)),15,Bt))),128))],6),[[Ye,d.value]]),r("div",{class:n(["absolute pointer-events-none",[d.value==="forever"?"right-3":"right-2","top-1/2 -translate-y-1/2"]])},[(F(),U("svg",{class:n(["w-4 h-4 transition-colors duration-300",[t(s)?"text-gray-400":"text-gray-500"]]),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[...e[12]||(e[12]=[r("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"},null,-1)])],2))],2)],2)])]),r("button",Lt,[e[13]||(e[13]=r("span",{class:"absolute top-0 left-0 w-full h-full bg-white opacity-0 group-hover:opacity-20 transition-opacity duration-300"},null,-1)),r("span",$t,[S(t(ft),{class:"w-6 h-6 mr-2"}),r("span",null,M(t(u)("send.submit")),1)])])],32),r("div",Vt,[S(l,{to:"/",class:"text-indigo-400 hover:text-indigo-300 transition duration-300"},{default:te(()=>[ce(M(t(u)("send.needRetrieveFile")),1)]),_:1})])]),r("div",{class:n(["px-8 py-4 bg-opacity-50 flex justify-between items-center",[t(s)?"bg-gray-800":"bg-gray-100"]])},[r("span",{class:n(["text-sm flex items-center",[t(s)?"text-gray-300":"text-gray-800"]])},[S(t(Me),{class:"w-4 h-4 mr-1 text-green-400"}),ce(" "+M(t(u)("send.secureEncryption")),1)],2),r("button",{onClick:ye,class:n(["text-sm hover:text-indigo-300 transition duration-300 flex items-center",[t(s)?"text-indigo-400":"text-indigo-600"]])},[ce(M(t(u)("send.sendRecords"))+" ",1),S(t(ot),{class:"w-4 h-4 ml-1"})],2)],2)],2),S(ie,{name:"drawer"},{default:te(()=>[T.value?(F(),U("div",{key:0,class:n(["fixed inset-y-0 right-0 w-full sm:w-120 bg-opacity-70 backdrop-filter backdrop-blur-xl shadow-2xl z-50 overflow-hidden flex flex-col",[t(s)?"bg-gray-900":"bg-white"]])},[r("div",{class:n(["flex justify-between items-center p-6 border-b",[t(s)?"border-gray-700":"border-gray-200"]])},[r("h3",{class:n(["text-2xl font-bold",[t(s)?"text-white":"text-gray-800"]])},M(t(u)("send.sendRecords")),3),r("button",{onClick:ye,class:n(["hover:text-white transition duration-300",[t(s)?"text-gray-400":"text-gray-800"]])},[S(t(Ce),{class:"w-6 h-6"})],2)],2),r("div",jt,[S(tt,{name:"list",tag:"div",class:"space-y-4"},{default:te(()=>[(F(!0),U(de,null,_e(C.value,i=>(F(),U("div",{key:i.id,class:n(["bg-opacity-50 rounded-lg p-4 flex items-center shadow-md hover:shadow-lg transition duration-300 transform hover:scale-102",[t(s)?"bg-gray-800 hover:bg-gray-700":"bg-gray-100 hover:bg-white"]])},[r("div",Nt,[S(t(Ie),{class:n(["w-10 h-10",[t(s)?"text-indigo-400":"text-indigo-600"]])},null,8,["class"])]),r("div",Gt,[r("p",{class:n(["font-medium text-lg truncate",[t(s)?"text-white":"text-gray-800"]])},M(i.filename?i.filename:"Text"),3),r("p",{class:n(["text-sm truncate",[t(s)?"text-gray-400":"text-gray-600"]])},M(i.date)+" · "+M(i.size),3)]),r("div",Ht,[r("button",{onClick:k=>t(ue)(i.retrieveCode),class:n(["p-2 rounded-full hover:bg-opacity-20 transition duration-300",[t(s)?"hover:bg-blue-400 text-blue-400":"hover:bg-blue-100 text-blue-600"]])},[S(t(pe),{class:"w-5 h-5"})],10,Ot),r("button",{onClick:k=>Be(i),class:n(["p-2 rounded-full hover:bg-opacity-20 transition duration-300",[t(s)?"hover:bg-green-400 text-green-400":"hover:bg-green-100 text-green-600"]])},[S(t(dt),{class:"w-5 h-5"})],10,qt),r("button",{onClick:k=>Le(i.id),class:n(["p-2 rounded-full hover:bg-opacity-20 transition duration-300",[t(s)?"hover:bg-red-400 text-red-400":"hover:bg-red-100 text-red-600"]])},[S(t(ct),{class:"w-5 h-5"})],10,Xt)])],2))),128))]),_:1})])],2)):K("",!0)]),_:1}),S(ie,{name:"fade"},{default:te(()=>[x.value?(F(),U("div",Zt,[r("div",{class:n(["w-full max-w-2xl rounded-2xl shadow-2xl transform transition-all duration-300 ease-out overflow-hidden",[t(s)?"bg-gray-900 bg-opacity-70":"bg-white bg-opacity-95"]])},[r("div",{class:n(["px-4 sm:px-6 py-3 sm:py-4 border-b",[t(s)?"border-gray-800":"border-gray-100"]])},[r("div",Wt,[r("h3",{class:n(["text-lg sm:text-xl font-semibold",[t(s)?"text-white":"text-gray-900"]])},M(t(u)("send.fileDetails")),3),r("button",{onClick:e[6]||(e[6]=i=>x.value=null),class:"p-1.5 sm:p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"},[S(t(Ce),{class:n(["w-4 h-4 sm:w-5 sm:h-5",[t(s)?"text-gray-400":"text-gray-500"]])},null,8,["class"])])])],2),r("div",Jt,[r("div",{class:n(["rounded-xl p-3 sm:p-4 mb-4 sm:mb-6",[t(s)?"bg-gray-800 bg-opacity-50":"bg-gray-50 bg-opacity-95"]])},[r("div",Kt,[r("div",{class:n(["p-2 sm:p-3 rounded-lg",[t(s)?"bg-gray-800":"bg-white"]])},[S(t(Ie),{class:n(["w-5 h-5 sm:w-6 sm:h-6",[t(s)?"text-indigo-400":"text-indigo-600"]])},null,8,["class"])],2),r("div",Qt,[r("h4",{class:n(["font-medium text-sm sm:text-base truncate",[t(s)?"text-white":"text-gray-900"]])},M(x.value.filename),3),r("p",{class:n(["text-xs sm:text-sm truncate",[t(s)?"text-gray-400":"text-gray-500"]])},M(x.value.size)+" · "+M(x.value.date),3)])]),r("div",Yt,[r("div",er,[S(t(pt),{class:n(["w-3.5 h-3.5 sm:w-4 sm:h-4 mr-1.5 sm:mr-2 flex-shrink-0",[t(s)?"text-gray-400":"text-gray-500"]])},null,8,["class"]),r("span",{class:n(["text-xs sm:text-sm truncate",[t(s)?"text-gray-300":"text-gray-600"]])},M(x.value.expiration),3)]),r("div",tr,[S(t(Me),{class:n(["w-3.5 h-3.5 sm:w-4 sm:h-4 mr-1.5 sm:mr-2 flex-shrink-0",[t(s)?"text-gray-400":"text-gray-500"]])},null,8,["class"]),r("span",{class:n(["text-xs sm:text-sm truncate",[t(s)?"text-gray-300":"text-gray-600"]])}," 安全加密 ",2)])])],2),r("div",rr,[r("div",sr,[r("div",ar,[r("div",or,[e[14]||(e[14]=r("h4",{class:"font-medium text-sm sm:text-base"},"取件码",-1)),r("button",{onClick:e[7]||(e[7]=i=>t(nt)(x.value.retrieveCode)),class:"p-1.5 sm:p-2 rounded-full hover:bg-white/10 transition-colors"},[S(t(pe),{class:"w-4 h-4 sm:w-5 sm:h-5"})])]),r("p",nr,M(x.value.retrieveCode),1)]),r("div",{class:n(["rounded-xl p-3 sm:p-4",[t(s)?"bg-gray-800 bg-opacity-50":"bg-gray-50 bg-opacity-95"]])},[r("div",lr,[r("h4",{class:n(["font-medium text-sm sm:text-base flex items-center min-w-0",[t(s)?"text-white":"text-gray-900"]])},[S(t(vt),{class:"w-4 h-4 sm:w-5 sm:h-5 mr-1.5 sm:mr-2 text-indigo-500 flex-shrink-0"}),e[15]||(e[15]=r("span",{class:"truncate"},"wget下载",-1))],2),r("button",{onClick:e[8]||(e[8]=i=>t(lt)(x.value.retrieveCode,x.value.filename)),class:"p-1.5 sm:p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors flex-shrink-0"},[S(t(pe),{class:n(["w-4 h-4 sm:w-5 sm:h-5",[t(s)?"text-gray-400":"text-gray-500"]])},null,8,["class"])])]),r("p",{class:n(["text-xs sm:text-sm font-mono break-all line-clamp-2",[t(s)?"text-gray-300":"text-gray-600"]])}," 点击复制wget命令 ",2)],2)]),r("div",{class:n(["rounded-xl p-4 sm:p-5 flex flex-col items-center",[t(s)?"bg-gray-800 bg-opacity-50":"bg-gray-50 bg-opacity-95"]])},[r("div",ir,[S(it,{value:Ve(x.value),size:140,level:"M",class:"sm:w-[160px] sm:h-[160px]"},null,8,["value"])]),r("p",{class:n(["text-xs sm:text-sm truncate max-w-full",[t(s)?"text-gray-400":"text-gray-500"]])}," 扫描二维码快速取件 ",2)],2)])]),r("div",{class:n(["px-4 sm:px-6 py-3 sm:py-4 border-t",[t(s)?"border-gray-800":"border-gray-100"]])},[r("button",{onClick:e[9]||(e[9]=i=>t(ue)(x.value.retrieveCode)),class:"w-full bg-indigo-600 hover:bg-indigo-700 text-white px-4 sm:px-6 py-2 sm:py-3 rounded-lg text-sm sm:text-base font-medium transition-colors"}," 复制取件链接 ")],2)],2)])):K("",!0)]),_:1})],32)}}}),fr=ge(dr,[["__scopeId","data-v-832d304e"]]);export{fr as default};