1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/moderate-upload-BvipGHo3.js","assets/index-CiCw9Duq.js","assets/vendor-solana-BIelvPCZ.js","assets/vendor-i18n-BBu7i065.js","assets/vendor-react-BL5zx_iT.js","assets/vendor-ui-Ct1FBp4w.js","assets/vendor-supabase-DbyvBBOg.js","assets/index-DY1GOUxd.css","assets/image-compression-CVvWTbT5.js","assets/vendor-imaging-1cz-p0Wq.js"])))=>i.map(i=>d[i]); 2import{_ as F}from"./vendor-solana-BIelvPCZ.js";import{s as i,f as ue}from"./index-CiCw9Duq.js";import{b as Ce}from"./supabase-boosts-CUjpK0O_.js";import{checkR2Status as Q,uploadImageToR2 as _e}from"./r2-upload-BrkyCMx4.js";import"./vendor-i18n-BBu7i065.js";import"./vendor-react-BL5zx_iT.js";import"./vendor-ui-Ct1FBp4w.js";import"./vendor-supabase-DbyvBBOg.js";const q="id, user_id, content, media_urls, media_dimensions, likes_count, reposts_count, replies_count, created_at, edited_at, visibility, reply_to_post_id, repost_of_post_id, is_paid, price, preview_text, paid_media_urls, title, topic, is_nsfw, content_warning, is_hidden, thumbnail_url, allow_download",Y=async e=>{if(!e)return new Set;try{const[{data:s},{data:t}]=await Promise.all([i.from("blocks").select("blocked_id").eq("blocker_id",e),i.from("mutes").select("muted_id").eq("muter_id",e)]),r=s?.map(c=>c.blocked_id)||[],l=t?.map(c=>c.muted_id)||[];return new Set([...r,...l])}catch(s){return console.warn("Error fetching blocked/muted users:",s),new Set}};async function Ve(e){if(!e||e.length===0)return[];const{data:s}=await i.from("posts").select(q).in("id",e);if(!s)return[];const t=Array.from(new Set(s.map(d=>
2d.user_id))),r=s.filter(d=>d.repost_of_post_id).map(d=>d.repost_of_post_id),[{data:l},{data:c},{data:u}]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").in("id",t),i.from("creator_profiles").select("user_id, avatar").in("user_id",t),r.length>0?i.from("posts").select(q).in("id",r):Promise.resolve({data:[]})]),p=new Map((l||[]).map(d=>[d.id,d])),_=new Map((c||[]).map(d=>[d.user_id,d])),a=new Map((u||[]).map(d=>[d.id,d])),m=(u||[]).map(d=>d.user_id).filter(d=>!p.has(d));if(m.length>0){const[{data:d},{data:f}]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").in("id",m),i.from("creator_profiles").select("user_id, avatar").in("user_id",m)]);(d||[]).forEach(b=>p.set(b.id,b)),(f||[]).forEach(b=>_.set(b.user_id,b))}const n=new Map(s.map(d=>[d.id,d]));return e.map(d=>n.get(d)).filter(Boolean).map(d=>{const f={...d,user:p.get(d.user_id),creator_profile:_.get(d.user_id)};if(d.repost_of_post_id&&a.has(d.repost_of_post_id)){const b=a.get(d.repost_of_post_id);f.repost_of={...b,user:p.get(b.user_id),creator_profile:_.get(b.user_id)}}return f})}const z={uploadPostMedia:async(e,s)=>{const t=s.type.startsWith("video/"),r=t?"post-videos":"post-images",l=async n=>{try{const{moderateUploadedMedia:d}=await F(async()=>{const{moderateUploadedMedia:b}=await import("./moderate-upload-BvipGHo3.js");return{moderateUploadedMedia:b}},__vite__mapDeps([0,1,2,3,4,5,6,7])),f=await d(n,t?"video":"image");if(!f.ok)throw new Error(f.reason||"This media violates our content policy and cannot be posted.")}catch(d){if(d?.message?.includes("policy"))throw d;console.warn("[uploadPostMedia] moderation check failed (allowing):",d?.message)}};let c=s;if(!t&&s.type.startsWith("image/"))try{const{compressPostImage:n}=await F(async()=>{const{compressPostImage:d}=await import("./image-compression-CVvWTbT5.js");return{compressPostImage:d}},__vite__mapDeps([8,9]));c=await n(s)}catch(n){console.error("[uploadPostMedia] Compression failed, using original:",n),c=s}if(!t)try{if(await Q()){const d=await _e(c,"post-images");return await l(d),d}}catch(n){if(n?.message?.includes("policy"))throw n;console.warn("[uploadPostMedia] R2 upload failed, falling back to Supabase:",n)}const u=c.name.split(".").pop()?.toLowerCase()||"webp",p=`${e}-${Date.now()}-${Math.random().toString(36).slice(2,8)}.${u}`,_=`${e}/${p}`,{error:a}=await i.storage.from(r).upload(_,c,{cacheControl:"31536000",upsert:!1});if(a)throw new Error(a.message||"Failed to upload media");const{data:{publicUrl:m}}=i.storage.from(r).getPublicUrl(_);return await l(m),m},uploadPostImage:async(e,s)=>z.uploadPostMedia(e,s),getFeed:async(e=20,s=0,t)=>{try{const r=Math.max(e*2,40),{data:l,error:c}=await i.from("posts").select(q).in("visibility",["public","subscribers"]).is("reply_to_post_id",null).or("r2_ready.eq.true,r2_ready.is.null,has_video.eq.false,has_video.is.null").order("created_at",{ascending:!1}).range(s,s+r-1);if(c)return c.message?.includes("Failed to fetch")||console.error("Error fetching feed:",c.message),[];if(!l||l.length===0)return[];const u=await Y(t),p=[...new Set(l.filter(g=>!u.has(g.user_id)).map(g=>g.user_id))],_=l.filter(g=>g.repost_of_post_id).map(g=>g.repost_of_post_id);let a=new Map;if(_.length>0){const{data:g}=await i.from("posts").select(q).in("id",_);g&&(g.forEach(k=>{p.includes(k.user_id)||p.push(k.user_id)}),a=new Map(g.map(k=>[k.id,k])))}const[{data:m,error:n},{data:d}]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_banned, is_diamond_member, avatar_url, account_type").in("id",p),i.from("creator_profiles").select("user_id, avatar").in("user_id",p)]);n&&console.error("Error fetching users for posts:",n.message);const f=new Map(m?.map(g=>[g.id,g])||[]),b=new Set(m?.filter(g=>g.is_banned).map(g=>g.id)||[]),M=new Map(d?.map(g=>[g.user_id,g])||[]),R=l.filter(g=>!b.has(g.user_id)&&!u.has(g.user_id)&&!g.is_hidden),T="a0000001-5eed-4000-a000-000000000fff",S=Math.random()<.05;let E=!1;const w=new Map;return R.filter(g=>
2{if(g.user_id===T)return!S||E?!1:(E=!0,!0);const k=w.get(g.user_id)||0;return k>=3?!1:(w.set(g.user_id,k+1),!0)}).slice(0,e).map(g=>{const k={...g,user:f.get(g.user_id),creator_profile:M.get(g.user_id)};if(g.repost_of_post_id&&a.has(g.repost_of_post_id)){const A=a.get(g.repost_of_post_id);k.repost_of={...A,user:f.get(A.user_id),creator_profile:M.get(A.user_id)}}return k})}catch{return[]}},getFollowingFeed:async(e,s=20,t=0)=>{const r=await Y(e),{data:l,error:c}=await i.from("follows").select("following_id").eq("follower_id",e);if(c)return c.message?.includes("Failed to fetch")||console.error("Error fetching following:",c.message),[];if(!l||l.length===0)return[];const u=l.map(w=>w.following_id).filter(w=>!r.has(w)),{data:p,error:_}=await i.from("posts").select(q).in("user_id",u).in("visibility",["public","subscribers"]).is("reply_to_post_id",null).or("r2_ready.eq.true,r2_ready.is.null,has_video.eq.false,has_video.is.null").order("created_at",{ascending:!1}).range(t,t+s-1);if(_)return _.message?.includes("Failed to fetch")||console.error("Error fetching following feed:",_.message),[];if(!p||p.length===0)return[];const a=[...new Set(p.map(w=>w.user_id))],m=p.filter(w=>w.repost_of_post_id).map(w=>w.repost_of_post_id);let n=new Map;if(m.length>0){const{data:w}=await i.from("posts").select(q).in("id",m);w&&(w.forEach(D=>{a.includes(D.user_id)||a.push(D.user_id)}),n=new Map(w.map(D=>[D.id,D])))}const{data:d}=await i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_banned, is_diamond_member, avatar_url, account_type").in("id",a),f=new Map(d?.map(w=>[w.id,w])||[]),b=new Set(d?.filter(w=>w.is_banned).map(w=>w.id)||[]),{data:M}=await i.from("creator_profiles").select("user_id, avatar").in("user_id",a),R=new Map(M?.map(w=>[w.user_id,w])||[]),T="a0000001-5eed-4000-a000-000000000fff",S=Math.random()<.05;let E=!1;return p.filter(w=>{if(b.has(w.user_id)||r.has(w.user_id))return!1;if(w.user_id===T){if(!S||E)return!1;E=!0}return!0}).map(w=>{const D={...w,user:f.get(w.user_id),creator_profile:R.get(w.user_id)};if(w.repost_of_post_id&&n.has(w.repost_of_post_id)){const g=n.get(w.repost_of_post_id);D.repost_of={...g,user:f.get(g.user_id),creator_profile:R.get(g.user_id)}}return D})},getAlgorithmicFeed:async(e,s=20,t=0)=>{try{if(e&&typeof navigator<"u"&&navigator.onLine!==!1)try{let o=null;try{const{data:h}=await i.auth.getSession();o=h?.session?.access_token||null}catch{o=null}if(o){const{safeFetch:h}=await F(async()=>{const{safeFetch:P}=await import("./safe-fetch-CeDOm-Xr.js");return{safeFetch:P}},[]),y=await h(`/api/feed/rank?limit=${s}&offset=${t}`,{headers:{Authorization:`Bearer ${o}`},timeoutMs:4e3});if(y&&y.ok){let P=null;try{P=await y.json()}catch{P=null}const v=Array.isArray(P?.post_ids)?P.post_ids:[];if(v.length>0){let O=[];try{O=await Ve(v)}catch{O=[]}if(O.length>0)return O}}}}catch{}const r=await Y(e),l=new Date;l.setDate(l.getDate()-14);const{data:c,error:u}=await i.from("posts").select(q).in("visibility",["public","subscribers"]).is("reply_to_post_id",null).or("r2_ready.eq.true,r2_ready.is.null,has_video.eq.false,has_video.is.null").gte("created_at",l.toISOString()).order("created_at",{ascending:!1}).limit(300);if(u||!c||c.length===0)return z.getFeed(s,t,e);const p=[...new Set(c.filter(o=>!r.has(o.user_id)).map(o=>o.user_id))],[_,a,m,n,d,f]=await Promise.all([e?i.from("follows").select("following_id").eq("follower_id",e):Promise.resolve({data:null}),e?i.from("user_topics").select("topic_slug").eq("user_id",e):Promise.resolve({data:null}),i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type, created_at").in("id",p),i.from("creator_profiles").select("user_id, avatar").in("user_id",p),e?i.from("user_author_affinity").select("author_id, affinity_score").eq("user_id",e):Promise.resolve({data:null}),e?i.from("not_interested").select("post_id, author_id").eq("user_id",e):Promise.resolve({data:null})]),b=new Set(_.data?.map(o=>o.following_id)||[]),M=new Set(a.data?.map(o=>o.topic_slug)||[]),R=new Map;(d.data||[]).forEach(o=>{o.author_id&&R.set(o.author_id,Number(o.affinity_score)||0)});const T=new Set,S=new Map;
2(f.data||[]).forEach(o=>{o.post_id&&T.add(o.post_id),o.author_id&&S.set(o.author_id,(S.get(o.author_id)||0)+1)});const E=m.data,w=new Map(E?.map(o=>[o.id,o])||[]),D=new Map(n.data?.map(o=>[o.user_id,o])||[]),g=c.filter(o=>o.repost_of_post_id).map(o=>o.repost_of_post_id);let k=new Map;if(g.length>0){const{data:o}=await i.from("posts").select(q).in("id",g);if(o){o.forEach(y=>{p.includes(y.user_id)||p.push(y.user_id)}),k=new Map(o.map(y=>[y.id,y]));const h=o.map(y=>y.user_id).filter(y=>!w.has(y));if(h.length>0){const[{data:y},{data:P}]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type, created_at").in("id",h),i.from("creator_profiles").select("user_id, avatar").in("user_id",h)]);y?.forEach(v=>{w.set(v.id,v)}),P?.forEach(v=>D.set(v.user_id,v))}}}let A=new Map;try{A=await Ce()}catch{}const H=Date.now(),fe=o=>{const h=w.get(o.user_id),P=(H-new Date(o.created_at).getTime())/(1e3*60*60),v=Math.pow(.5,P/24),O=o.likes_count||0,$=o.replies_count||0,ce=o.reposts_count||0,qe=Math.log10(1+O*1+$*2+ce*1.5),Re=b.has(o.user_id)?2.5:1,De=h?.verified||h?.is_lifetime_member||h?.is_diamond_member||h?.account_type==="business"?1.3:1,Fe=o.media_urls&&o.media_urls.length>0?1.4:1,de=(o.content||"").length,Te=de>80?1.2:de>30?1:.9,Oe=.5+Math.random()*1,le=A.get(o.id),Ae=le?le.multiplier:1,Ie=o.topic&&M.size>0&&M.has(o.topic)?2.5:1,Ue=R.get(o.user_id)||0,$e=1+Math.min(2,Math.log10(1+Ue)*1.2),pe=S.get(o.user_id)||0,Le=pe>0?Math.pow(.5,pe):1,Ne=h?.created_at?(H-new Date(h.created_at).getTime())/(1e3*60*60*24):365,Be=O+$+ce<1,je=Ne<2&&Be&&!h?.verified?.4:1,xe=v*(1+qe)*Re*De*Fe*Te*Oe*Ae*Ie*$e*Le*je;return{post:o,score:xe,user:h}},K=c.map(fe);K.sort((o,h)=>h.score-o.score);const me="a0000001-5eed-4000-a000-000000000fff",he=Math.random()<.05;let X=!1;const Z=`feed_seen_${e||"anon"}`;let C=new Set;try{const o=sessionStorage.getItem(Z);o&&(C=new Set(JSON.parse(o)))}catch{}const ee=new Map,te=new Set,V=[],se=[];for(const o of K){const{post:h}=o;if(r.has(h.user_id)||T.has(h.id)||(S.get(h.user_id)||0)>=3)continue;const y=h.repost_of_post_id||h.id;if(te.has(y))continue;if(te.add(y),h.user_id===me){if(!he||X)continue;X=!0,V.push(o);continue}const P=ee.get(h.user_id)||0;P>=3||(ee.set(h.user_id,P+1),C.has(y)?se.push(o):V.push(o))}const oe=(o,h=5)=>{const y=[];for(let P=0;P<o.length;P+=h){const v=o.slice(P,P+h);for(let O=v.length-1;O>0;O--){const $=Math.floor(Math.random()*(O+1));[v[O],v[$]]=[v[$],v[O]]}y.push(...v)}for(let P=1;P<y.length;P++)if(y[P].post.user_id===y[P-1].post.user_id){for(let v=P+1;v<Math.min(P+4,y.length);v++)if(y[v].post.user_id!==y[P-1].post.user_id){[y[P],y[v]]=[y[v],y[P]];break}}return y},U=oe(V),ge=oe(se,8),L=o=>b.has(o.post.user_id)||(R.get(o.post.user_id)||0)>5,J=o=>!!o.post.topic&&M.has(o.post.topic),re=o=>{const h=o.post;return(h.likes_count||0)+(h.replies_count||0)*2+(h.reposts_count||0)*1.5},we=U.filter(L),ye=U.filter(o=>!L(o)&&J(o)),be=[...U].filter(o=>!L(o)&&!J(o)).sort((o,h)=>re(h)-re(o)),I=U.filter(o=>!L(o)&&!J(o));for(let o=I.length-1;o>0;o--){const h=Math.floor(Math.random()*(o+1));[I[o],I[h]]=[I[h],I[o]]}const N=Math.max(s,60),B={followed:Math.round(N*.5),topic:Math.round(N*.25),trending:Math.round(N*.15),exploration:Math.round(N*.1)},G=new Set,j=(o,h)=>{const y=[];for(const P of o){if(y.length>=h)break;G.has(P.post.id)||(G.add(P.post.id),y.push(P))}return y},Pe=j(we,B.followed),ve=j(ye,B.topic),Ee=j(be,B.trending),Me=j(I,B.exploration),Se=[Pe,ve,Ee,Me],ae=[];let W=!0;for(;W;){W=!1;for(const o of Se){const h=o.shift();h&&(ae.push(h),W=!0)}}const ke=U.filter(o=>!G.has(o.post.id)),ie=[...ae,...ke,...ge].slice(t,t+s),ne=new Set(C);ie.forEach(({post:o})=>{const h=o.repost_of_post_id||o.id;ne.add(h)});const x=[...ne];x.length>500&&x.splice(0,x.length-500);try{sessionStorage.setItem(Z,JSON.stringify(x))}catch{}return ie.map(({post:o})=>{const h={...o,user:w.get(o.user_id),creator_profile:D.get(o.user_id)};if(o.repost_of_post_id&&k.has(o.repost_of_post_id)){const y=k.get(o.repost_of_post_id);h.repost_of={...y,user:w.get(y.user_id),creator_profile:D.get(y.user_id
2)}}return h})}catch{try{return await z.getFeed(s,t,e)}catch{return[]}}},getByUser:async(e,s=50,t=!1)=>{let r=i.from("posts").select(q).eq("user_id",e).is("reply_to_post_id",null);t?r=r.in("visibility",["public","subscribers"]):r=r.eq("visibility","public");const{data:l,error:c}=await r.order("created_at",{ascending:!1}).limit(s);if(c)return console.error("Error fetching user posts:",c.message),[];if(!l||l.length===0)return[];const u=l.filter(f=>f.repost_of_post_id).map(f=>f.repost_of_post_id),p=[e];let _=new Map;if(u.length>0){const{data:f}=await i.from("posts").select(q).in("id",u);f&&(f.forEach(b=>{p.includes(b.user_id)||p.push(b.user_id)}),_=new Map(f.map(b=>[b.id,b])))}const[a,m]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").in("id",p),i.from("creator_profiles").select("user_id, avatar").in("user_id",p)]),n=new Map(a.data?.map(f=>[f.id,f])||[]),d=new Map(m.data?.map(f=>[f.user_id,f])||[]);return l.map(f=>{const b={...f,user:n.get(f.user_id),creator_profile:d.get(f.user_id)};if(f.repost_of_post_id&&_.has(f.repost_of_post_id)){const M=_.get(f.repost_of_post_id);
2b.repost_of={...M,user:n.get(M.user_id),creator_profile:d.get(M.user_id)}}return b})},getUserReplies:async(e,s=50)=>{const{data:t,error:r}=await i.from("posts").select(q).eq("user_id",e).not("reply_to_post_id","is",null).order("created_at",{ascending:!1}).limit(s);if(r||!t||t.length===0)return[];const l=[...new Set(t.map(n=>n.reply_to_post_id).filter(Boolean))],c=[e];let u=new Map;if(l.length>0){const{data:n}=await i.from("posts").select("id, user_id, content").in("id",l);n&&(n.forEach(d=>{c.includes(d.user_id)||c.push(d.user_id)}),u=new Map(n.map(d=>[d.id,d])))}const[{data:p},{data:_}]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").in("id",c),i.from("creator_profiles").select("user_id, avatar").in("user_id",c)]),a=new Map(p?.map(n=>[n.id,n])||[]),m=new Map(_?.map(n=>[n.user_id,n])||[]);return t.map(n=>{const d=u.get(n.reply_to_post_id),f=d?a.get(d.user_id):null;return{...n,user:a.get(n.user_id),creator_profile:m.get(n.user_id),reply_to_user:f||null}})},create:async(e,s,t=[],r="public",l,c,u,p,_,a,m,n)=>{if(!s.trim()&&(!t||t.length===0))throw new Error("Cannot create an empty post");const d=["/api/posts/create","/.netlify/functions/create-post"],f=!!c,b=r==="paid_content"&&u&&u>0,M=JSON.stringify({userId:e,content:s,mediaUrls:t,visibility:r==="paid_content"?"paid_content":r,title:l||void 0,isNsfw:f||void 0,contentWarning:c||void 0,isPaid:b||void 0,price:b?u:void 0,platformCutPercent:b&&p?p:void 0,videoQuality:_||void 0,needsEncoding:a||void 0,thumbnailUrl:m||void 0,allowDownload:n===!0?!0:void 0});let R=null;const{authFetch:T}=await F(async()=>{const{authFetch:S}=await import("./index-CiCw9Duq.js").then(E=>E.ag);return{authFetch:S}},__vite__mapDeps([1,2,3,4,5,6,7]));for(const S of d)try{const E=await T(S,{method:"POST",body:M});if(E.ok){const D=await E.json();return F(async()=>{const{track:g}=await import("./index-CiCw9Duq.js").then(k=>k.ah);return{track:g}},__vite__mapDeps([1,2,3,4,5,6,7])).then(({track:g})=>g("post.created",{feature:"composer",props:{visibility:r,has_media:!!t?.length,media_count:t?.length||0,is_paid:!!b}})),D.post}const w=await E.json().catch(()=>({}));if(E.status===404||E.status===502)continue;R=w.error||`Server error (${E.status})`,console.error(`Error from ${S}:`,R)}catch(E){console.warn(`Endpoint ${S} unreachable:`,E.message);continue}throw new Error(R||"Failed to create post â please check your connection and try again")},updateContent:async(e,s)=>{const{authFetch:t}=await F(async()=>{const{authFetch:l}=await import("./index-CiCw9Duq.js").then(c=>c.ag);return{authFetch:l}},__vite__mapDeps([1,2,3,4,5,6,7])),r=await t("/api/posts/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({postId:e,content:s})});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error||"Failed to update post")}},delete:async e=>{const{error:s}=await i.from("posts").delete().eq("id",e);if(s)throw console.error("Error deleting post:",s.message),new Error(s.message||"Failed to delete post")},like:async(e,s)=>{await ue();const{error:t}=await i.from("post_likes").insert({post_id:e,user_id:s});if(t){if(t.code==="23505")return;throw console.error("Error liking post:",t.message),new Error(t.message||"Failed to like post")}},unlike:async(e,s)=>{await ue();const{error:t}=await i.from("post_likes").delete().eq("post_id",e).eq("user_id",s);if(t)throw console.error("Error unliking post:",t.message),new Error(t.message||"Failed to unlike post")},isLiked:async(e,s)=>{const{data:t,error:r}=await i.from("post_likes").select("id").eq("post_id",e).eq("user_id",s).maybeSingle();return r&&r.code!=="PGRST116"&&console.error("Error checking like:",r.message),!!t},getLikedPosts:async(e,s)=>{if(!e.length)return new Set;try{const{data:t,error:r}=await i.from("post_likes").select("post_id").eq("user_id",s).in("post_id",e);return r?(console.warn("[Supabase] Error fetching liked posts:",{message:r.message,code:r.code,details:r.details}),new Set):new Set(t?.map(l=>l.post_id)||[])}catch(t){return console.warn("[Supabase] Network error fetching liked posts:",t),new Set}},repost:async(e,s)=>{let t=e,r=0;const l=10;for(;r<l;){const{data:a}=await i.from("posts").select("repost_of_post_id, content").eq("id",t).single();if(a?.repost_of_post_id&&!a.content?.trim())t=a.repost_of_post_id,r++;else break}const{data:c}=await i.from("posts").select("id").eq("user_id",s).eq("repost_of_post_id",t).eq("content","").single();if(c)throw new Error("You have already reposted this");const{data:u,error:p}=await i.from("posts").insert({user_id:s,content:"",media_urls:[],visibility:"public",repost_of_post_id:t}).select().single();if(p)throw console.error("Error creating repost:",p.message),new Error(p.message||"Failed to repost");const{data:_}=await i.from("posts").select("reposts_count").eq("id",t).single();return _&&await i.from("posts").update({reposts_count:(_.reposts_count||0)+1}).eq("id",t),u},quoteRepost:async(e,s,t,r=[])=>{const{authFetch:l}=await F(async()=>{const{authFetch:_}=await import("./index-CiCw9Duq.js").then(a=>a.ag);return{authFetch:_}},__vite__mapDeps([1,2,3,4,5,6,7])),c=JSON.stringify({userId:e,content:t,mediaUrls:r,visibility:"public",repostOfPostId:s}),u=["/api/posts/create","/.netlify/functions/create-post"];let p="Failed to quote-repost";for(const _ of u)try{const a=await l(_,{method:"POST",body:c});if(a.ok)return(await a.json()).post;const m=await a.json().catch(()=>({}));if(a.status===404||a.status===502)continue;throw new Error(m.error||m.message||`Quote blocked (${a.status})`)}catch(a){if(a?.message&&!/fetch|network|unreachable/i.test(a.message))throw a;p=a?.message||p}throw new Error(p)},unrepost:async(e,s)=>{const{data:t}=await i.from("posts").select("id").eq("user_id",s).eq("repost_of_post_id",e).maybeSingle();if(!t)return;const{error:r}=await i.from("posts").delete().eq("id",t.id);if(r)throw console.error("Error removing repost:",r.message),new Error(r.message||"Failed to remove repost");const{data:l}=await i.from("posts").select("reposts_count").eq("id",e).maybeSingle();l&&await i.from("posts").update({reposts_count:Math.max(0,(l.reposts_count||0)-1)}).eq("id",e)},isReposted:async(e,s)=>{const{data:t,error:r}=await i.from("posts").select("id").eq("content","").eq("user_id",s).eq("repost_of_post_id",e).maybeSingle();return r&&r.code!=="PGRST116"&&console.error("Error checking repost:",r.message),!!t},getRepostedPosts:async(e,s)=>{if(!e.length)return new Set;try{const{data:t,error:r}=await i.from("posts").select("repost_of_post_id").eq("user_id",s).eq("content","").in("repost_of_post_id",e);
2return r?(console.warn("[Supabase] Error fetching reposted posts:",{message:r.message,code:r.code,details:r.details}),new Set):new Set(t?.map(l=>l.repost_of_post_id).filter(Boolean)||[])}catch(t){return console.warn("[Supabase] Network error fetching reposted posts:",t),new Set}},pinPost:async(e,s)=>{const{authFetch:t}=await F(async()=>{const{authFetch:c}=await import("./index-CiCw9Duq.js").then(u=>u.ag);return{authFetch:c}},__vite__mapDeps([1,2,3,4,5,6,7])),r=await t("/api/posts/pin",{method:"POST",body:JSON.stringify({postId:e,userId:s})}),l=await r.json();if(!r.ok)throw console.error("Error pinning post:",l.error),new Error(l.error||"Failed to pin post")},unpinPost:async e=>{const{authFetch:s}=await F(async()=>{const{authFetch:l}=await import("./index-CiCw9Duq.js").then(c=>c.ag);return{authFetch:l}},__vite__mapDeps([1,2,3,4,5,6,7])),t=await s("/api/posts/unpin",{method:"POST",body:JSON.stringify({userId:e})}),r=await t.json();if(!t.ok)throw console.error("Error unpinning post:",r.error),new Error(r.error||"Failed to unpin post")},createReply:async(e,s,t,r=[])=>{const{authFetch:l}=await F(async()=>{const{authFetch:_}=await import("./index-CiCw9Duq.js").then(a=>a.ag);return{authFetch:_}},__vite__mapDeps([1,2,3,4,5,6,7])),c=JSON.stringify({userId:e,content:t,mediaUrls:r,visibility:"public",replyToPostId:s}),u=["/api/posts/create","/.netlify/functions/create-post"];let p="Failed to create reply";for(const _ of u)try{const a=await l(_,{method:"POST",body:c});if(a.ok)return(await a.json()).post;const m=await a.json().catch(()=>({}));if(a.status===404||a.status===502)continue;throw new Error(m.error||m.message||`Reply blocked (${a.status})`)}catch(a){if(a?.message&&!/fetch|network|unreachable/i.test(a.message))throw a;p=a?.message||p}throw new Error(p)},getReplies:async(e,s=50)=>{const{data:t,error:r}=await i.from("posts").select(q).eq("reply_to_post_id",e).or("r2_ready.eq.true,r2_ready.is.null,has_video.eq.false,has_video.is.null").order("created_at",{ascending:!0}).limit(s);if(r)return console.error("Error fetching replies:",r.message),[];if(!t||t.length===0)return[];const l=[...new Set(t.map(a=>a.user_id))],{data:c}=await i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").in("id",l),u=new Map(c?.map(a=>[a.id,a])||[]),{data:p}=await i.from("creator_profiles").select("user_id, avatar").in("user_id",l),_=new Map(p?.map(a=>[a.user_id,a])||[]);return t.map(a=>({...a,user:u.get(a.user_id),creator_profile:_.get(a.user_id)}))},getById:async e=>{let s=null;if(e.length===36&&e.includes("-")){const{data:a,error:m}=await i.from("posts").select(q).eq("id",e).single();if(m)return console.error("Error fetching post:",m.message),null;s=a}else{const a=e.toLowerCase().padEnd(8,"0"),m=`${a}-0000-0000-0000-000000000000`,n=a.split("");let d=!0;for(let T=n.length-1;T>=0&&d;T--){const S=parseInt(n[T],16)+1;S>15?n[T]="0":(n[T]=S.toString(16),d=!1)}const b=`${d?"ffffffff":n.join("")}-ffff-ffff-ffff-ffffffffffff`,{data:M,error:R}=await i.from("posts").select(q).gte("id",m).lt("id",b).limit(1);if(R)return console.error("Error fetching post by short ID:",R.message),null;s=M?.[0]||null}if(!s)return null;const t=[s.user_id];let r=null;if(s.repost_of_post_id){const{data:a}=await i.from("posts").select(q).eq("id",s.repost_of_post_id).single();a&&(r=a,t.includes(a.user_id)||t.push(a.user_id))}const[l,c]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").in("id",t),i.from("creator_profiles").select("user_id, avatar").in("user_id",t)]),u=new Map(l.data?.map(a=>[a.id,a])||[]),p=new Map(c.data?.map(a=>[a.user_id,a])||[]),_={...s,user:u.get(s.user_id),creator_profile:p.get(s.user_id)};return r&&(_.repost_of={...r,user:u.get(r.user_id),creator_profile:p.get(r.user_id)}),_},createPaidPost:async(e,s,t,r=[],l,c,u)=>{const{authFetch:p}=await F(async()=>{const{authFetch:d}=await import("./index-CiCw9Duq.js").then(f=>f.ag);return{authFetch:d}},__vite__mapDeps([1,2,3,4,5,6,7])),_=l||s.substring(0,100)+"...",a=JSON.stringify({userId:e,content:_,previewText:_,mediaUrls:u?[u]:[],paidMediaUrls:r,visibility:"paid_content",isPaid:!0,price:t,needsEncoding:c===!0?!0:void 0,thumbnailUrl:u||void 0}),m=["/api/posts/create","/.netlify/functions/create-post"];let n="Failed to create paid post";for(const d of m)try{const f=await p(d,{method:"POST",body:a});if(f.ok)return(await f.json()).post;const b=await f.json().catch(()=>({}));if(f.status===404||f.status===502)continue;throw new Error(b.error||b.message||`Paid post blocked (${f.status})`)}catch(f){if(f?.message&&!/fetch|network|unreachable/i.test(f.message))throw f;n=f?.message||n}throw new Error(n)},getShowcaseImages:async(e,s=8)=>{const{data:t,error:r}=await i.from("posts").select("media_urls").eq("user_id",e).eq("is_paid",!1).order("created_at",{ascending:!1}).limit(24);if(r||!t)return[];const l=u=>/\.(mp4|mov|webm)$/i.test(u)||u.includes("video"),c=[];for(const u of t)for(const p of u.media_urls||[])if(!(!p||l(p))&&(c.includes(p)||c.push(p),c.length>=s))return c;return c},getPaidPostsByUser:async(e,s)=>{const{data:t,error:r}=await i.from("posts").select(q).eq("user_id",e).eq("is_paid",!0).order("created_at",{ascending:!1});if(r)return console.error("Error fetching paid posts:",r.message),[];if(!t||t.length===0)return[];const[l,c,u]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").eq("id",e).single(),i.from("creator_profiles").select("avatar").eq("user_id",e).single(),s?i.from("paid_content_purchases").select("post_id").eq("buyer_id",s).eq("status","completed"):Promise.resolve({data:null})]),p=l.data,_=c.data,a=new Set((u.data||[]).map(m=>m.post_id));return t.map(m=>({...m,user:p,creator_profile:_,has_purchased:s===e||a.has(m.id)}
2))},hasPurchased:async(e,s)=>{const{data:t,error:r}=await i.from("paid_content_purchases").select("id").eq("post_id",e).eq("buyer_id",s).eq("status","completed").single();return r&&r.code!=="PGRST116"&&console.error("Error checking purchase:",r.message),!!t},getPurchasedPostIds:async e=>{const{data:s,error:t}=await i.from("paid_content_purchases").select("post_id").eq("buyer_id",e).eq("status","completed");return t?(console.error("Error fetching purchases:",t.message),new Set):new Set(s?.map(r=>r.post_id)||[])},recordPurchase:async(e,s,t)=>{const{authFetch:r}=await F(async()=>{const{authFetch:c}=await import("./index-CiCw9Duq.js").then(u=>u.ag);return{authFetch:c}},__vite__mapDeps([1,2,3,4,5,6,7])),l=await r("/api/posts/record-purchase",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({postId:e})});if(!l.ok){let c="Failed to record purchase";try{const u=await l.json();u?.error&&(c=u.error)}catch{}throw new Error(c)}},uploadPaidMedia:async(e,s)=>{const t=async _=>{const{moderateUploadedMedia:a}=await F(async()=>{const{moderateUploadedMedia:n}=await import("./moderate-upload-BvipGHo3.js");return{moderateUploadedMedia:n}},__vite__mapDeps([0,1,2,3,4,5,6,7])),m=await a(_,"image");if(!m.ok)throw new Error(m.reason||"This image violates our content policy and cannot be posted.")};try{if(await Q()){const a=await _e(s,"post-images");return await t(a),a}}catch(_){if(_?.message?.includes("policy"))throw _;console.warn("[uploadPaidMedia] R2 failed, falling back to Supabase:",_)}const r=s.name.split(".").pop(),l=`${e}-${Date.now()}-paid.${r}`,c=`paid/${e}/${l}`,{error:u}=await i.storage.from("post-images").upload(c,s,{cacheControl:"3600",upsert:!1});if(u)throw console.error("Error uploading paid media:",u.message),new Error(u.message||"Failed to upload media");const{data:{publicUrl:p}}=i.storage.from("post-images").getPublicUrl(c);return await t(p),p},uploadPaidVideo:async(e,s,t)=>{const r=async a=>{const{moderateUploadedMedia:m}=await F(async()=>{const{moderateUploadedMedia:d}=await import("./moderate-upload-BvipGHo3.js");return{moderateUploadedMedia:d}},__vite__mapDeps([0,1,2,3,4,5,6,7])),n=await m(a,"video");if(!n.ok)throw new Error(n.reason||"This video violates our content policy and cannot be posted.")};try{if(await Q()){const{authFetch:m}=await F(async()=>{const{authFetch:d}=await import("./index-CiCw9Duq.js").then(f=>f.ag);return{authFetch:d}},__vite__mapDeps([1,2,3,4,5,6,7])),n=await m("/api/r2/upload",{method:"POST",headers:{"Content-Type":s.type||"video/mp4","X-Upload-Category":"paid-raw"},body:s,signal:AbortSignal.timeout(3e5)});if(n.ok){const d=await n.json();return await r(d.url),d.url}}}catch(a){if(a?.message?.includes("policy"))throw a;console.warn("[uploadPaidVideo] R2 failed, falling back to Supabase:",a)}const l=s.name.split(".").pop()||"mp4",c=`${e}-${Date.now()}-raw.${l}`,u=`paid-raw/${e}/${c}`,{error:p}=await i.storage.from("post-videos").upload(u,s,{cacheControl:"3600",upsert:!1});if(p)throw console.error("Error uploading paid video:",p.message),new Error(p.message||"Failed to upload video");const{data:{publicUrl:_}}=i.storage.from("post-videos").getPublicUrl(u);return await r(_),_},getCreatorEarnings:async e=>{const s=new Date;s.setDate(1),s.setHours(0,0,0,0);const[t,r,l]=await Promise.all([i.from("creator_profiles").select("earnings").eq("user_id",e).single(),i.from("paid_content_purchases").select("amount").eq("seller_id",e).eq("status","completed").gte("created_at",s.toISOString()),i.from("paid_content_purchases").select("id",{count:"exact",head:!0}).eq("seller_id",e).eq("status","completed")]),c=t.data,u=r.data,p=l.count,_=u?.reduce((a,m)=>a+m.amount*.95,0)||0;return{total:c?.earnings||0,thisMonth:_,salesCount:p||0}},getUserPurchases:async e=>{const{data:s,error:t}=await i.from("paid_content_purchases").select("post_id, amount, created_at").eq("buyer_id",e).eq("status","completed").order("created_at",{ascending:!1});if(t||!s?.length)return[];const r=s.map(c=>c.post_id),{data:l}=await i.from("posts").select("*, user:users(id, username, verified, avatar_url, is_lifetime_member, account_type)").in("id",r);return l?l.map(c=>({...c,has_purchased:!0})):[]},getPaidFeedPosts:async e=>{const{data:s,error:t}=await i.from("posts").select(q).eq("is_paid",!0).is("reply_to_post_id",null).is("repost_of_post_id",null).order("created_at",{ascending:!1}).limit(200);if(t)return console.error("Error fetching paid posts:",t.message),[];if(!s||s.length===0)return[];const r=s.filter(n=>!n.is_hidden);if(r.length===0)return[];const l=[...new Set(r.map(n=>
2n.user_id))],[c,u,p]=await Promise.all([i.from("profiles").select("id, username, display_name, is_lifetime_member, verified, is_diamond_member, avatar_url, account_type").in("id",l),i.from("creator_profiles").select("user_id, avatar").in("user_id",l),e?i.from("paid_content_purchases").select("post_id").eq("buyer_id",e).eq("status","completed"):Promise.resolve({data:null})]),_=new Map(c.data?.map(n=>[n.id,n])||[]),a=new Map(u.data?.map(n=>[n.user_id,n])||[]),m=new Set(p.data?.map(n=>n.post_id)||[]);return r.map(n=>({...n,user:_.get(n.user_id)||null,creator_profile:a.get(n.user_id)||null,has_purchased:e===n.user_id||m.has(n.id)}))}};function tt(e){return e.substring(0,8)}export{q as POST_FIELDS,tt as generateOptimalShortId,z as supabasePosts};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.