PageSourceSearch

https://mostreams-com.lovable.app/assets/release-links-7xAPxzWb.js

js mostreams-com.lovable.app collected 2026-10-03 03:36:01 UTC 6,396 bytes, 3 lines download raw bytes

1import{bz as G,r as i,j as e,bA as M,B as h,a$ as F,bc as H,b1 as J,s as v,v as u}from"./index-BNrdOJig.js";import{I as f}from"./input-CwAqzCK4.js";import{P as K}from"./plus-BewcIKll.js";import{T as Q}from"./trash-2-DqSHrMYS.js";const V=["spotify","apple","youtube","amazon","tidal","deezer"];function W(c){return c.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,48)}function se(){const c=G(),[p,O]=i.useState([]),[m,k]=i.useState({}),[P,b]=i.useState(!0),[D,j]=i.useState(!1),[x,w]=i.useState(""),[y,N]=i.useState({}),[S,C]=i.useState(""),[_,L]=i.useState(!1),g=async()=>{b(!0);const{data:s}=await v.from("smart_links").select("*").order("created_at",{ascending:!1}),t=s??[];if(O(t),t.length){const r=new Date(Date.now()-2592e6).toISOString(),{data:n}=await v.from("smart_link_clicks").select("link_id, dsp, kind").gte("created_at",r).in("link_id",t.map(a=>a.id)),l={};for(const a of n??[]){const o=l[a.link_id]??={clicks:0,presaves:0,dsps:{}};a.kind==="presave"?o.presaves+=1:o.clicks+=1,a.dsp&&a.dsp!=="page"&&(o.dsps[a.dsp]=(o.dsps[a.dsp]??0)+1)}const d={};for(const[a,o]of Object.entries(l)){const B=Object.entries(o.dsps).sort((A,q)=>q[1]-A[1])[0]?.[0]??"—";d[a]={clicks:o.clicks,presaves:o.presaves,top:B}}k(d)}else k({});b(!1)};i.useEffect(()=>{c?.id&&g()},[c?.id]);const R=async()=>{if(!x.trim()||!c?.id){u.error("Give the release a title");return}L(!0);const t=`${W(x)||"release"}-${Math.random().toString(36).slice(2,6)}`,r=Object.fromEntries(Object.entries(y).filter(([,l])=>l?.trim())),{error:n}=await v.from("smart_links").insert({owner_id:c.id,slug:t,title:x.trim(),artist_name:c.display_name??null,dsp_links:r,presave_url:S.trim()||null});if(L(!1),n){u.error(n.message);return}u.success("Smart link created",{description:`/l/${t}`}),w(""),N({}),C(""),j(!1),g()},$=s=>{navigator.clipboard.writeText(`${window.location.origin}/l/${s}`),u.success("Link copied")},E=async s=>{await v.from("smart_links").delete().eq("id",s.id),u.success("Smart link deleted"),g()},U=()=>{const s=`Release,Slug,Clicks 30d,Pre-saves,Top DSP,Created
2`,t=p.map(l=>{const d=m[l.id]??{clicks:0,presaves:0,top:"—"};return[l.title,l.slug,d.clicks,d.presaves,d.top,new Date(l.created_at).toISOString().slice(0,10)].map(a=>`"${String(a).replace(/"/g,'""')}"`).join(",")}).join(`
3`),r=URL.createObjectURL(new Blob([s+t],{type:"text/csv"})),n=document.createElement("a");n.href=r,n.download="smart-links.csv",n.click(),URL.revokeObjectURL(r)},T=Object.values(m).reduce((s,t)=>s+t.clicks,0),z=Object.values(m).reduce((s,t)=>s+t.presaves,0),I=(()=>{const s={};for(const t of Object.values(m))t.top!=="—"&&(s[t.top]=(s[t.top]??0)+t.clicks);return Object.entries(s).sort((t,r)=>r[1]-t[1])[0]?.[0]??"—"})();return e.jsx(M,{profile:c,title:"Release Links",subtitle:"Smart links for every release",children:e.jsxs("div",{className:"space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground max-w-3xl",children:"One short link that opens your release on every store, with built-in pre-save. Clicks and pre-saves are tracked per DSP."}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[{label:"Active links",value:p.length},{label:"Clicks (30d)",value:T},{label:"Pre-saves",value:z},{label:"Top DSP",value:I}].map(s=>e.jsxs("div",{className:"rounded-2xl border border-white/5 p-5",style:{background:"var(--backoffice-card)"},children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground",children:s.label}),e.jsx("div",{className:"font-display text-3xl mt-2 capitalize",children:s.value})]},s.label))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(h,{onClick:()=>j(s=>!s),className:"bg-primary text-primary-foreground hover:opacity-90",children:[e.jsx(K,{className:"w-4 h-4 mr-1.5"})," Create smart link"]}),e.jsxs(h,{variant:"outline",onClick:U,disabled:p.length===0,children:[e.jsx(F,{className:"w-4 h-4 mr-1.5"})," Export clicks"]})]}),D&&e.jsxs("div",{className:"rounded-2xl border border-white/5 p-5 space-y-3",style:{background:"var(--backoffice-card)"},children:[e.jsx(f,{placeholder:"Release title",value:x,onChange:s=>w(s.target.value)}),e.jsxs("div",{className:"grid md:grid-cols-3 gap-3",children:[V.map(s=>e.jsx(f,{placeholder:`${s} URL`,value:y[s]??"",onChange:t=>N(r=>({...r,[s]:t.target.value}))},s)),e.jsx(f,{placeholder:"Pre-save URL",value:S,onChange:s=>C(s.target.value)})]}),e.jsx(h,{onClick:R,disabled:_,children:_?"Creating…":"Create link"})]}),e.jsxs("div",{className:"rounded-2xl border border-white/5 overflow-hidden",style:{background:"var(--backoffice-card)"},children:[e.jsxs("div",{className:"grid grid-cols-5 px-5 py-3 border-b border-white/5 text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("div",{children:"Release"}),e.jsx("div",{children:"Slug"}),e.jsx("div",{children:"Clicks"}),e.jsx("div",{children:"Pre-saves"}),e.jsx("div",{className:"text-right",children:"Created"})]}),P?e.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"Loading…"}):p.length===0?e.jsxs("div",{className:"p-10 text-center",children:[e.jsx("div",{className:"font-display text-lg mb-1",children:"No smart links yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Create your first smart link to share one URL that works on every DSP."})]}):p.map(s=>{const t=m[s.id]??{clicks:0,presaves:0}
3;return e.jsxs("div",{className:"grid grid-cols-5 px-5 py-4 border-b border-white/5 text-sm items-center",children:[e.jsx("div",{className:"font-semibold truncate",children:s.title}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground truncate",children:[e.jsxs("span",{className:"truncate",children:["/l/",s.slug]}),e.jsx("button",{onClick:()=>$(s.slug),"aria-label":"Copy link",children:e.jsx(H,{className:"w-3.5 h-3.5"})}),e.jsx("a",{href:`/l/${s.slug}`,target:"_blank",rel:"noreferrer","aria-label":"Open link",children:e.jsx(J,{className:"w-3.5 h-3.5"})})]}),e.jsx("div",{children:t.clicks}),e.jsx("div",{children:t.presaves}),e.jsxs("div",{className:"text-right text-muted-foreground flex items-center justify-end gap-3",children:[new Date(s.created_at).toLocaleDateString(),e.jsx("button",{onClick:()=>E(s),"aria-label":`Delete ${s.title}`,className:"hover:text-destructive",children:e.jsx(Q,{className:"w-4 h-4"})})]})]},s.id)})]})]})})}export{se as component};

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.