PIMS/public/build/assets/Index-BdIxoUYY.js

2 lines
6.4 KiB
JavaScript
Raw Normal View History

import{d as $,r as o,c as H,e as U,p as z,a as r,f as C,u as B,h as F,w as A,b as s,i as v,q as K,z as J,v as G,o as n,t as m,F as h,g as Q,l as j,T as Y}from"./app-BXYcVHqk.js";import{_ as Z}from"./AppLayout.vue_vue_type_script_setup_true_lang-86gE95Fg.js";import{_ as ee}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./AppLogoIcon.vue_vue_type_script_setup_true_lang-BzXwPo6R.js";import"./useForwardExpose-Djbxsgaa.js";import"./VisuallyHidden-BvthYHr5.js";import"./RovingFocusGroup-dmigQ6Dy.js";import"./useArrowNavigation-C6Y-ieo6.js";import"./index-C4J_hXM0.js";import"./createLucideIcon-BlA39rtn.js";const te={class:"flex h-full flex-1 flex-col gap-4 overflow-x-auto rounded-xl p-4"},ae={class:"flex items-center gap-2"},se={key:0,class:"rounded-md border border-red-300 bg-red-50 p-3 text-red-800 dark:border-red-800 dark:bg-red-950 dark:text-red-200"},oe={class:"divide-y divide-muted-foreground/20"},re={class:"h-20 w-14 shrink-0 overflow-hidden rounded bg-muted"},ne=["src"],ie={class:"flex min-w-0 flex-1 flex-col"},le={class:"flex items-center justify-between gap-2"},ce={class:"truncate font-medium"},de={class:"text-xs text-muted-foreground"},ue={class:"mt-2"},fe={key:0,class:"inline-flex items-center rounded-md border px-3 py-1.5 text-xs"},pe=["disabled","aria-busy","onClick"],ve={key:0},me={key:1},he={key:0,class:"fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded bg-foreground px-3 py-2 text-sm text-background shadow-lg"},_e={key:0,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/50"},xe={class:"w-full max-w-md rounded-lg bg-background p-5 shadow-lg"},ge={class:"text-base font-semibold"},ye=$({__name:"Index",setup(be){const _=o(""),x=o(1),i=o([]),D=o(0),w=o(!1),d=o(!1),g=o(null),c=o(!1),y=o(""),u=o(new Set),p=o(!1),q=o(""),k=o("");let S=null;const E=H(()=>w.value&&!d.value);async function T(e=!1){if(!d.value){d.value=!0,g.value=null;try{const a=new URLSearchParams;a.set("q",_.value),a.set("page",String(x.value));const t=await fetch(`/admin/movies/search?${a.toString()}`,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"},credentials:"same-origin"});if(!t.ok)throw new Error(`Search failed: ${t.status}`);const l=await t.json();D.value=l.total,w.value=l.has_more,e?i.value=l.results:i.value=i.value.concat(l.results)}catch(a){g.value=a?.message??"Unexpected error"}finally{d.value=!1}}}function L(){clearTimeout(S);const e=_.value.trim().length;e>=3&&e%3===0&&(S=setTimeout(()=>{x.value=1,T(!0)},300))}function N(){clearTimeout(S),x.value=1,T(!0)}async function X(){E.value&&(x.value+=1,await T(!1))}const b=o(null);let f=null;U(()=>{f=new IntersectionObserver(e=>{for(const a of e)a.isIntersecting&&X()},{root:null,rootMargin:"200px",threshold:0}),b.value&&f.observe(b.value)}),z(b,(e,a)=>{a&&f&&f.unobserve(a),e&&f&&f.observe(e)});async function I(e){try{if(u.value.has(e.provider_id))return;const a=new URLSearchParams({provider_id:e.provider_id}),t=await fetch(`/admin/movies/exists?${a.toString()}`,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"},credentials:"same-origin"});if(!t.ok)throw new Error("Duplicate check failed");if((await t.json()).exists){q.value=e.title??"This movie",k.value=e.provider_id,p.value=!0;return}await M(e.provider_id,"overwrite")}catch(a){console.error(a),y.value=a instanceof Error?a.message:"Something went wrong",c.value=!0,setTimeout(()=>c.value=!1,2500)}}async function M(e,a){try{u.value.add(e);const t=await fetch("/admin/movies/accept",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest","X-CSRF-TOKEN":document.querySelector('meta[name="csrf-token"]')?.content??""},body:JSON.stringify({provider_id:e,mode:a}),credentials:"same-origin"});if(!t.ok)throw new Error("Accept failed");try{const l=await t.json(),R=i.value.findIndex(W=>W.provider_id===e);R!==-1&&(i.value[R]._accepted=!0),y.value=a==="duplicate"?"Saved as duplicate":"Accepted (overwrote if existed)",c.value=!0,setTimeout(()=>c.value=!1,2e3)}catch{}}catch(t){throw console.error(t),y.value=t instanceof Error?t.mes