Files
archy-demo/web-dist/assets/PeerFiles-qTLuUhI-.js

2 lines
6.5 KiB
JavaScript

import{d as D,o as R,B as g,c as r,a as t,J as N,m as T,a1 as U,D as l,F as A,P as E,r as u,j as H,x as O,f as x,G as S,q as o}from"./index-DnbYEqLr.js";const G={class:"pb-6"},$={class:"shrink-0 mb-4"},q={class:"flex items-center gap-4"},J={class:"hidden md:block"},K={class:"text-2xl font-bold text-white"},Q={class:"text-sm text-white/50"},X={key:0,class:"glass-card p-8 text-center"},Y={key:1,class:"glass-card p-6"},Z={class:"text-red-400 text-sm mb-3"},ee={key:2,class:"glass-card p-8 text-center"},te={key:3,class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"},ne=["d"],se={class:"flex-1 min-w-0"},oe={class:"text-sm font-medium text-white truncate"},re={class:"text-xs text-white/40"},ae={class:"flex items-center gap-2"},le=["disabled","onClick"],ce=D({__name:"PeerFiles",props:{peerId:{}},setup(b){const i=b,y=O(),c=u(!0),a=u(null),d=u(""),p=u([]),f=u(null),_=H(()=>a.value?.name?a.value.name:a.value?.did?C(a.value.did):i.peerId?B(i.peerId):"Peer Files");function v(){y.push({name:"cloud"})}R(async()=>{if(i.peerId){try{const n=(await g.federationListNodes())?.nodes??[];a.value=n.find(s=>s.onion===i.peerId)||null}catch{}await m()}else c.value=!1});async function m(){const e=i.peerId||a.value?.onion;if(e){c.value=!0,d.value="",p.value=[];try{const n=await g.call({method:"content.browse-peer",params:{onion:e},timeout:3e4});p.value=n?.items??[]}catch(n){d.value=n instanceof Error?n.message:"Failed to connect to peer"}finally{c.value=!1}}}function C(e){return e.length<=24?e:e.slice(0,16)+"..."+e.slice(-8)}function B(e){return e.length<=20?e:e.slice(0,12)+"..."}function M(e){if(e===0)return"0 B";const n=["B","KB","MB","GB"],s=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,s)).toFixed(s>0?1:0)+" "+n[s]}function j(e){return e.startsWith("image/")?"bg-blue-500/15":e.startsWith("audio/")?"bg-orange-500/15":e.startsWith("video/")?"bg-pink-500/15":e.startsWith("text/")?"bg-green-500/15":"bg-white/10"}function I(e){return e.startsWith("image/")?"text-blue-400":e.startsWith("audio/")?"text-orange-400":e.startsWith("video/")?"text-pink-400":e.startsWith("text/")?"text-green-400":"text-white/60"}function W(e){return e.startsWith("image/")?"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z":e.startsWith("audio/")?"M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3":e.startsWith("video/")?"M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z":"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"}function z(e){return e==="free"?"Free":e==="peersonly"?"Peers Only":typeof e=="object"&&"paid"in e?`${e.paid.price_sats} sats`:String(e)}function L(e){return e==="free"?"bg-green-500/15 text-green-400":e==="peersonly"?"bg-blue-500/15 text-blue-400":typeof e=="object"&&"paid"in e?"bg-orange-500/15 text-orange-400":"bg-white/10 text-white/50"}function V(e){return e==="free"||e==="peersonly"}async function F(e){const n=i.peerId||a.value?.onion;if(n){f.value=e.id;try{const s=await g.call({method:"content.download-peer",params:{onion:n,content_id:e.id},timeout:12e4});if(s?.data){const w=new Blob([Uint8Array.from(atob(s.data),P=>P.charCodeAt(0))],{type:e.mime_type}),k=URL.createObjectURL(w),h=document.createElement("a");h.href=k,h.download=e.filename.split("/").pop()||e.filename,h.click(),URL.revokeObjectURL(k)}}catch{}finally{f.value=null}}}return(e,n)=>(o(),r("div",G,[t("div",$,[t("button",{onClick:v,class:"hidden md:flex mb-4 items-center gap-2 text-white/70 hover:text-white transition-colors"},[...n[0]||(n[0]=[t("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 19l-7-7 7-7"})],-1),N(" Back to Cloud ",-1)])]),(o(),T(U,{to:"body"},[t("button",{onClick:v,class:"md:hidden mobile-back-btn glass-button px-6 py-3 rounded-lg font-medium shadow-2xl flex items-center justify-center gap-2"},[...n[1]||(n[1]=[t("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 19l-7-7 7-7"})],-1),t("span",null,"Back to Cloud",-1)])])])),t("div",q,[n[2]||(n[2]=t("div",{class:"flex-shrink-0 w-12 h-12 rounded-xl flex items-center justify-center bg-purple-500/15"},[t("svg",{class:"w-7 h-7 text-purple-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2"})])],-1)),t("div",J,[t("h1",K,l(_.value),1),t("p",Q,l(a.value?.onion||"Peer files"),1)])])]),c.value?(o(),r("div",X,[...n[3]||(n[3]=[t("svg",{class:"animate-spin h-6 w-6 text-purple-400 mx-auto mb-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[t("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),t("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1),t("p",{class:"text-white/50 text-sm"},"Connecting via Tor... This may take a few seconds.",-1)])])):d.value?(o(),r("div",Y,[t("p",Z,l(d.value),1),t("button",{class:"glass-button px-4 py-2 rounded-lg text-sm",onClick:m},"Retry")])):p.value.length===0&&!c.value?(o(),r("div",ee,[...n[4]||(n[4]=[t("p",{class:"text-white/50"},"This peer has no shared files.",-1)])])):(o(),r("div",te,[(o(!0),r(A,null,E(p.value,s=>(o(),r("div",{key:s.id,class:"glass-card p-4 flex items-center gap-4"},[t("div",{class:x(["flex-shrink-0 w-10 h-10 rounded-lg flex items-center justify-center",j(s.mime_type)])},[(o(),r("svg",{class:x(["w-5 h-5",I(s.mime_type)]),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:W(s.mime_type)},null,8,ne)],2))],2),t("div",se,[t("p",oe,l(s.filename),1),t("p",re,l(M(s.size_bytes)),1)]),t("div",ae,[t("span",{class:x(["text-xs px-2 py-0.5 rounded-full",L(s.access)])},l(z(s.access)),3),V(s.access)?(o(),r("button",{key:0,class:"glass-button px-3 py-1.5 rounded-lg text-xs font-medium",disabled:f.value===s.id,onClick:w=>F(s)},l(f.value===s.id?"...":"Download"),9,le)):S("",!0)])]))),128))]))]))}});export{ce as default};