Files
skills-here-run-place/dist/client/_astro/DeleteButton.CHpgpUL1.js
Alejandro Martinez aa477a553b Add author auth, forking, tags, and stats tracking
Introduce token-based author authentication (register/verify API),
   skill forking with EditGate protection, tag metadata on skills,
   and download/push stats. Enhanced push scripts with token auth
   and per-skill filtering. Updated UI with stats, tags, and
   author info on skill cards.
2026-02-12 14:37:40 +01:00

2 lines
5.0 KiB
JavaScript

import{c as m,a as o,d as v,t as h,l as C,g as x,w as D,v as T,b as k,T as E,h as S,i as d,m as B,o as c}from"./runtime-dom.esm-bundler.A7MyAQcw.js";import{_ as j}from"./_plugin-vue_export-helper.DlAUqK2U.js";const M=S({__name:"DeleteButton",props:{slug:{},authorEmail:{},authorName:{},authorHasToken:{type:Boolean}},setup(p,{expose:t}){t();const a=p,e=d(!1),u=d(!1),n=d(""),r=d(""),b=d();async function w(){if(a.authorEmail&&a.authorHasToken){const l=localStorage.getItem("skillshere-token")||"";if(l)try{if((await fetch("/api/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:a.authorEmail,token:l})})).ok){f(l);return}}catch{}u.value=!0,r.value="",n.value="",B(()=>b.value?.focus())}else f("")}async function _(){r.value="",e.value=!0;try{const l=await fetch("/api/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:a.authorEmail,token:n.value})});if(!l.ok){const s=await l.json();r.value=s.error||"Invalid token",e.value=!1;return}}catch{r.value="Could not verify token",e.value=!1;return}localStorage.setItem("skillshere-token",n.value),f(n.value)}async function f(l){if(!confirm(`Delete "${a.slug}"? This cannot be undone.`)){e.value=!1;return}e.value=!0,r.value="";try{const s={};l&&(s.Authorization=`Bearer ${l}`);const i=await fetch(`/api/skills/${a.slug}`,{method:"DELETE",headers:s});if(i.status===403){const y=await i.json();r.value=y.error||"Permission denied",u.value=!0,e.value=!1;return}if(!i.ok&&i.status!==204){const y=await i.json().catch(()=>({error:"Failed to delete"}));throw new Error(y.error||"Failed to delete")}window.location.href="/"}catch(s){r.value=s instanceof Error?s.message:"Failed to delete skill.",e.value=!1}}const g={props:a,deleting:e,showModal:u,token:n,error:r,tokenInput:b,handleClick:w,verifyAndDelete:_,doDelete:f};return Object.defineProperty(g,"__isScriptSetup",{enumerable:!1,value:!0}),g}}),N={class:"inline-flex"},P=["disabled"],I={class:"w-full max-w-md rounded-2xl border border-white/[0.08] bg-[var(--color-surface-200)] p-6 shadow-2xl"},O={class:"text-sm text-gray-500 mb-4"},V={class:"text-gray-300"},L={key:0,class:"mt-2 text-sm text-red-400"},z={class:"mt-4 flex items-center gap-3"},A=["disabled"],F={key:0,class:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24"};function H(p,t,a,e,u,n){return c(),m("div",N,[o("button",{onClick:e.handleClick,disabled:e.deleting,class:"inline-flex items-center gap-1.5 rounded-lg border border-red-500/20 bg-red-500/5 px-3.5 py-2 text-sm font-medium text-red-400 hover:bg-red-500/10 hover:border-red-500/30 disabled:opacity-50 active:scale-[0.97] transition-all"},[t[3]||(t[3]=o("svg",{class:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","stroke-width":"2"},[o("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0"})],-1)),v(" "+h(e.deleting?"Deleting...":"Delete"),1)],8,P),(c(),C(E,{to:"body"},[e.showModal?(c(),m("div",{key:0,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:t[2]||(t[2]=x(r=>e.showModal=!1,["self"]))},[o("div",I,[t[7]||(t[7]=o("h3",{class:"text-lg font-semibold text-red-400 mb-1"},"Delete Skill",-1)),o("p",O,[t[4]||(t[4]=v(" This skill is owned by ",-1)),o("strong",V,h(a.authorName||a.authorEmail),1),t[5]||(t[5]=v(". Enter your token to delete it. ",-1))]),o("form",{onSubmit:x(e.verifyAndDelete,["prevent"])},[D(o("input",{ref:"tokenInput","onUpdate:modelValue":t[0]||(t[0]=r=>e.token=r),type:"password",placeholder:"Paste your author token...",class:"w-full rounded-xl border border-white/[0.06] bg-[var(--color-surface-100)] px-4 py-2.5 text-sm text-white placeholder-gray-600 font-mono focus:border-red-500/50 focus:outline-none focus:ring-1 focus:ring-red-500/20 transition-all"},null,512),[[T,e.token]]),e.error?(c(),m("p",L,h(e.error),1)):k("",!0),o("div",z,[o("button",{type:"submit",disabled:e.deleting||!e.token,class:"inline-flex items-center gap-2 rounded-xl bg-red-500 px-5 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:opacity-50 active:scale-[0.97] transition-all"},[e.deleting?(c(),m("svg",F,[...t[6]||(t[6]=[o("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"},null,-1),o("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"},null,-1)])])):k("",!0),v(" "+h(e.deleting?"Deleting...":"Delete Permanently"),1)],8,A),o("button",{type:"button",onClick:t[1]||(t[1]=r=>e.showModal=!1),class:"ml-auto text-sm text-gray-600 hover:text-gray-300 transition-colors"}," Cancel ")])],32)])])):k("",!0)]))])}const U=j(M,[["render",H]]);export{U as default};