home-atom 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/.vite/manifest.json +33 -33
- package/dist/client/_next/static/chunks/{app-top-nav-Dh0jEt8u.js → app-top-nav-Co7RIixU.js} +1 -1
- package/dist/client/_next/static/chunks/{index-hn3AiVww.js → index-BUxxgh38.js} +3 -3
- package/dist/client/_next/static/chunks/{layout-segment-context-DRM8YCgm.js → layout-segment-context-D_cL7vkY.js} +1 -1
- package/dist/client/_next/static/chunks/manage-profiles-modal-CWi3qgd4.js +1 -0
- package/dist/client/_next/static/chunks/netflix-browser-BrXQctI5.js +2 -0
- package/dist/client/_next/static/chunks/playback-activity-66FeikYZ.js +1 -0
- package/dist/client/_next/static/chunks/playback-activity-track-switcher-BzvHiv7c.js +1 -0
- package/dist/client/_next/static/chunks/{step-forward-CV8I5pPb.js → provider-registry-CWHfJn3B.js} +1 -1
- package/dist/client/_next/static/chunks/spotify-app-CJimeMR0.js +1 -0
- package/dist/client/_next/static/chunks/storefront-CCeanBPs.js +1 -0
- package/dist/client/_next/static/css/index.8o3Y-jts.css +1 -0
- package/dist/client/_next/static/css/layout.D2NsWbhP.css +1 -0
- package/dist/client/_next/static/css/layout.D4D5fsiD.css +1 -0
- package/dist/client/_next/static/css/manage-profiles-modal.BOKESpxI.css +1 -0
- package/dist/client/vinext-client-entry-manifest.json +1 -1
- package/dist/server/BUILD_ID +1 -1
- package/dist/server/__vite_rsc_assets_manifest.js +35 -35
- package/dist/server/_next/static/{app-page-cache-DcrtN14Y.js → app-page-cache-CQaSjBaF.js} +1 -1
- package/dist/server/_next/static/{app-page-cache-render-DoCquoNb.js → app-page-cache-render-Dty3aMiv.js} +1 -1
- package/dist/server/_next/static/{app-route-handler-dispatch-Be2YIqVp.js → app-route-handler-dispatch-DCSrhGNV.js} +1 -1
- package/dist/server/_next/static/{cache-headers-BQ-QuzWN.js → cache-headers-lY59goLh.js} +1 -1
- package/dist/server/_next/static/css/index.8o3Y-jts.css +1 -0
- package/dist/server/_next/static/css/layout.D2NsWbhP.css +1 -0
- package/dist/server/_next/static/css/layout.D4D5fsiD.css +1 -0
- package/dist/server/_next/static/database-D79CeUrn.js +161 -0
- package/dist/server/_next/static/{db-BE1J0NNS.js → db-x8J3Vuoa.js} +1 -1
- package/dist/server/_next/static/{downloader-DgnjNL5T.js → downloader-0G-gq1D-.js} +3 -3
- package/dist/server/_next/static/episode-sync-Ct5CeY25.js +1 -0
- package/dist/server/_next/static/{isr-decision-D1zHgPSI.js → isr-decision-BOA4L6nr.js} +1 -1
- package/dist/server/_next/static/netflix-page-Cpp2PgD1.js +1 -0
- package/dist/server/_next/static/{page-Cs-erYTy.js → page-BvzzZVuW.js} +1 -1
- package/dist/server/_next/static/{page-DlBGATQp.js → page-C27wjUYW.js} +1 -1
- package/dist/server/_next/static/{page-DlRXyzSQ.js → page-Rnpx_OjW.js} +1 -1
- package/dist/server/_next/static/{providers-B3YELr_F.js → providers-DwLUa_U_.js} +13 -13
- package/dist/server/_next/static/{providers-CMBIwNGs.js → providers-_uOQh6hB.js} +1 -1
- package/dist/server/_next/static/{request-profile-B1yGQ0l6.js → request-profile-ClcH0i0T.js} +1 -1
- package/dist/server/_next/static/route-4xkmbpc4.js +1 -0
- package/dist/server/_next/static/{route-CeVsDcbj2.js → route-B0L_rsrg2.js} +1 -1
- package/dist/server/_next/static/{route-xtz48fti.js → route-B6q-wR2F.js} +1 -1
- package/dist/server/_next/static/{route-DXTJyFWD.js → route-B6zrlXB5.js} +1 -1
- package/dist/server/_next/static/{route-CNNiXZoM2.js → route-B99Pvusz2.js} +1 -1
- package/dist/server/_next/static/route-B9YeBtG6.js +1 -0
- package/dist/server/_next/static/route-BHbJ9hFI2.js +1 -0
- package/dist/server/_next/static/{route-mzLdjDCs2.js → route-BR3Y_0V42.js} +1 -1
- package/dist/server/_next/static/{route-Cim7D4XQ.js → route-BaGo5TEW.js} +1 -1
- package/dist/server/_next/static/{route-DslPFTAK.js → route-BczKcyvV.js} +1 -1
- package/dist/server/_next/static/{route-B0WNLJZp.js → route-BiSvZr_s.js} +1 -1
- package/dist/server/_next/static/{route-Dbs39TkC.js → route-Bj7s6WXI.js} +1 -1
- package/dist/server/_next/static/{route-vD15s2A8.js → route-CGH08Y8C.js} +1 -1
- package/dist/server/_next/static/{route-CkH7Cg-p.js → route-CJmc17Dq.js} +1 -1
- package/dist/server/_next/static/{route-C74RA7va.js → route-CLvr0Ue3.js} +1 -1
- package/dist/server/_next/static/route-CUaIuP8a.js +1 -0
- package/dist/server/_next/static/{route-BPcAdbz_.js → route-CcrNbScT.js} +1 -1
- package/dist/server/_next/static/route-CiOFTfyw2.js +1 -0
- package/dist/server/_next/static/route-Cn7l9eYT.js +1 -0
- package/dist/server/_next/static/route-CnKXQb5r2.js +1 -0
- package/dist/server/_next/static/{route-CVPPmUto.js → route-D93PQ3NI2.js} +1 -1
- package/dist/server/_next/static/{route-D_G2SOlz.js → route-D9ZD1_5T.js} +1 -1
- package/dist/server/_next/static/{route-DAyF4BHS.js → route-DWPhX9kT2.js} +1 -1
- package/dist/server/_next/static/route-DihT2xS82.js +1 -0
- package/dist/server/_next/static/route-Dn-sYYEs.js +1 -0
- package/dist/server/_next/static/route-DpzLCx1V.js +1 -0
- package/dist/server/_next/static/route-Dswz7MvP2.js +1 -0
- package/dist/server/_next/static/route-Dwk0kt8B.js +1 -0
- package/dist/server/_next/static/route-DxLQx9eD.js +1 -0
- package/dist/server/_next/static/{route-zazqen-A2.js → route-FwNLcs2r2.js} +1 -1
- package/dist/server/_next/static/route-GmbSJZjk2.js +1 -0
- package/dist/server/_next/static/route-iUxcDN2r.js +1 -0
- package/dist/server/_next/static/{route-UWQN8uYr.js → route-j61HPczh.js} +1 -1
- package/dist/server/_next/static/{route-CHJzaQu2.js → route-qJ1EJhxJ.js} +1 -1
- package/dist/server/_next/static/{route-BWk9YK7r.js → route-sNW0pw7C.js} +1 -1
- package/dist/server/_next/static/{seed-cache-oCd9Lfdw.js → seed-cache-DsYPqBld.js} +1 -1
- package/dist/server/_next/static/{server-CS40XqUP.js → server-DwVU6UyP.js} +1 -1
- package/dist/server/_next/static/storage-fxaUbjG1.js +322 -0
- package/dist/server/_next/static/streamer-DUAWx_Tm.js +2 -0
- package/dist/server/_next/static/{subtitles-DYBlMnha.js → subtitles-4c0GFlaW.js} +1 -1
- package/dist/server/_next/static/{title-progress-CQBrSxvN.js → title-progress-BTypVYBz.js} +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/prerendered-routes/404.html +2 -2
- package/dist/server/prerendered-routes/index.html +2 -2
- package/dist/server/prerendered-routes/index.rsc +2 -2
- package/dist/server/ssr/__vite_rsc_assets_manifest.js +35 -35
- package/dist/server/ssr/_next/static/css/refresh-cw.BOKESpxI.css +1 -0
- package/dist/server/ssr/_next/static/minimize-gPI5ytrc.js +1 -0
- package/dist/server/ssr/_next/static/netflix-browser-CXJEizJ6.js +2 -0
- package/dist/server/ssr/_next/static/{pin-BQre-tQY.js → pin-DiZl7z2n.js} +1 -1
- package/dist/server/ssr/_next/static/playback-activity-AIsC-eO5.js +1 -0
- package/dist/server/ssr/_next/static/refresh-cw-DNvHlOAy.js +1 -0
- package/dist/server/ssr/_next/static/spotify-app-xyDH0rho.js +1 -0
- package/dist/server/ssr/_next/static/storefront-DMeL08z3.js +1 -0
- package/dist/server/ssr/index.js +1 -1
- package/dist/server/ssr/vinext-client-assets.js +1 -1
- package/dist/server/ssr/vinext-server.json +1 -1
- package/dist/server/vinext-client-assets.js +1 -1
- package/dist/server/vinext-prerender-paths.json +1 -1
- package/dist/server/vinext-prerender.json +16 -1
- package/dist/server/vinext-server.json +1 -1
- package/package.json +4 -2
- package/dist/client/_next/static/chunks/manage-profiles-modal-Doi6QM4e.js +0 -1
- package/dist/client/_next/static/chunks/netflix-browser-L_Vb9wXK.js +0 -2
- package/dist/client/_next/static/chunks/playback-activity-Dug3BRYr.js +0 -1
- package/dist/client/_next/static/chunks/playback-activity-track-switcher-CbO6kl8K.js +0 -1
- package/dist/client/_next/static/chunks/spotify-app-f93K4FG_.js +0 -1
- package/dist/client/_next/static/chunks/storefront-C_nmcuvH.js +0 -1
- package/dist/client/_next/static/css/index.BGXy8e6j.css +0 -1
- package/dist/client/_next/static/css/layout.AKSLtSR6.css +0 -1
- package/dist/client/_next/static/css/layout.D8T68cCD.css +0 -1
- package/dist/client/_next/static/css/manage-profiles-modal.BAVyxRRR.css +0 -1
- package/dist/server/_next/static/css/index.BGXy8e6j.css +0 -1
- package/dist/server/_next/static/css/layout.AKSLtSR6.css +0 -1
- package/dist/server/_next/static/css/layout.D8T68cCD.css +0 -1
- package/dist/server/_next/static/database-BNnYfHmT.js +0 -114
- package/dist/server/_next/static/netflix-page-BRbORN1F.js +0 -1
- package/dist/server/_next/static/route-96DdgJBs.js +0 -1
- package/dist/server/_next/static/route-BBmE0xf12.js +0 -1
- package/dist/server/_next/static/route-BdG5ojMj2.js +0 -1
- package/dist/server/_next/static/route-BovNctFc.js +0 -1
- package/dist/server/_next/static/route-C2LuSjoh.js +0 -1
- package/dist/server/_next/static/route-CCUsQ7AG.js +0 -1
- package/dist/server/_next/static/route-CN6VdJwN.js +0 -1
- package/dist/server/_next/static/route-CjUCKwSj2.js +0 -1
- package/dist/server/_next/static/route-Cn40NftM.js +0 -1
- package/dist/server/_next/static/route-DWAMZHLa.js +0 -1
- package/dist/server/_next/static/route-DiT9UYUd.js +0 -1
- package/dist/server/_next/static/route-jMq6H_yh.js +0 -1
- package/dist/server/_next/static/storage-D1zF0J_t.js +0 -288
- package/dist/server/_next/static/streamer-B1PRR-dj.js +0 -2
- package/dist/server/ssr/_next/static/css/refresh-cw.BAVyxRRR.css +0 -1
- package/dist/server/ssr/_next/static/minimize-C9JLgte-.js +0 -1
- package/dist/server/ssr/_next/static/netflix-browser-CMAehdwi.js +0 -2
- package/dist/server/ssr/_next/static/playback-activity-D5TYX2Ae.js +0 -1
- package/dist/server/ssr/_next/static/refresh-cw-CWdWHjqY.js +0 -1
- package/dist/server/ssr/_next/static/spotify-app-CE-RaTjZ.js +0 -1
- package/dist/server/ssr/_next/static/storefront-C5NNzPMa.js +0 -1
- /package/dist/client/_next/static/{e1ce9af7-d770-43d6-845a-511443f19971 → 7c810a6d-59fd-41d6-b465-cf61efaea04f}/_buildManifest.js +0 -0
- /package/dist/client/_next/static/{e1ce9af7-d770-43d6-845a-511443f19971 → 7c810a6d-59fd-41d6-b465-cf61efaea04f}/_ssgManifest.js +0 -0
- /package/dist/server/_next/static/{layout-Ds3pFa6r.js → layout-D1iejeee.js} +0 -0
- /package/dist/server/_next/static/{layout-ClEWbCcj.js → layout-DpOw0OgX.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./storage-
|
|
1
|
+
import{r as e}from"./storage-fxaUbjG1.js";import{S as t,a as n,n as r,p as i}from"./db-x8J3Vuoa.js";import{a,i as o,r as s,t as c}from"./http-B2HyuWoI.js";import{createHash as l,createHmac as u}from"node:crypto";var d=`https://zingmp3.vn/`,f=`https://www.nhaccuatui.com/`,p=`https://www.tiktok.com/`,m=`https://www.youtube.com/`,h=`1.19.3`,g=`X5BM3w8N7MKozC0B85o4KMlzLZKhV00y`,_=`acOrvUS15XRW2o9JksiK1KgQ6Vbds8ZW`,v=new Set([`ctime`,`id`,`type`,`page`,`count`,`version`]);function y(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function b(e){return e.replace(/<[^>]*>/g,` `).replace(/ /gi,` `).replace(/&/gi,`&`).replace(/"/gi,`"`).replace(/'|'/gi,`'`).replace(/</gi,`<`).replace(/>/gi,`>`).replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t))).replace(/\s+/g,` `).trim()}function x(e){return typeof e==`string`&&e.trim()?b(e):``}function S(...e){return l(`sha256`).update(e.join(`\0`)).digest(`hex`).slice(0,24)}function C(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=e.match(RegExp(`<script\\b[^>]*\\bid=["']${n}["'][^>]*>([\\s\\S]*?)<\\/script>`,`i`));if(!r)return null;try{return JSON.parse(r[1])}catch{return null}}function w(e,t){let n=e.indexOf(t);if(n<0)return null;let r=e.indexOf(`{`,n+t.length);if(r<0)return null;let i=0,a=!1,o=!1;for(let t=r;t<e.length;t+=1){let n=e[t];if(a){o?o=!1:n===`\\`?o=!0:n===`"`&&(a=!1);continue}if(n===`"`)a=!0;else if(n===`{`)i+=1;else if(n===`}`&&(--i,i===0))try{return JSON.parse(e.slice(r,t+1))}catch{return null}}return null}function T(e,t,n=0){if(!(n>18)){if(Array.isArray(e)){for(let r of e)T(r,t,n+1);return}if(y(e)){t(e);for(let r of Object.values(e))T(r,t,n+1)}}}function E(e){return y(e)?x(e.simpleText)||(Array.isArray(e.runs)?e.runs.filter(y).map(e=>x(e.text)).filter(Boolean).join(``):``):``}function D(e){if(!(!y(e)||!Array.isArray(e.thumbnails)))return x(e.thumbnails.filter(y).at(-1)?.url)||void 0}function O(e){let t=w(e,`ytInitialData`)??w(e,`window["ytInitialData"]`),n=[],r=new Set;return T(t,e=>{if(!(n.length>=250))for(let[t,i]of Object.entries(e)){if(!t.toLowerCase().endsWith(`videorenderer`)||!y(i))continue;let e=x(i.videoId),a=E(i.title);if(!/^[A-Za-z0-9_-]{11}$/.test(e)||!a||r.has(e))continue;r.add(e);let o=E(i.ownerText)||E(i.longBylineText)||E(i.shortBylineText),s=E(i.viewCountText);n.push({externalId:e,kind:`video`,title:a,subtitle:[o,s].filter(Boolean).join(` · `),imageUrl:D(i.thumbnail),sourceUrl:new URL(`/watch?v=${encodeURIComponent(e)}`,m).toString(),position:n.length,payload:{duration:E(i.lengthText),published:E(i.publishedTimeText)}})}}),n}function k(e){if(y(e))return x(e.coverLarge)||x(e.coverMedium)||x(e.coverThumb)||x(e.originCover)||x(e.dynamicCover)||x(e.cover)||void 0}function A(e){let t=C(e,`__UNIVERSAL_DATA_FOR_REHYDRATION__`)??C(e,`SIGI_STATE`),n=[],r=new Set;return T(t,e=>{if(n.length>=250)return;let t=x(e.id);if(!/^\d{8,24}$/.test(t)||r.has(t)||!y(e.video)&&!y(e.music))return;let i=y(e.author)?e.author:null,a=y(e.music)?e.music:null,o=y(e.video)?e.video:null,s=x(i?.uniqueId)||x(e.author),c=x(i?.nickname)||s||`TikTok creator`,l=x(a?.title)||x(e.desc)||`TikTok by ${c}`;r.add(t),n.push({externalId:t,kind:`video`,title:l,subtitle:x(a?.authorName)||c,imageUrl:k(a)||k(o),sourceUrl:s?new URL(`/@${encodeURIComponent(s)}/video/${t}`,p).toString():p,position:n.length,payload:{description:x(e.desc)}})}),n}function j(e){let t=e.getSetCookie?.()??[];if(t.length)return t;let n=e.get(`set-cookie`);return n?n.split(/,(?=[^;,]+=)/g):[]}function M(e){return j(e).map(e=>e.split(`;`,1)[0]).filter(e=>/^(?:zmp3_app_version\.1|zmp3_rqid)=/i.test(e)).join(`; `)}function N(e,t){let n=Object.keys(t).sort().filter(e=>v.has(e)&&t[e]!==``&&t[e]!==void 0).map(e=>`${encodeURIComponent(e)}=${encodeURIComponent(String(t[e]))}`).join(``),r=l(`sha256`).update(n).digest(`hex`);return u(`sha512`,_).update(e+r).digest(`hex`)}async function P(e,t={}){let n=await o(d,`zing-mp3`);if(!n.response.ok)throw new c(`Zing MP3 bootstrap returned HTTP ${n.response.status}.`);let r=M(n.response.headers);if(await n.response.body?.cancel(),!r)throw new c(`Zing MP3 did not issue a session cookie.`);let i={...t,ctime:Math.floor(Date.now()/1e3),version:h},a=new URL(e,d);for(let[t,n]of Object.entries({...i,sig:N(e,i),apiKey:g}))a.searchParams.set(t,String(n));let{response:s}=await o(a,`zing-mp3`,{headers:{cookie:r,referer:d}}),l=await s.json().catch(()=>null);if(!s.ok||!l||l.err!==0||l.data===void 0)throw new c(l?.msg||`Zing MP3 returned HTTP ${s.status}.`);return l.data}function F(e){if(e)try{let t=new URL(e,d);return t.hostname===`zingmp3.vn`||t.hostname.endsWith(`.zingmp3.vn`)?t.toString():void 0}catch{return}}function I(e){let t=[],n=new Set,r=0,i=(e,i=``)=>{let a=x(e.title)||x(e.name),o=x(e.encodeId)||x(e.id)||x(e.sectionId),s=x(e.link);if(!a||!o&&!s)return;let c=o||S(a,s,i);if(n.has(c))return;n.add(c);let l=x(e.artistsNames)||x(e.description)||x(e.sortDescription),u=x(e.thumbnailM)||x(e.thumbnail)||x(e.banner);t.push({externalId:c,kind:x(e.sectionType)||i||(e.duration?`song`:`homepage-item`),title:a,subtitle:l,imageUrl:u||void 0,sourceUrl:F(s),position:r,payload:{id:c,sectionType:x(e.sectionType)||i,duration:typeof e.duration==`number`?e.duration:void 0}}),r+=1},a=(e,n=``,r=0)=>{if(r>8||t.length>=350)return;if(Array.isArray(e)){for(let t of e)a(t,n,r+1);return}if(!y(e))return;let o=x(e.sectionType)||n;i(e,o);for(let[t,n]of Object.entries(e))(t===`artists`||t===`genres`||t===`chart`||t===`items`||t===`song`||t===`songs`||Array.isArray(n)&&r<5)&&a(n,o,r+1)};return a(e),t}function L(e){let t=[...e.matchAll(/<img\b[^>]*\bsrc=["']([^"']+)["'][^>]*>/gi)].at(-1)?.[1];if(t)return b(t.replace(/\\u0026/g,`&`).replace(/\\\//g,`/`))}function R(e){let t=[],n=new Set,r=0,i=(e,i,a=``,o)=>{let s=b(i),c=b(a);if(!s||s.length>220)return;let l=`${e}\u0000${s}\u0000${c}`;n.has(l)||(n.add(l),t.push({externalId:S(l),kind:e,title:s,subtitle:c,imageUrl:o,position:r}),r+=1)};for(let n of e.matchAll(/<div\b[^>]*class=["'][^"']*\bsong-name\b[^"']*["'][^>]*>([\s\S]*?)<\/div>/gi)){let r=n.index??0,a=[...e.slice(r+n[0].length,r+n[0].length+2600).matchAll(/<span\b[^>]*class=["'][^"']*\bname-text\b[^"']*["'][^>]*>([\s\S]*?)<\/span>/gi)].slice(0,4).map(e=>b(e[1])).filter(Boolean).join(`, `),o=e.slice(Math.max(0,r-1500),r);if(i(`song`,n[1],a,L(o)),t.length>=220)break}for(let n of e.matchAll(/<span\b[^>]*class=["'][^"']*\bcard-name\b[^"']*["'][^>]*>([\s\S]*?)<\/span>/gi)){let r=n.index??0,a=e.slice(Math.max(0,r-1800),r);if(i(`collection`,n[1],``,L(a)),t.length>=300)break}for(let t of e.matchAll(/<h2\b[^>]*class=["'][^"']*\btitle\b[^"']*["'][^>]*>([\s\S]*?)<\/h2>/gi))i(`section`,t[1]);return t.slice(0,350)}async function z(){let e=I(await P(`/api/v2/page/get/home`,{page:1,count:30}));if(!e.length)throw new c(`Zing MP3 returned no homepage content.`);return e}async function B(){let{text:e}=await a(f,`nhac-cua-tui`),t=R(e);if(!t.length)throw new c(`NhacCuaTui returned no homepage content.`);return t}async function V(){let{text:e}=await a(p,`tiktok`),t=A(e);if(!t.length)throw new c(`TikTok returned no public homepage content.`);return t}async function H(){let{text:e}=await a(new URL(`/feed/trending`,m),`youtube`),t=O(e);if(!t.length)throw new c(`YouTube returned no public trending content.`);return t}async function U(a,o){if(o??=e().id,!i(a,o))throw new c(`Unknown music provider.`,404);if(!t(a,o))throw new c(`This music provider is already synchronizing.`,409);try{let e;switch(a){case`zing-mp3`:e=await z();break;case`nhac-cua-tui`:e=await B();break;case`tiktok`:e=await V();break;case`youtube`:e=await H();break}r(a,e,o);let t=i(a,o);if(!t)throw Error(`The synchronized provider could not be loaded.`);return t}catch(e){throw n(a,s(e),o),e}}export{U as n,P as t};
|
package/dist/server/_next/static/{request-profile-B1yGQ0l6.js → request-profile-ClcH0i0T.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,r as t}from"./storage-
|
|
1
|
+
import{i as e,r as t}from"./storage-fxaUbjG1.js";function n(n,r){let i=new URL(n.url).searchParams.get(`profileId`),a=typeof r==`string`&&r.trim()?r.trim():i?.trim()||void 0,o=a?e(a):t();if(!o)throw Error(`Profile not found.`);return o.id}export{n as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{r as t,u as n,y as r}from"./database-D79CeUrn.js";var i=`nodejs`,a=`force-dynamic`;function o(e){let t=e,n=typeof t?.name==`string`?t.name.trim():``,r=typeof t?.avatarColor==`string`?t.avatarColor.trim():``;if(!n||n.length>30)throw Error(`Profile name must be between 1 and 30 characters.`);if(!/^#[0-9a-f]{6}$/i.test(r))throw Error(`Choose a valid avatar color.`);return{name:n,avatarColor:r}}function s(){return e.json({profiles:r(),activeProfile:n()})}async function c(i){try{let a=o(await i.json()),s=t(a.name,a.avatarColor);return e.json({profile:s,profiles:r(),activeProfile:n()},{status:201})}catch(t){let n=t instanceof Error?t.message:`Profile could not be created.`,r=/unique/i.test(n);return e.json({error:r?`A profile with that name already exists.`:n},{status:r?409:400})}}export{s as GET,c as POST,a as dynamic,i as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{E as n,v as r,x as i}from"./db-x8J3Vuoa.js";import{n as a,r as o,t as s}from"./http-B2HyuWoI.js";var c=`nodejs`,l=`force-dynamic`,u={"cache-control":`no-store`};function d(n){try{let i=t(n);return e.json({items:r(i,10)},{headers:u})}catch(t){return e.json({error:o(t)},{status:400,headers:u})}}async function f(r){try{a(r,{json:!0});let o=await r.json(),s=typeof o==`object`&&o&&!Array.isArray(o)?o:{},c=n(s.item);if(!c)return e.json({error:`Recently played item is invalid.`},{status:400,headers:u});let l=t(r,s.profileId);return e.json({item:i(c,l)},{status:201,headers:u})}catch(t){return e.json({error:o(t)},{status:t instanceof s?t.status:400,headers:u})}}export{d as GET,f as POST,l as dynamic,c as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{r as t}from"./input-platform-C0756QEt.js";import{n}from"./automation-UGP78ei5.js";import{n as r}from"./automation-tAN_1u1H.js";var i=`nodejs`,a=`force-dynamic`;function o(e){return typeof e==`number`&&Number.isFinite(e)?Math.min(1,Math.max(0,e)):null}function s(e){return typeof e==`number`&&Number.isFinite(e)?Math.min(240,Math.max(-240,e)):0}async function c(i){if(!t(i))return e.json({error:`Cross-site screen control is not allowed.`},{status:403});if(!i.headers.get(`content-type`)?.includes(`application/json`))return e.json({error:`Screen control requests must use JSON.`},{status:415});try{let t=await i.json(),a=t.action,c=typeof t.displayId==`string`?t.displayId:``,l=o(t.x),u=o(t.y);if(![`move`,`down`,`up`,`rightClick`,`scroll`].includes(a)||!c||l===null||u===null)return e.json({error:`Invalid local screen control request.`},{status:400});let d=await r(c);if(!d)return e.json({error:`The selected local display is unavailable.`},{status:404});let f=await n(`moveTo`,d.x+l*Math.max(0,d.width-1),d.y+u*Math.max(0,d.height-1));if(!f.ok||a===`move`)return e.json(f,{status:f.ok?200:503});let p=a===`down`?await n(`mouseDown`):a===`up`?await n(`mouseUp`):a===`rightClick`?await n(`rightClick`):await n(`scroll`,s(t.dx),s(t.dy));return e.json(p,{status:p.ok?200:503})}catch{return e.json({error:`Invalid request body.`},{status:400})}}export{c as POST,a as dynamic,i as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{f as t}from"./database-D79CeUrn.js";import{n,t as r}from"./title-progress-BTypVYBz.js";var i=`nodejs`,a=`force-dynamic`,o={"cache-control":`no-store`};function s(e){let t=new URL(e.url).searchParams.get(`profileId`)?.trim()??``;if(!t||t.length>128)throw Error(`A valid profile ID is required.`);return t}function c(e){if(!e||e!==e.trim()||e.length>256)throw Error(`A valid title ID is required.`);return e}function l(e){return e===`Profile not found.`||e===`Title not found.`?404:400}async function u(i,a){try{let l=s(i),u=t(l),d=n(c((await a.params).id),l);if(!d)throw Error(`Title not found.`);let f=u.progress.find(e=>e.titleId===d.id);return e.json({title:r(d,f)},{headers:o})}catch(t){let n=t instanceof Error?t.message:`Title could not be loaded.`;return e.json({error:n},{status:l(n),headers:o})}}export{u as GET,a as dynamic,i as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{E as t}from"./database-D79CeUrn.js";var n=`nodejs`,r=`force-dynamic`;async function i(n){try{let r=await n.json(),i=typeof r.profileId==`string`?r.profileId.trim():``;if(!i)throw Error(`Profile ID is required.`);let a={};if(typeof r.fontSize==`number`){let e=Math.round(r.fontSize);if(e<18||e>64)throw Error(`Font size must be between 18 and 64.`);a.fontSize=e}return typeof r.positionX==`number`&&typeof r.positionY==`number`&&(a.positionX=Math.max(7,Math.min(93,r.positionX)),a.positionY=Math.max(10,Math.min(86,r.positionY))),typeof r.fontColor==`string`&&(a.fontColor=r.fontColor.trim()),typeof r.backgroundColor==`string`&&(a.backgroundColor=r.backgroundColor.trim()),typeof r.fontFamily==`string`&&(a.fontFamily=r.fontFamily.trim()),typeof r.captionsOn==`boolean`&&(a.captionsOn=r.captionsOn),e.json(t(i,a))}catch(t){let n=t instanceof Error?t.message:`Subtitle preferences could not be saved.`;return e.json({error:n},{status:n===`Profile not found.`?404:400})}}export{i as PUT,r as dynamic,n as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{g as t,p as n}from"./database-D79CeUrn.js";import{t as r}from"./request-profile-ClcH0i0T.js";var i=`nodejs`,a=`force-dynamic`;function o(i){let a=r(i);return e.json({providers:n(a),titles:t(a)})}export{o as GET,a as dynamic,i as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{y as n}from"./db-x8J3Vuoa.js";var r=`nodejs`,i=`force-dynamic`;function a(r){let i=t(r);return e.json({tracks:n(i)},{headers:{"cache-control":`no-store`}})}export{a as GET,i as dynamic,r as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{r as t}from"./input-platform-C0756QEt.js";import{n,t as r}from"./automation-UGP78ei5.js";function i(){return e.json(r())}async function a(r){if(!t(r))return e.json({error:`Cross-site trackpad control is not allowed.`},{status:403});if(!r.headers.get(`content-type`)?.includes(`application/json`))return e.json({error:`Trackpad control requests must use JSON.`},{status:415});try{let t=await r.json();switch(t.action){case`warmup`:{let t=await n(`warmup`);return e.json(t,{status:t.ok?200:503})}case`move`:{let{dx:r,dy:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i))return e.json({error:`dx and dy must be finite numbers`},{status:400});let a=await n(`move`,r,i);return e.json(a,{status:a.ok?200:503})}case`click`:{let t=await n(`click`);return e.json(t,{status:t.ok?200:503})}case`rightClick`:{let t=await n(`rightClick`);return e.json(t,{status:t.ok?200:503})}case`doubleClick`:{let t=await n(`doubleClick`);return e.json(t,{status:t.ok?200:503})}case`scroll`:{let{dx:r,dy:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i))return e.json({error:`dx and dy must be finite numbers`},{status:400});let a=await n(`scroll`,r,i);return e.json(a,{status:a.ok?200:503})}default:return e.json({error:`Unknown action`},{status:400})}}catch{return e.json({error:`Invalid request body`},{status:400})}}export{i as GET,a as POST};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{I as t,T as n}from"./database-D79CeUrn.js";import{a as r}from"./providers-DwLUa_U_.js";import{t as i}from"./request-profile-ClcH0i0T.js";import{r as a}from"./downloader-0G-gq1D-.js";import{t as o}from"./subtitles-4c0GFlaW.js";var s=`nodejs`,c=60;async function l(s){try{let c=await s.json();if(!c.url?.trim())return e.json({error:`Enter a movie link.`},{status:400});let l=i(s,c.profileId),u=c.mode===`download`,d=await r(c.url.trim()),f=t(u?await o(d):d,u?`queued`:`metadata`,l);if(!f)throw Error(`The imported movie could not be saved.`);return u&&f.download_status!==`ready`&&a(f.id,l),e.json({title:n(f)},{status:202})}catch(t){let n=t instanceof Error?t.message:`Movie import failed.`;return e.json({error:n},{status:400})}}export{l as POST,c as maxDuration,s as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{O as t}from"./database-D79CeUrn.js";var n=`nodejs`,r=`force-dynamic`;async function i(n){try{let r=await n.json(),i=typeof r.profileId==`string`?r.profileId.trim():``,a=typeof r.titleId==`string`?r.titleId.trim():``,o=Number(r.seasonNumber),s=Number(r.episodeNumber),c=Number(r.positionSeconds),l=Number(r.durationSeconds);if(!i||!a)throw Error(`Profile and title are required.`);if(!Number.isInteger(o)||o<1||!Number.isInteger(s)||s<1)throw Error(`Season and episode must be positive whole numbers.`);if(!Number.isFinite(c)||c<0||!Number.isFinite(l)||l<0)throw Error(`Playback position and duration must be valid seconds.`);return e.json(t(i,{titleId:a,seasonNumber:o,episodeNumber:s,positionSeconds:c,durationSeconds:l,completed:r.completed===!0}))}catch(t){let n=t instanceof Error?t.message:`Playback progress could not be saved.`;return e.json({error:n},{status:n===`Profile not found.`?404:400})}}export{i as PUT,r as dynamic,n as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{F as t,i as n,u as r,y as i}from"./database-D79CeUrn.js";var a=`nodejs`,o=`force-dynamic`;function s(e){let t=e,n=typeof t?.name==`string`?t.name.trim():``,r=typeof t?.avatarColor==`string`?t.avatarColor.trim():``;if(!n||n.length>30)throw Error(`Profile name must be between 1 and 30 characters.`);if(!/^#[0-9a-f]{6}$/i.test(r))throw Error(`Choose a valid avatar color.`);return{name:n,avatarColor:r}}async function c(n,a){try{let{id:o}=await a.params,c=t(o,s(await n.json()));return e.json({profile:c,profiles:i(),activeProfile:r()})}catch(t){let n=t instanceof Error?t.message:`Profile could not be updated.`,r=n===`Profile not found.`,i=/unique/i.test(n);return e.json({error:i?`A profile with that name already exists.`:n},{status:r?404:i?409:400})}}async function l(t,a){try{let{id:t}=await a.params;return n(t),e.json({profiles:i(),activeProfile:r()})}catch(t){let n=t instanceof Error?t.message:`Profile could not be deleted.`;return e.json({error:n},{status:n===`Profile not found.`?404:409})}}export{l as DELETE,c as PATCH,o as dynamic,a as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{n}from"./subtitles-4c0GFlaW.js";var r=`nodejs`,i=`force-dynamic`,a=60;async function o(r,i){try{let{id:a,ownerId:o,track:s}=await i.params,c=s.match(/^(\d+)\.vtt$/);if(!c)return e.json({error:`Subtitle track not found.`},{status:404});let l=await n(a,o,Number(c[1]),t(r));return new Response(l,{headers:{"cache-control":`private, max-age=3600`,"content-type":`text/vtt; charset=utf-8`}})}catch(t){return e.json({error:t instanceof Error?t.message:`The subtitle could not be streamed.`},{status:502})}}export{o as GET,i as dynamic,a as maxDuration,r as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{r as t}from"./input-platform-C0756QEt.js";import{t as n}from"./automation-tAN_1u1H.js";var r=`nodejs`,i=`force-dynamic`;async function a(r){if(!t(r))return e.json({error:`Cross-site screen access is not allowed.`},{status:403});let i=new URL(r.url),a=i.searchParams.get(`display`)??``,o=i.searchParams.get(`density`)===`high`?`high`:`standard`,s=i.searchParams.get(`quality`)===`high`?`high`:`balanced`;if(!a)return e.json({error:`A local display must be selected.`},{status:400});try{let e=await n(a,{density:o,quality:s});return new Response(new Uint8Array(e.buffer),{status:200,headers:{"Content-Type":e.contentType,"Content-Length":String(e.buffer.byteLength),"Cache-Control":`private, no-store, max-age=0`,Pragma:`no-cache`,"X-Frame-Width":String(e.width),"X-Frame-Height":String(e.height),"X-Content-Type-Options":`nosniff`}})}catch(t){return e.json({error:t instanceof Error?t.message:`The local display could not be captured.`},{status:503,headers:{"Cache-Control":`private, no-store`}})}}export{a as GET,i as dynamic,r as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{C as t,R as n,l as r}from"./database-D79CeUrn.js";var i=`nodejs`,a=`force-dynamic`,o={"cache-control":`no-store`};function s(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function c(e){let t=e.trim();if(!t||t.length>128)throw Error(`Session ID is required.`);return t}function l(e){if(e===null)return 0;if(!/^\d+$/.test(e))throw Error(`The command cursor must be a non-negative numeric ID.`);let t=Number(e);if(!Number.isSafeInteger(t))throw Error(`The command cursor is too large.`);return t}function u(e){let t=new URL(e.url).searchParams.get(`profileId`);if(t===null)return;let n=t.trim();if(!n||n.length>128)throw Error(`Profile ID is required.`);return n}function d(e,t){let r={kind:`command`,sessionId:t,command:s(e)&&`command`in e?e.command:e};if(!n(r)||r.kind!==`command`)throw Error(`Playback command is invalid.`);let i=r.command;if(i.type===`seek-relative`&&Math.abs(i.seconds)>1440*60||i.type===`seek-to`&&i.seconds>1440*60||i.type===`select-episode`&&i.episodeNumber>1e5||i.type===`switch-track`&&(i.trackId!==i.trackId.trim()||i.trackId.length>256)||i.type===`switch-playlist`&&(i.playlistId!==i.playlistId.trim()||i.playlistId.length>256)||i.type===`switch-title`&&(i.titleId!==i.titleId.trim()||i.titleId.length>256)||i.type===`set-subtitle-font-color`&&i.color.length>128||i.type===`set-subtitle-background`&&i.background.length>128)throw Error(`Playback command exceeds the allowed range.`);return i}function f(e){return e===`Playback session not found.`?404:400}async function p(n,r){try{let{sessionId:i}=await r.params,a=c(i),s=l(new URL(n.url).searchParams.get(`after`));return e.json(t(a,s,Date.now(),u(n)),{headers:o})}catch(t){let n=t instanceof Error?t.message:`Playback commands could not be loaded.`;return e.json({error:n},{status:f(n),headers:o})}}async function m(t,n){try{let{sessionId:i}=await n.params,a=c(i),s=r(a,d(await t.json(),a),Date.now(),u(t));return e.json({command:s,cursor:s.id},{status:201,headers:o})}catch(t){let n=t instanceof Error?t.message:`Playback command could not be queued.`;return e.json({error:n},{status:f(n),headers:o})}}export{p as GET,m as POST,a as dynamic,i as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{D as t,a as n,m as r}from"./database-D79CeUrn.js";var i=`nodejs`,a=`force-dynamic`;async function o(t){try{let{searchParams:n}=new URL(t.url),i=n.get(`titleId`)?.trim()??``,a=n.get(`profileId`)?.trim()||void 0;if(!i)throw Error(`Title ID is required.`);return e.json({markers:r(i,a)})}catch(t){let n=t instanceof Error?t.message:`Markers could not be loaded.`;return e.json({error:n},{status:400})}}async function s(n){try{let r=await n.json(),i=typeof r.titleId==`string`?r.titleId.trim():``,a=r.markerType,o=Number(r.timeSeconds),s=typeof r.profileId==`string`&&r.profileId.trim()||void 0;if(!i)throw Error(`Title ID is required.`);let c=t(i,a,o,s);return e.json(c)}catch(t){let n=t instanceof Error?t.message:`Marker could not be saved.`;return e.json({error:n},{status:400})}}async function c(t){try{let r=await t.json(),i=typeof r.titleId==`string`?r.titleId.trim():``,a=r.markerType,o=typeof r.profileId==`string`&&r.profileId.trim()||void 0;if(!i)throw Error(`Title ID is required.`);if(a!==`intro`&&a!==`outro`)throw Error(`Marker type must be 'intro' or 'outro'.`);return n(i,a,o),e.json({ok:!0})}catch(t){let n=t instanceof Error?t.message:`Marker could not be deleted.`;return e.json({error:n},{status:400})}}export{c as DELETE,o as GET,s as PUT,a as dynamic,i as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{I as t,M as n}from"./database-D79CeUrn.js";import{o as r,t as i}from"./providers-DwLUa_U_.js";import{t as a}from"./request-profile-ClcH0i0T.js";var o=`nodejs`,s=60;async function c(o,s){let{providerId:c}=await s.params,l=i.find(e=>e.id===c);if(!l)return e.json({error:`Unknown provider.`},{status:404});let u=l.id,d=a(o);n(u,`syncing`,void 0,d);try{let i=await r(u);for(let e of i)t(e,`metadata`,d);return n(u,`idle`,void 0,d),e.json({count:i.length})}catch(t){let r=t instanceof Error?t.message:`Provider sync failed.`;return n(u,`error`,r,d),e.json({error:r},{status:502})}}export{c as POST,s as maxDuration,o as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./streamer-
|
|
1
|
+
import{n as e}from"./streamer-DUAWx_Tm.js";var t=`nodejs`,n=`force-dynamic`,r=60;async function i(t,n){let{id:r,path:i}=await n.params;return e(t,r,i)}export{i as GET,n as dynamic,r as maxDuration,t as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{g as n}from"./db-x8J3Vuoa.js";var r=`nodejs`,i=`force-dynamic`;function a(r){let i=t(r);return e.json({playlists:n(i)},{headers:{"cache-control":`no-store`}})}export{a as GET,i as dynamic,r as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{f as t,g as n,p as r}from"./database-D79CeUrn.js";import{t as i}from"./catalog-BS93IoWO.js";import{c as a,l as o,s}from"./providers-DwLUa_U_.js";import{n as c,t as l}from"./title-progress-BTypVYBz.js";var u=`nodejs`,d=`force-dynamic`,f=60,p={"cache-control":`no-store`},m=class extends Error{};function h(e){let t=e.searchParams.get(`profileId`)?.trim()??``;if(!t||t.length>128)throw Error(`A valid profile ID is required.`);return t}function g(e){return e===`Profile not found.`?404:400}async function _(u){try{let d=new URL(u.url),f=h(d),g=d.searchParams.get(`q`)?.trim()??``;if(g.length>120)throw Error(`Search query is too long.`);let _=t(f),v=r(f).map(e=>e.id),y=new Map(_.progress.map(e=>[e.titleId,e]));if(!g){let t=[];for(let e of _.progress){let n=c(e.titleId,f);if(n&&(t.push(l(n,e)),t.length===12))break}return e.json({titles:t,mode:`recent`,failedProviders:[]},{headers:p})}let b=[...i,...n(f)].filter(e=>o(e,g)),x=a(b,v),S=[];if(g.length>=2){let e;try{e=await s(g,v)}catch(e){throw new m(e instanceof Error?e.message:`Provider search failed.`)}x=a([...b,...e.titles],v),S=e.failedProviders}return e.json({titles:x.map(e=>l(e,y.get(e.id))),mode:`search`,failedProviders:S},{headers:p})}catch(t){let n=t instanceof Error?t.message:`Activity titles could not be loaded.`;return e.json({error:n},{status:t instanceof m?502:g(n),headers:p})}}export{_ as GET,d as dynamic,f as maxDuration,u as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{_ as n}from"./db-x8J3Vuoa.js";var r=`nodejs`,i=`force-dynamic`;function a(r){let i=t(r);return e.json({providers:n(i)},{headers:{"cache-control":`no-store`}})}export{a as GET,i as dynamic,r as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{n,r,t as i}from"./http-B2HyuWoI.js";import{n as a}from"./providers-_uOQh6hB.js";var o=`nodejs`,s=`force-dynamic`;async function c(o,s){let{id:c}=await s.params;if(c!==`zing-mp3`&&c!==`nhac-cua-tui`&&c!==`tiktok`&&c!==`youtube`)return e.json({error:`Unknown music provider.`},{status:404});try{n(o);let r=await a(c,t(o));return e.json({provider:r},{headers:{"cache-control":`no-store`}})}catch(t){return e.json({error:r(t)},{status:t instanceof i?t.status:502,headers:{"cache-control":`no-store`}})}}export{c as POST,s as dynamic,o as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{L as t,R as n,c as r,v as i}from"./database-D79CeUrn.js";var a=`nodejs`,o=`force-dynamic`,s={"cache-control":`no-store`};function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(e,t){let n=e?.trim()??``;if(!n||n.length>128)throw Error(`${t} is required.`);return n}function u(e){let t={kind:`announce`,activity:c(e)&&`activity`in e?e.activity:e};if(!n(t)||t.kind!==`announce`)throw Error(`Playback activity is invalid.`);let r=t.activity,i=r.sessionId!==r.sessionId.trim()||r.profileId!==r.profileId.trim()||r.titleId!==r.titleId.trim()||r.sessionId.length>128||r.profileId.length>128||r.titleId.length>256||r.title.length>500||r.artwork.length>8192,a=r.service===`spotify`?r.artist.length>500||r.album.length>500||(r.provider?.length??0)>200:r.episodeTitle.length>500||r.episodes.length>1e3||r.episodes.some(e=>e.title.length>500);if(i||a)throw Error(`Playback activity exceeds the allowed size.`);return r}function d(e){return e===`Profile not found.`?404:400}function f(t){try{let n=new URL(t.url).searchParams.get(`profileId`),r=n===null?void 0:l(n,`Profile ID`);return e.json({activities:i(r)},{headers:s})}catch(t){let n=t instanceof Error?t.message:`Playback activity could not be loaded.`;return e.json({error:n},{status:d(n),headers:s})}}async function p(n){try{let r=u(await n.json());return e.json({activity:t(r)},{headers:s})}catch(t){let n=t instanceof Error?t.message:`Playback activity could not be saved.`;return e.json({error:n},{status:d(n),headers:s})}}async function m(t){try{let n=new URL(t.url).searchParams.get(`sessionId`),i=null,a=null;if(n===null){let e=await t.json();i=c(e)&&typeof e.sessionId==`string`?e.sessionId:null,a=c(e)&&typeof e.profileId==`string`?e.profileId:null}let o=l(n??i,`Session ID`),u=new URL(t.url).searchParams.get(`profileId`),d=u===null&&a===null?void 0:l(u??a,`Profile ID`);return e.json({sessionId:o,ended:r(o,d)},{headers:s})}catch(t){let n=t instanceof Error?t.message:`Playback activity could not be ended.`;return e.json({error:n},{status:400,headers:s})}}export{m as DELETE,f as GET,p as PUT,o as dynamic,a as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{r as t}from"./input-platform-C0756QEt.js";import{i as n,r}from"./automation-tAN_1u1H.js";var i=`nodejs`,a=`force-dynamic`;async function o(i){if(!t(i))return e.json({error:`Cross-site screen access is not allowed.`},{status:403});let a=await r({fresh:!0});return e.json({...a,displays:a.displays.map(n)},{headers:{"Cache-Control":`private, no-store`}})}export{o as GET,a as dynamic,i as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{t as n}from"./streamer-DUAWx_Tm.js";var r=`nodejs`,i=`force-dynamic`,a=60;async function o(r,i){try{let{id:a}=await i.params,o=new URL(r.url).searchParams,s=Number(o.get(`episode`)||0),c=o.get(`server`)?.trim()||void 0,l=t(r);return e.json(await n(a,Number.isInteger(s)&&s>0?s:void 0,l,c))}catch(t){return e.json({error:t instanceof Error?t.message:`The stream could not be started.`},{status:502})}}export{o as GET,i as dynamic,a as maxDuration,r as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{f as t,k as n}from"./database-D79CeUrn.js";var r=`nodejs`,i=`force-dynamic`;async function a(r,i){try{let{id:r}=await i.params,a=n(r);return e.json({activeProfile:a,library:t(r)})}catch(t){return e.json({error:t instanceof Error?t.message:`Profile could not be selected.`},{status:404})}}export{a as POST,i as dynamic,r as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{j as t}from"./database-D79CeUrn.js";import{t as n}from"./request-profile-ClcH0i0T.js";var r=`nodejs`,i=`force-dynamic`;async function a(r){try{let i=await r.json();if(!i||typeof i!=`object`||Array.isArray(i))throw Error(`Provider order is invalid.`);let a=i;if(!Array.isArray(a.providerIds)||a.providerIds.some(e=>typeof e!=`string`))throw Error(`Provider order is invalid.`);let o=n(r,a.profileId);return e.json({providers:t(a.providerIds,o)})}catch(t){let n=t instanceof Error?t.message:`Provider order could not be saved.`;return e.json({error:n},{status:n===`Profile not found.`?404:400})}}export{a as PUT,i as dynamic,r as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{p as t}from"./database-D79CeUrn.js";import{s as n}from"./providers-DwLUa_U_.js";import{t as r}from"./request-profile-ClcH0i0T.js";var i=`nodejs`,a=`force-dynamic`,o=60;async function s(i){let a=new URL(i.url).searchParams.get(`q`)?.trim()??``;if(a.length<2)return e.json({titles:[],failedProviders:[]});if(a.length>120)return e.json({error:`Search query is too long.`},{status:400});try{let o=t(r(i)).map(e=>e.id);return e.json(await n(a,o))}catch(t){let n=t instanceof Error?t.message:`Provider search failed.`;return e.json({error:n},{status:n===`Profile not found.`?404:502})}}export{s as GET,a as dynamic,o as maxDuration,i as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{A as t,N as n,f as r,h as i}from"./database-D79CeUrn.js";var a=`nodejs`,o=`force-dynamic`;async function s(t,n){try{let{id:t}=await n.params;return e.json(r(t))}catch(t){return e.json({error:t instanceof Error?t.message:`Profile library is unavailable.`},{status:404})}}async function c(r,a){try{let{id:o}=await a.params,s=await r.json(),c=typeof s.titleId==`string`?s.titleId.trim():``;if(!c)throw Error(`A title is required.`);if(s.inMyList!==void 0&&typeof s.inMyList!=`boolean`)throw Error(`My List state must be true or false.`);if(s.liked!==void 0&&typeof s.liked!=`boolean`)throw Error(`Rating state must be true or false.`);if(s.tracked!==void 0&&typeof s.tracked!=`boolean`)throw Error(`Episode tracking must be true or false.`);if(s.episodeSort!==void 0&&!i(s.episodeSort))throw Error(`Episode order must be 'asc' or 'desc'.`);return typeof s.tracked==`boolean`&&n(o,c,s.tracked),e.json(t(o,c,{inMyList:typeof s.inMyList==`boolean`?s.inMyList:void 0,liked:typeof s.liked==`boolean`?s.liked:void 0,episodeSort:i(s.episodeSort)?s.episodeSort:void 0}))}catch(t){let n=t instanceof Error?t.message:`Title state could not be saved.`;return e.json({error:n},{status:n===`Profile not found.`?404:400})}}export{s as GET,c as PATCH,o as dynamic,a as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{_ as t,s as n,x as r}from"./database-D79CeUrn.js";import{t as i}from"./request-profile-ClcH0i0T.js";var a=`nodejs`,o=`force-dynamic`;function s(n){let r=i(n);return e.json({newEpisodes:t(r)})}async function c(t){try{let a=await t.json(),o=i(t,a.profileId);if(a.action===`mark-seen`)return e.json(r(o));if(a.action===`dismiss`){let t=typeof a.titleId==`string`?a.titleId.trim():``;if(!t)throw Error(`A title is required.`);return e.json(n(o,t))}throw Error(`Unsupported action.`)}catch(t){let n=t instanceof Error?t.message:`New episode alerts could not be updated.`;return e.json({error:n},{status:n===`Profile not found.`?404:400})}}export{s as GET,c as POST,o as dynamic,a as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./request-profile-
|
|
1
|
+
import{t as e}from"./request-profile-ClcH0i0T.js";import{m as t,t as n}from"./db-x8J3Vuoa.js";import r from"node:path";import{createReadStream as i}from"node:fs";import{Readable as a}from"node:stream";import{stat as o}from"node:fs/promises";var s=`nodejs`,c=`force-dynamic`;function l(){return new Response(`Audio file not found.`,{status:404,headers:{"cache-control":`no-store`}})}async function u(s,c,u){let{id:d}=await c.params,f=t(d,e(s));if(!f?.audioPath||f.downloadStatus!==`completed`)return l();let p=`${r.resolve(n)}${r.sep}`,m=r.resolve(f.audioPath);if(!m.startsWith(p))return l();let h;try{let e=await o(m);if(!e.isFile())return l();h=e.size}catch{return l()}let g=new Headers({"accept-ranges":`bytes`,"cache-control":`private, no-cache`,"content-type":f.audioMime||`audio/mpeg`,"x-content-type-options":`nosniff`}),_=s.headers.get(`range`);if(!_){if(g.set(`content-length`,String(h)),u)return new Response(null,{status:200,headers:g});let e=i(m);return new Response(a.toWeb(e),{status:200,headers:g})}let v=_.match(/^bytes=(\d*)-(\d*)$/);if(!v||!v[1]&&!v[2])return new Response(`Invalid byte range.`,{status:416,headers:{"cache-control":`no-store`,"content-range":`bytes */${h}`}});let y,b;if(v[1])y=Number(v[1]),b=v[2]?Number(v[2]):h-1;else{let e=Number(v[2]);if(!Number.isSafeInteger(e)||e<=0)return new Response(`Invalid byte range.`,{status:416,headers:{"content-range":`bytes */${h}`}});y=Math.max(0,h-e),b=h-1}if(!Number.isSafeInteger(y)||!Number.isSafeInteger(b)||y<0||b<y||y>=h)return new Response(`Requested range is not satisfiable.`,{status:416,headers:{"cache-control":`no-store`,"content-range":`bytes */${h}`}});if(b=Math.min(b,h-1),g.set(`content-length`,String(b-y+1)),g.set(`content-range`,`bytes ${y}-${b}/${h}`),u)return new Response(null,{status:206,headers:g});let x=i(m,{start:y,end:b});return new Response(a.toWeb(x),{status:206,headers:g})}function d(e,t){return u(e,t,!1)}function f(e,t){return u(e,t,!0)}export{d as GET,f as HEAD,c as dynamic,s as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{t}from"./request-profile-ClcH0i0T.js";import{h as n}from"./db-x8J3Vuoa.js";var r=`nodejs`,i=`force-dynamic`;function a(r){let i=t(r);return e.json({downloads:n(100,i)},{headers:{"cache-control":`no-store`}})}export{a as GET,i as dynamic,r as runtime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{f as t}from"./database-D79CeUrn.js";import{t as n}from"./request-profile-ClcH0i0T.js";import{i as r,n as i,r as a,t as o}from"./episode-sync-Ct5CeY25.js";var s=`nodejs`,c=`force-dynamic`,l=300;function u(){return i(),e.json({intervalMs:o,maxIdleHours:240,lastSummary:a()})}async function d(a){try{let o=await a.json().catch(()=>({})),s=n(a,o.profileId);i();let c=await r(o.allProfiles===!0?void 0:s);return c?e.json({summary:c,library:t(s)}):e.json({error:`An episode sync is already running.`,library:t(s)},{status:409})}catch(t){let n=t instanceof Error?t.message:`Episode sync failed.`;return e.json({error:n},{status:n===`Profile not found.`?404:400})}}export{u as GET,d as POST,c as dynamic,l as maxDuration,s as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-CS40XqUP.js";import{r as t}from"./storage-D1zF0J_t.js";import{t as n}from"./request-profile-B1yGQ0l6.js";import{C as r,T as i,b as a,c as o,d as s,f as c,i as l,l as u,o as d,r as f,s as p,t as m,u as h,w as g}from"./db-BE1J0NNS.js";import{a as _,n as v,o as y,r as b,t as x}from"./http-B2HyuWoI.js";import{t as S}from"./providers-CMBIwNGs.js";import C from"node:path";import{createHash as w,randomUUID as T}from"node:crypto";import{mkdir as ee,open as te,rename as ne,rm as E,stat as D}from"node:fs/promises";function O(e){let t=e.hostname.toLowerCase(),n=e.pathname.split(`/`).filter(Boolean),r=t===`youtu.be`?n[0]??``:n[0]===`shorts`||n[0]===`embed`||n[0]===`live`?n[1]??``:e.searchParams.get(`v`)??``;return/^[A-Za-z0-9_-]{11}$/.test(r)?r:null}function k(e){let t=e.searchParams.get(`list`)?.trim()??``;return/^[A-Za-z0-9_-]{2,128}$/.test(t)?t:null}function A(e){let t=e.pathname.match(/\/video\/(\d{8,24})(?:\/|$)/),n=e.pathname.match(/\/music\/[^/]*?(\d{8,24})(?:\/|$)/);if(t?.[1])return{id:t[1],kind:`video`};if(n?.[1])return{id:n[1],kind:`music`};let r=e.hostname.toLowerCase();if(r===`vm.tiktok.com`||r===`vt.tiktok.com`||e.pathname.startsWith(`/t/`)){let t=e.pathname.split(`/`).filter(Boolean).at(-1);if(t&&/^[A-Za-z0-9_-]{4,80}$/.test(t))return{id:`short-${w(`sha256`).update(t).digest(`hex`).slice(0,20)}`,kind:`short`}}return null}function re(e){return A(e)?.id??null}function ie(e,t){let n=A(t);if(n&&n.kind!==`short`)return n;let r=A(e);return r&&r.kind!==`short`?r:null}var j=100*1024*1024,M=64*1024,ae=250,oe=2,N=100,se=20,P=globalThis;function ce(){let e=P.spotifyDownloadAdmissionTokens??new Set;if(P.spotifyDownloadAdmissionTokens=e,e.size>=oe)throw new x(`Two music imports are already running. Wait for one to finish.`,429);let t=T();e.add(t);let n=!1;return()=>{n||(n=!0,e.delete(t))}}function F(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function I(e,t=``){return typeof e==`string`&&e.trim()?e.trim():t}function L(e){return typeof e==`string`?e.trim():typeof e==`number`&&Number.isSafeInteger(e)?String(e):``}function R(e){let t=e.pathname.match(/\/([A-Z0-9]{8})\.html$/i),n=e.pathname.match(/\/link\/song\/([A-Z0-9]{8})\/?$/i),r=t?.[1]??n?.[1];if(!r||!e.pathname.includes(`/bai-hat/`)&&!n)throw new x(`Enter a Zing MP3 song link, not a playlist or artist link.`,400);return r.toUpperCase()}function z(e){let t=e.pathname.match(/\/song\/([A-Za-z0-9]+)\/?$/),n=e.pathname.match(/\.([A-Za-z0-9]{8,})\.html$/),r=t?.[1]??n?.[1];if(!r||!e.pathname.includes(`/bai-hat/`)&&!t)throw new x(`Enter a NhacCuaTui song link, not a playlist or artist link.`,400);return r}function B(e){let t=O(e);if(!t)throw new x(`Enter a direct YouTube video, Short, or music video link.`,400);return t}function le(e){let t=re(e);if(t)return t;throw new x(`Enter a direct TikTok video, music, or shared short link.`,400)}function V(e,t){return e===t||e.endsWith(`.${t}`)}function H(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||!(n===`zmdcdn.me`||n.endsWith(`.zmdcdn.me`)||n===`zadn.vn`||n.endsWith(`.zadn.vn`)))throw new x(`Zing MP3 returned an invalid media address.`);return t.toString()}function U(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||!(n===`nct.vn`||n.endsWith(`.nct.vn`)||n===`nixcdn.com`||n.endsWith(`.nixcdn.com`)))throw new x(`NhacCuaTui returned an invalid media address.`);return t.toString()}function W(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||![`tiktok.com`,`tiktokcdn.com`,`tiktokcdn-us.com`,`tiktokv.com`,`byteoversea.com`,`bytefcdn-oversea.com`,`ibytedtos.com`,`musical.ly`].some(e=>V(n,e)))throw new x(`TikTok returned an invalid media address.`);return t.toString()}function G(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||!V(n,`googlevideo.com`))throw new x(`YouTube returned an invalid media address.`);return t.toString()}async function ue(e){let t=R(e),n=await S(`/api/v2/song/get/info`,{id:t}),r=await S(`/api/v2/song/get/streaming`,{id:t}),i=I(r[128])||(I(r[320])===`VIP`?``:I(r[320]));if(!i||i===`VIP`)throw new x(`This Zing MP3 track does not expose a non-VIP audio stream.`,422);if(n.streamingStatus===2||n.isPrivate===!0||n.isWorldWide===!1&&n.streamingStatus!==1)throw new x(`This Zing MP3 track is restricted and cannot be imported.`,422);let a=F(n.album)?I(n.album.title):``,o=I(n.link);return{provider:`zing-mp3`,externalId:I(n.encodeId,t),sourceUrl:o?new URL(o,`https://zingmp3.vn/`).toString():e.toString(),title:I(n.title,`Untitled track`),artist:I(n.artistsNames,`Unknown artist`),album:a||`Imported from Zing MP3`,durationSec:typeof n.duration==`number`&&Number.isFinite(n.duration)?Math.max(0,Math.round(n.duration)):0,imageUrl:I(n.thumbnailM)||I(n.thumbnail)||null,streamUrl:H(i)}}function de(e,t){let n=e.match(/<script\b[^>]*\bid=["']__NUXT_DATA__["'][^>]*>([\s\S]*?)<\/script>/i);if(!n)throw new x(`NhacCuaTui did not return music data for this link.`,422);let r;try{r=JSON.parse(n[1])}catch{throw new x(`NhacCuaTui returned malformed music data.`,502)}if(!Array.isArray(r))throw new x(`NhacCuaTui returned an unsupported music response.`,502);let i=e=>typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<r.length?r[e]:e,a=e=>{let t=i(e);return Array.isArray(t)&&(t[0]===`ShallowReactive`||t[0]===`Reactive`)?i(t[1]):t},o=`dataDetail:${t}`,s=a(r[0]),c=F(s)?a(s.data):void 0,l=F(c)?i(c[o]):void 0;if(!F(l)||I(i(l.key))!==t)throw new x(`NhacCuaTui did not return details for the requested track.`,422);let u=i(l.streamURL),d=Array.isArray(u)?u.map(e=>i(e)).filter(F).map(e=>({onlyVip:i(e.onlyVIP),status:i(e.status),type:I(i(e.type)),url:I(i(e.stream))})).filter(e=>e.status===1&&e.onlyVip===!1&&!!e.url):[],f=d.find(e=>e.type===`128`)??d[0];if(!f)throw new x(`This NhacCuaTui track does not expose a non-VIP audio stream.`,422);let p=i(l.duration);return{title:I(i(l.name),`Untitled track`),artist:I(i(l.artistName),`Unknown artist`),durationSec:typeof p==`number`&&Number.isFinite(p)?Math.max(0,Math.round(p)):0,imageUrl:I(i(l.image))||null,streamUrl:U(f.url)}}async function fe(e){let t=z(e),n=new URL(`/song/${encodeURIComponent(t)}`,`https://www.nhaccuatui.com/`),{text:r}=await _(n,`nhac-cua-tui`),i=de(r,t);return{provider:`nhac-cua-tui`,externalId:t,sourceUrl:n.toString(),title:i.title,artist:i.artist,album:`Imported from NhacCuaTui`,durationSec:i.durationSec,imageUrl:i.imageUrl,streamUrl:i.streamUrl}}function K(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=e.match(RegExp(`<script\\b[^>]*\\bid=["']${n}["'][^>]*>([\\s\\S]*?)<\\/script>`,`i`));if(!r)return null;try{return JSON.parse(r[1])}catch{return null}}function pe(e,t){let n=e.indexOf(t);if(n<0)return null;let r=e.indexOf(`{`,n+t.length);if(r<0)return null;let i=0,a=!1,o=!1;for(let t=r;t<e.length;t+=1){let n=e[t];if(a){o?o=!1:n===`\\`?o=!0:n===`"`&&(a=!1);continue}if(n===`"`)a=!0;else if(n===`{`)i+=1;else if(n===`}`&&(--i,i===0))try{return JSON.parse(e.slice(r,t+1))}catch{return null}}return null}function q(e,t,n=0){if(!(n>20)){if(Array.isArray(e)){for(let r of e)q(r,t,n+1);return}if(F(e)){t(e);for(let r of Object.values(e))q(r,t,n+1)}}}function J(e){return typeof e==`string`?e.trim():F(e)?I(e.url)||I(e.uri)||I(e.playUrl)||(Array.isArray(e.urlList)?e.urlList.map(e=>I(e)).find(Boolean)??``:``):``}function Y(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?Math.max(0,Math.round(t)):0}function me(e){return e&&(J(e.coverLarge)||J(e.coverMedium)||J(e.coverThumb)||J(e.originCover)||J(e.dynamicCover)||J(e.cover))||null}function he(e){return e.replace(/&/gi,`&`).replace(/"/gi,`"`).replace(/'|'/gi,`'`).replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}function X(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=[RegExp(`<meta\\b[^>]*(?:property|name)=["']${n}["'][^>]*content=["']([^"']*)["'][^>]*>`,`i`),RegExp(`<meta\\b[^>]*content=["']([^"']*)["'][^>]*(?:property|name)=["']${n}["'][^>]*>`,`i`)];for(let t of r){let n=e.match(t);if(n)return he(n[1]).trim()}return``}function ge(e,t){let n=[],r=[];q(e,e=>{L(e.id)&&(F(e.music)||F(e.video))&&n.push(e),L(e.id)&&I(e.title)&&J(e.playUrl)&&r.push(e)});let i=t.kind===`video`?n.find(e=>L(e.id)===t.id)??null:n.find(e=>L((F(e.music)?e.music:null)?.id)===t.id)??null,a=i&&F(i.music)?i.music:null;return{item:i,music:t.kind===`video`||L(a?.id)===t.id?a:r.find(e=>L(e.id)===t.id)??null}}async function _e(e){le(e);let{text:t,url:n}=await _(e,`tiktok`,{headers:{accept:`text/html,application/xhtml+xml`,referer:`https://www.tiktok.com/`}}),r=ie(e,n);if(!r)throw new x(`The TikTok shared link did not resolve to a public video or music page.`,422);let{item:i,music:a}=ge(K(t,`__UNIVERSAL_DATA_FOR_REHYDRATION__`)??K(t,`SIGI_STATE`),r);if(r.kind===`video`&&!i)throw new x(`TikTok returned data for a different video.`,422);if(r.kind===`music`&&!a)throw new x(`TikTok returned data for a different sound.`,422);let o=i&&F(i.video)?i.video:null,s=i&&F(i.author)?i.author:null,c=J(a?.playUrl)||J(o?.playAddr)||J(o?.downloadAddr)||(r.kind===`video`?X(t,`og:video`):``);if(!c)throw new x(`This TikTok link does not expose a public music or video stream.`,422);let l=r.id,u=I(s?.uniqueId),d=I(a?.authorName)||I(s?.nickname)||u||`TikTok creator`,f=r.kind===`video`&&u?new URL(`/@${encodeURIComponent(u)}/video/${l}`,`https://www.tiktok.com/`):new URL(n);return f.search=``,f.hash=``,{provider:`tiktok`,externalId:l,sourceUrl:f.toString(),title:I(a?.title)||I(i?.desc)||X(t,`og:title`)||`TikTok audio`,artist:d,album:`Imported from TikTok`,durationSec:Y(a?.duration)||Y(o?.duration),imageUrl:me(a)||me(o)||X(t,`og:image`)||null,streamUrl:W(c)}}function Z(e){return F(e)&&I((Array.isArray(e.thumbnails)?e.thumbnails:Array.isArray(e.sources)?e.sources:[]).filter(F).at(-1)?.url)||null}function Q(e){return typeof e==`string`?e.trim():F(e)?I(e.simpleText)||I(e.content)||(Array.isArray(e.runs)?e.runs.filter(F).map(e=>I(e.text)).filter(Boolean).join(``):``):``}function ve(e){let t=e.trim().split(`:`).map(e=>Number(e));return t.length!==2&&t.length!==3||t.some(e=>!Number.isInteger(e)||e<0)||t.slice(1).some(e=>e>59)?0:t.reduce((e,t)=>e*60+t,0)}function ye(e){let t=[],n=new Set,r=``,i=``,a=``,o=null,s=``;return q(e,e=>{let c=F(e.playlistVideoRenderer)?e.playlistVideoRenderer:null;if(c){let e=L(c.videoId),n=Q(c.title);c.isPlayable!==!1&&/^[A-Za-z0-9_-]{11}$/.test(e)&&n&&t.push({externalId:e,title:n,artist:Q(c.shortBylineText)||Q(c.longBylineText)||`YouTube creator`,durationSec:ve(Q(c.lengthText)),imageUrl:Z(c.thumbnail)})}let l=F(e.lockupViewModel)?e.lockupViewModel:null;if(l&&I(l.contentType)===`LOCKUP_CONTENT_TYPE_VIDEO`){let e=F(l.metadata)?l.metadata:null,n=e&&F(e.lockupMetadataViewModel)?e.lockupMetadataViewModel:null,r=L(l.contentId),i=Q(n?.title),a=n&&F(n.metadata)?n.metadata:null,o=a&&F(a.contentMetadataViewModel)?a.contentMetadataViewModel:null,s=(Array.isArray(o?.metadataRows)?o.metadataRows.filter(F):[])[0],c=Q((s&&Array.isArray(s.metadataParts)?s.metadataParts.filter(F):[]).find(e=>F(e.text))?.text)||`YouTube creator`,u=F(l.contentImage)?l.contentImage:null,d=u&&F(u.thumbnailViewModel)?u.thumbnailViewModel:null,f=d&&F(d.image)?d.image:null,p=0;q(d,e=>{p||!F(e.thumbnailBadgeViewModel)||(p=ve(Q(e.thumbnailBadgeViewModel.text)))}),/^[A-Za-z0-9_-]{11}$/.test(r)&&i&&t.push({externalId:r,title:i,artist:c,durationSec:p,imageUrl:Z(f)})}let u=F(e.pageHeaderRenderer)?e.pageHeaderRenderer:null;r||=Q(u?.pageTitle);let d=F(e.playlistHeaderRenderer)?e.playlistHeaderRenderer:null;r||=Q(d?.title),i||=Q(d?.descriptionText),a||=Q(d?.ownerText);let f=F(e.playlistMetadataRenderer)?e.playlistMetadataRenderer:null;r||=Q(f?.title),i||=Q(f?.description);let p=F(e.microformatDataRenderer)?e.microformatDataRenderer:null;r||=Q(p?.title),i||=Q(p?.description),o||=Z(p?.thumbnail);let m=F(e.videoOwnerRenderer)?e.videoOwnerRenderer:null;a||=Q(m?.title);let h=Q((F(e.avatarStackViewModel)?e.avatarStackViewModel:null)?.text).replace(/^by\s+/i,``);a||=h;let g=F(e.contentPreviewImageViewModel)?e.contentPreviewImageViewModel:null;o||=Z(g?.image);let _=F(e.playlistHeaderBanner)?e.playlistHeaderBanner:null,v=_&&F(_.heroPlaylistThumbnailRenderer)?_.heroPlaylistThumbnailRenderer:null;o||=Z(v?.thumbnail);let y=I((F(e.nextContinuationData)?e.nextContinuationData:null)?.continuation);y&&n.add(y);let b=I((F(e.continuationCommand)?e.continuationCommand:null)?.token);b&&n.add(b);let x=F(e.alertRenderer)?e.alertRenderer:null;x&&(!I(x.type)||I(x.type).toUpperCase()===`ERROR`)&&(s||=Q(x.text))}),{title:r,description:i,curator:a,imageUrl:o,items:t,continuations:[...n],alert:s}}function be(e){let t=F(e)&&F(e.streamingData)?e.streamingData:null;return[...Array.isArray(t?.adaptiveFormats)?t.adaptiveFormats:[],...Array.isArray(t?.formats)?t.formats:[]].filter(F).map(e=>{let t=Number(e.contentLength);return{audioQuality:I(e.audioQuality),bitrate:typeof e.bitrate==`number`&&Number.isFinite(e.bitrate)?e.bitrate:0,contentLength:Number.isFinite(t)&&t>0?t:null,mime:I(e.mimeType).split(`;`,1)[0].toLowerCase(),url:I(e.url)}}).filter(e=>!!e.url&&(!e.contentLength||e.contentLength<=j)&&(e.mime.startsWith(`audio/`)||e.mime===`video/mp4`&&!!e.audioQuality)).sort((e,t)=>{let n=e=>e.mime===`video/mp4`?50:e.mime===`audio/mp4`?40:e.mime===`audio/webm`?30:e.mime.startsWith(`audio/`)?20:10;return n(t)-n(e)||t.bitrate-e.bitrate})}async function xe(e){let{text:t}=await _(new URL(`/youtubei/v1/player?prettyPrint=false`,`https://www.youtube.com/`),`youtube`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":`com.google.android.youtube/20.10.38 (Linux; U; Android 15) gzip`,"x-youtube-client-name":`3`,"x-youtube-client-version":`20.10.38`},body:JSON.stringify({context:{client:{androidSdkVersion:35,clientName:`ANDROID`,clientVersion:`20.10.38`,gl:`US`,hl:`en`,utcOffsetMinutes:0}},contentCheckOk:!0,racyCheckOk:!0,videoId:e})}),n;try{n=JSON.parse(t)}catch{throw new x(`YouTube returned malformed player data.`)}if(!F(n))throw new x(`YouTube returned invalid player data.`);return n}async function Se(e,t){let n=new URL(`/youtubei/v1/browse?prettyPrint=false`,`https://www.youtube.com/`),r;try{({text:r}=await _(n,`youtube`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":`com.google.android.youtube/20.10.38 (Linux; U; Android 15) gzip`,"x-youtube-client-name":`3`,"x-youtube-client-version":`20.10.38`},body:JSON.stringify({context:{client:{androidSdkVersion:35,clientName:`ANDROID`,clientVersion:`20.10.38`,gl:`US`,hl:`en`,utcOffsetMinutes:0}},...t?{continuation:t}:{browseId:`VL${e}`}})}))}catch(e){throw e instanceof x&&/HTTP (?:403|404)\b/.test(e.message)?new x(`This YouTube playlist is private, deleted, or unavailable. Make it Public or Unlisted and try again.`,422):e}let i;try{i=JSON.parse(r)}catch{throw new x(`YouTube returned malformed playlist data.`)}if(!F(i))throw new x(`YouTube returned invalid playlist data.`);return i}async function Ce(e){let t=k(e);if(!t)throw new x(`Enter a direct YouTube playlist link.`,400);let n=new URL(`/playlist?list=${encodeURIComponent(t)}`,`https://www.youtube.com/`).toString(),r=[],i=new Set,a,o=``,s=``,c=``,l=null;for(let e=0;e<se;e+=1){let e=ye(await Se(t,a));if(e.alert)throw new x(`This YouTube playlist is private, deleted, or unavailable. Make it Public or Unlisted and try again.`,422);o||=e.title,s||=e.description,c||=e.curator,l||=e.imageUrl,r.push(...e.items);let n=e.continuations.find(e=>!i.has(e));if(r.length>N)throw new x(`YouTube playlists can contain at most ${N} importable videos.`,413);if(!n){a=void 0;break}if(r.length>=N)throw new x(`YouTube playlists can contain at most ${N} importable videos.`,413);i.add(n),a=n}if(a)throw new x(`The YouTube playlist returned too many continuation pages.`,413);if(!r.length)throw new x(`This YouTube playlist has no public, playable videos.`,422);return{externalId:t,sourceUrl:n,title:o||`Imported YouTube playlist`,description:s||`${r.length} videos imported from YouTube`,curator:c||`YouTube`,imageUrl:l||r[0]?.imageUrl||null,items:r}}async function we(e){let t=B(e),n=new URL(`/watch?v=${encodeURIComponent(t)}`,`https://www.youtube.com/`),{text:r}=await _(n,`youtube`,{headers:{accept:`text/html,application/xhtml+xml`,cookie:`CONSENT=YES+cb`,referer:`https://www.youtube.com/`}}),i=pe(r,`ytInitialPlayerResponse`),a=i,o=be(a);o.length||(a=await xe(t),o=be(a));let s=F(a)&&F(a.videoDetails)?a.videoDetails:F(i)&&F(i.videoDetails)?i.videoDetails:null,c=o[0];if(!s||!c)throw new x(`This YouTube video does not expose a direct public audio stream.`,422);let l=L(s.videoId);if(l!==t)throw new x(`YouTube returned player data for a different video.`,422);let u=F(s.thumbnail)?s.thumbnail:null;return{provider:`youtube`,externalId:l,sourceUrl:n.toString(),title:I(s.title)||X(r,`og:title`)||`YouTube audio`,artist:I(s.author,`YouTube creator`),album:`Imported from YouTube`,durationSec:Y(s.lengthSeconds),imageUrl:Z(u)||X(r,`og:image`)||null,streamUrl:G(c.url)}}async function Te(e,t){switch(e){case`zing-mp3`:return ue(t);case`nhac-cua-tui`:return fe(t);case`tiktok`:return _e(t);case`youtube`:return we(t)}}function Ee(e,t){try{switch(t){case`zing-mp3`:H(e.toString());break;case`nhac-cua-tui`:U(e.toString());break;case`tiktok`:W(e.toString());break;case`youtube`:G(e.toString());break;default:return!1}return!0}catch{return!1}}function De(e,t){let n=e.hostname.toLowerCase(),r=/^(rr\d+---)(sn-[a-z0-9-]+)(\.googlevideo\.com)$/.exec(n);if(!r)return null;for(let i of(e.searchParams.get(`mn`)??``).split(`,`)){if(!/^sn-[a-z0-9-]+$/.test(i))continue;let a=`${r[1]}${i}${r[3]}`;if(a===n||t.has(a))continue;let o=new URL(e);return o.hostname=a,o}return null}async function Oe(e,t){let n=new URL(e),r=new Set;for(let e=0;e<=5;e+=1){if(!Ee(n,t))throw new x(`The media host redirected to an unsupported address.`);let e;try{e=await fetch(n,{redirect:`manual`,signal:AbortSignal.timeout(6e4),headers:{accept:`audio/mpeg,audio/*;q=0.9,video/mp4;q=0.6,*/*;q=0.1`,"accept-encoding":`identity`,referer:{"zing-mp3":`https://zingmp3.vn/`,"nhac-cua-tui":`https://www.nhaccuatui.com/`,tiktok:`https://www.tiktok.com/`,youtube:`https://www.youtube.com/`}[t],"user-agent":t===`youtube`?`com.google.android.youtube/20.10.38 (Linux; U; Android 15) gzip`:`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 Chrome/140.0.0.0 Safari/537.36`}})}catch{r.add(n.hostname.toLowerCase());let e=t===`youtube`?De(n,r):null;if(e){n=e;continue}throw new x(`The provider media host could not be reached.`)}if([301,302,303,307,308].includes(e.status)){let t=e.headers.get(`location`);if(await e.body?.cancel().catch(()=>void 0),!t)throw new x(`The audio host returned an invalid redirect.`);try{n=new URL(t,n)}catch{throw new x(`The audio host returned an invalid redirect.`)}continue}if(!e.ok)throw await e.body?.cancel().catch(()=>void 0),new x(`The audio host returned HTTP ${e.status}.`);return e}throw new x(`The audio host redirected too many times.`)}var ke=new Set([`application/octet-stream`,`audio/aac`,`audio/mp3`,`audio/mp4`,`audio/mpeg`,`audio/ogg`,`audio/webm`,`audio/x-m4a`,`video/mp4`,`video/webm`]);function Ae(e){return e===`audio/mp3`?`audio/mpeg`:e===`audio/x-m4a`?`audio/mp4`:e}function je(e,t){let n=t===`audio/mpeg`||t===`audio/mp3`?`mp3`:t===`audio/aac`?`aac`:t===`audio/mp4`||t===`audio/x-m4a`?`m4a`:t===`video/mp4`?`mp4`:t.endsWith(`/webm`)?`webm`:t===`audio/ogg`?`ogg`:`media`;return`${w(`sha256`).update(e).digest(`hex`)}.${n}`}function Me(e){let t=w(`sha256`).update(e).digest(`hex`).slice(0,24);return C.join(m,t)}function Ne(e,t){if(t<0||t+3>=e.length)return!1;let n=e[t+1],r=e[t+2];return e[t]===255&&(n&224)==224&&(n>>3&3)!=1&&(n>>1&3)!=0&&(r>>4&15)!=0&&(r>>4&15)!=15&&(r>>2&3)!=3}function Pe(e){if(e.length<10||e[0]!==73||e[1]!==68||e[2]!==51||e[3]<2||e[3]>4||e.slice(6,10).some(e=>(e&128)!=0))return-1;let t=e[6]<<21|e[7]<<14|e[8]<<7|e[9],n=e[3]===4&&(e[5]&16)!=0;return 10+t+(n?10:0)}function Fe(e){if(e.length<7)return!1;let t=e[2]>>2&15,n=(e[3]&3)<<11|e[4]<<3|e[5]>>5&7;return e[0]===255&&(e[1]&246)==240&&t!==15&&n>=7}function Ie(e){let t=Pe(e);return Ne(e,0)||t>=0&&Ne(e,t)?`audio/mpeg`:Fe(e)?`audio/aac`:e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83?`audio/ogg`:e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163?`audio/webm`:e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112?`audio/mp4`:``}function Le(e,t,n){if(!n)return null;if(!t||t===`application/octet-stream`)return n;let r=Ae(t);return r===n||r===`video/mp4`&&n===`audio/mp4`||r===`video/webm`&&n===`audio/webm`?r:e===`tiktok`&&r===`video/mp4`&&n===`audio/mpeg`||r===`audio/aac`&&n===`audio/mpeg`?n:null}async function Re(e,t,n,o,s){let c=null,l=null,u=null;try{if(!r(e,{status:`fetching`,error:null},s))throw Error(`The download job is no longer available.`);let d=o??await Te(n,t);if(c=i({id:`${n}:${d.externalId}`,provider:n,externalId:d.externalId,sourceUrl:d.sourceUrl,title:d.title,artist:d.artist,album:d.album,durationSec:d.durationSec,imageUrl:d.imageUrl},s).id,!r(e,{trackId:c,status:`downloading`},s))throw Error(`The download job is no longer available.`);a(c,s);let p=await Oe(d.streamUrl,n);if(!p.body)throw new x(`The audio host returned an empty response.`);let m=p.headers.get(`content-type`)?.split(`;`,1)[0].trim().toLowerCase()??``;if(m&&!ke.has(m))throw await p.body.cancel().catch(()=>void 0),new x(`The provider returned unsupported media type ${m}.`);let h=Number(p.headers.get(`content-length`)),g=Number.isFinite(h)&&h>0?h:null;if(g&&g>j)throw await p.body.cancel().catch(()=>void 0),new x(`The audio file exceeds the 100 MB limit.`,413);let _=`${w(`sha256`).update(c).digest(`hex`)}.${e}.part`,v=Me(s);await ee(v,{recursive:!0}),l=C.join(v,_),await E(l,{force:!0});let y=await te(l,`w`),b=0,S=0,T=-1,D=[];try{let t=p.body.getReader();for(;;){let{done:n,value:i}=await t.read();if(n)break;if(b+i.byteLength>j)throw await t.cancel(),new x(`The audio file exceeds the 100 MB limit.`,413);D.length<M&&D.push(...i.subarray(0,M-D.length));let a=0;for(;a<i.byteLength;){let{bytesWritten:e}=await y.write(i,a,i.byteLength-a,null);if(e<=0)throw Error(`The local audio file could not be written.`);a+=e}b+=i.byteLength;let o=g?Math.min(99,Math.floor(b/g*100)):0,c=Date.now();if(o!==T||c-S>=ae){if(!r(e,{status:`downloading`,progress:o,bytesDownloaded:b,totalBytes:g},s))throw Error(`The download job is no longer available.`);T=o,S=c}}await y.sync()}finally{await y.close()}if(b===0)throw new x(`The audio host returned an empty file.`);if(g!==null&&b!==g)throw new x(`The audio download ended before the complete file was received.`);let O=Le(n,m,Ie(D));if(!O)throw new x(`The provider response is not a valid supported audio or video file.`);let k=C.join(v,je(c,O));if(await ne(l,k),l=null,u=k,f(c,k,O,b,s),!r(e,{status:`completed`,progress:100,bytesDownloaded:b,totalBytes:g??b,error:null},s))throw Error(`The completed download job could not be updated.`);u=null}catch(t){if(l&&await E(l,{force:!0}).catch(()=>void 0),u&&await E(u,{force:!0}).catch(()=>void 0),c)try{d(c,s)}catch{}try{r(e,{status:`failed`,error:b(t)},s)}catch{}}}async function $(e,n){n??=t().id;let{provider:r,url:i}=y(e),a,d,f,m=null;try{switch(r){case`zing-mp3`:d=R(i),a=new URL(`/link/song/${encodeURIComponent(d)}`,`https://zingmp3.vn/`).toString();break;case`nhac-cua-tui`:d=z(i),a=new URL(`/song/${encodeURIComponent(d)}`,`https://www.nhaccuatui.com/`).toString();break;case`tiktok`:m=ce(),f=await _e(i),d=f.externalId,a=f.sourceUrl;break;case`youtube`:d=B(i),a=new URL(`/watch?v=${encodeURIComponent(d)}`,`https://www.youtube.com/`).toString();break}let e=p(a,n);if(e)return e;let t=h(r,d,n)??s(a,n);if(t){let e=o(t.track.id,n);if(e)return e}if(t?.status===`completed`&&t.audioPath)try{let e=await D(t.audioPath);if(e.isFile()&&e.size>0)return u(t.track.id,n)||l(T(),a,r,`completed`,t.track.id,e.size,n)}catch{}m??=ce();let g;try{g=l(T(),a,r,`queued`,null,0,n)}catch(e){let t=p(a,n);if(t)return t;throw e}let _=m;return m=null,Re(g.id,i,r,f,n).finally(_).catch(()=>void 0),c(g.id,n)??g}finally{m?.()}}async function ze(e,t){for(let n=0;n<2400;n+=1){let n=c(e,t);if(!n||n.status===`completed`||n.status===`failed`)return;await new Promise(e=>setTimeout(e,500))}}async function Be(e,t){let n=`youtube:${e.externalId}`,r=new URL(`/watch?v=${encodeURIComponent(e.externalId)}`,`https://www.youtube.com/`).toString();for(let e=0;e<2400;e+=1)try{await ze((await $(r,t)).id,t);return}catch(e){if(e instanceof x&&e.status===429){await new Promise(e=>setTimeout(e,500));continue}d(n,t);return}d(n,t)}function Ve(e,t,n){let r=P.spotifyPlaylistImportTokens??new Set;P.spotifyPlaylistImportTokens=r;let i=`${n??`active`}:${e.id}`;if(r.has(i))return;r.add(i);let a=0,o=async()=>{for(;a<t.length;){let e=t[a];a+=1,await Be(e,n)}};Promise.all([o(),o()]).finally(()=>r.delete(i)).catch(()=>void 0)}async function He(e,t){let n=await Ce(e),r=g({id:`youtube-playlist:${n.externalId}`,provider:`youtube`,externalId:n.externalId,sourceUrl:n.sourceUrl,title:n.title,description:n.description,curator:n.curator,imageUrl:n.imageUrl,tracks:n.items.map(e=>({id:`youtube:${e.externalId}`,provider:`youtube`,externalId:e.externalId,sourceUrl:new URL(`/watch?v=${encodeURIComponent(e.externalId)}`,`https://www.youtube.com/`).toString(),title:e.title,artist:e.artist,album:n.title,durationSec:e.durationSec,imageUrl:e.imageUrl}))},t);return Ve(r,n.items,t),r}async function Ue(e,n){n??=t().id;let{provider:r,url:i}=y(e);return r===`youtube`&&k(i)?{playlist:await He(i,n)}:{download:await $(e,n)}}var We=`nodejs`,Ge=`force-dynamic`;async function Ke(t){try{v(t,{json:!0});let r;try{r=await t.json()}catch{return e.json({error:`Send a JSON object containing a music URL.`},{status:400})}let i=r&&typeof r==`object`&&`url`in r?r.url:null;if(typeof i!=`string`||!i.trim())return e.json({error:`Enter a music link.`},{status:400});if(i.length>2048)return e.json({error:`The music link is too long.`},{status:400});let a=await Ue(i,n(t,r&&typeof r==`object`&&`profileId`in r?r.profileId:void 0));return e.json(a,{status:`playlist`in a||a.download.status!==`completed`?202:200,headers:{"cache-control":`no-store`}})}catch(t){return e.json({error:b(t)},{status:t instanceof x?t.status:500,headers:{"cache-control":`no-store`}})}}export{Ke as POST,Ge as dynamic,We as runtime};
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{r as t}from"./storage-fxaUbjG1.js";import{t as n}from"./request-profile-ClcH0i0T.js";import{C as r,T as i,b as a,c as o,d as s,f as c,i as l,l as u,o as d,r as f,s as p,t as m,u as h,w as g}from"./db-x8J3Vuoa.js";import{a as _,n as v,o as y,r as b,t as x}from"./http-B2HyuWoI.js";import{t as S}from"./providers-_uOQh6hB.js";import C from"node:path";import{createHash as w,randomUUID as T}from"node:crypto";import{mkdir as ee,open as te,rename as ne,rm as E,stat as D}from"node:fs/promises";function O(e){let t=e.hostname.toLowerCase(),n=e.pathname.split(`/`).filter(Boolean),r=t===`youtu.be`?n[0]??``:n[0]===`shorts`||n[0]===`embed`||n[0]===`live`?n[1]??``:e.searchParams.get(`v`)??``;return/^[A-Za-z0-9_-]{11}$/.test(r)?r:null}function k(e){let t=e.searchParams.get(`list`)?.trim()??``;return/^[A-Za-z0-9_-]{2,128}$/.test(t)?t:null}function A(e){let t=e.pathname.match(/\/video\/(\d{8,24})(?:\/|$)/),n=e.pathname.match(/\/music\/[^/]*?(\d{8,24})(?:\/|$)/);if(t?.[1])return{id:t[1],kind:`video`};if(n?.[1])return{id:n[1],kind:`music`};let r=e.hostname.toLowerCase();if(r===`vm.tiktok.com`||r===`vt.tiktok.com`||e.pathname.startsWith(`/t/`)){let t=e.pathname.split(`/`).filter(Boolean).at(-1);if(t&&/^[A-Za-z0-9_-]{4,80}$/.test(t))return{id:`short-${w(`sha256`).update(t).digest(`hex`).slice(0,20)}`,kind:`short`}}return null}function re(e){return A(e)?.id??null}function ie(e,t){let n=A(t);if(n&&n.kind!==`short`)return n;let r=A(e);return r&&r.kind!==`short`?r:null}var j=100*1024*1024,M=64*1024,ae=250,oe=2,N=100,se=20,P=globalThis;function ce(){let e=P.spotifyDownloadAdmissionTokens??new Set;if(P.spotifyDownloadAdmissionTokens=e,e.size>=oe)throw new x(`Two music imports are already running. Wait for one to finish.`,429);let t=T();e.add(t);let n=!1;return()=>{n||(n=!0,e.delete(t))}}function F(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function I(e,t=``){return typeof e==`string`&&e.trim()?e.trim():t}function L(e){return typeof e==`string`?e.trim():typeof e==`number`&&Number.isSafeInteger(e)?String(e):``}function R(e){let t=e.pathname.match(/\/([A-Z0-9]{8})\.html$/i),n=e.pathname.match(/\/link\/song\/([A-Z0-9]{8})\/?$/i),r=t?.[1]??n?.[1];if(!r||!e.pathname.includes(`/bai-hat/`)&&!n)throw new x(`Enter a Zing MP3 song link, not a playlist or artist link.`,400);return r.toUpperCase()}function z(e){let t=e.pathname.match(/\/song\/([A-Za-z0-9]+)\/?$/),n=e.pathname.match(/\.([A-Za-z0-9]{8,})\.html$/),r=t?.[1]??n?.[1];if(!r||!e.pathname.includes(`/bai-hat/`)&&!t)throw new x(`Enter a NhacCuaTui song link, not a playlist or artist link.`,400);return r}function B(e){let t=O(e);if(!t)throw new x(`Enter a direct YouTube video, Short, or music video link.`,400);return t}function le(e){let t=re(e);if(t)return t;throw new x(`Enter a direct TikTok video, music, or shared short link.`,400)}function V(e,t){return e===t||e.endsWith(`.${t}`)}function H(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||!(n===`zmdcdn.me`||n.endsWith(`.zmdcdn.me`)||n===`zadn.vn`||n.endsWith(`.zadn.vn`)))throw new x(`Zing MP3 returned an invalid media address.`);return t.toString()}function U(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||!(n===`nct.vn`||n.endsWith(`.nct.vn`)||n===`nixcdn.com`||n.endsWith(`.nixcdn.com`)))throw new x(`NhacCuaTui returned an invalid media address.`);return t.toString()}function W(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||![`tiktok.com`,`tiktokcdn.com`,`tiktokcdn-us.com`,`tiktokv.com`,`byteoversea.com`,`bytefcdn-oversea.com`,`ibytedtos.com`,`musical.ly`].some(e=>V(n,e)))throw new x(`TikTok returned an invalid media address.`);return t.toString()}function G(e){let t=new URL(e),n=t.hostname.toLowerCase();if(t.protocol!==`https:`||t.username||t.password||t.port||!V(n,`googlevideo.com`))throw new x(`YouTube returned an invalid media address.`);return t.toString()}async function ue(e){let t=R(e),n=await S(`/api/v2/song/get/info`,{id:t}),r=await S(`/api/v2/song/get/streaming`,{id:t}),i=I(r[128])||(I(r[320])===`VIP`?``:I(r[320]));if(!i||i===`VIP`)throw new x(`This Zing MP3 track does not expose a non-VIP audio stream.`,422);if(n.streamingStatus===2||n.isPrivate===!0||n.isWorldWide===!1&&n.streamingStatus!==1)throw new x(`This Zing MP3 track is restricted and cannot be imported.`,422);let a=F(n.album)?I(n.album.title):``,o=I(n.link);return{provider:`zing-mp3`,externalId:I(n.encodeId,t),sourceUrl:o?new URL(o,`https://zingmp3.vn/`).toString():e.toString(),title:I(n.title,`Untitled track`),artist:I(n.artistsNames,`Unknown artist`),album:a||`Imported from Zing MP3`,durationSec:typeof n.duration==`number`&&Number.isFinite(n.duration)?Math.max(0,Math.round(n.duration)):0,imageUrl:I(n.thumbnailM)||I(n.thumbnail)||null,streamUrl:H(i)}}function de(e,t){let n=e.match(/<script\b[^>]*\bid=["']__NUXT_DATA__["'][^>]*>([\s\S]*?)<\/script>/i);if(!n)throw new x(`NhacCuaTui did not return music data for this link.`,422);let r;try{r=JSON.parse(n[1])}catch{throw new x(`NhacCuaTui returned malformed music data.`,502)}if(!Array.isArray(r))throw new x(`NhacCuaTui returned an unsupported music response.`,502);let i=e=>typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<r.length?r[e]:e,a=e=>{let t=i(e);return Array.isArray(t)&&(t[0]===`ShallowReactive`||t[0]===`Reactive`)?i(t[1]):t},o=`dataDetail:${t}`,s=a(r[0]),c=F(s)?a(s.data):void 0,l=F(c)?i(c[o]):void 0;if(!F(l)||I(i(l.key))!==t)throw new x(`NhacCuaTui did not return details for the requested track.`,422);let u=i(l.streamURL),d=Array.isArray(u)?u.map(e=>i(e)).filter(F).map(e=>({onlyVip:i(e.onlyVIP),status:i(e.status),type:I(i(e.type)),url:I(i(e.stream))})).filter(e=>e.status===1&&e.onlyVip===!1&&!!e.url):[],f=d.find(e=>e.type===`128`)??d[0];if(!f)throw new x(`This NhacCuaTui track does not expose a non-VIP audio stream.`,422);let p=i(l.duration);return{title:I(i(l.name),`Untitled track`),artist:I(i(l.artistName),`Unknown artist`),durationSec:typeof p==`number`&&Number.isFinite(p)?Math.max(0,Math.round(p)):0,imageUrl:I(i(l.image))||null,streamUrl:U(f.url)}}async function fe(e){let t=z(e),n=new URL(`/song/${encodeURIComponent(t)}`,`https://www.nhaccuatui.com/`),{text:r}=await _(n,`nhac-cua-tui`),i=de(r,t);return{provider:`nhac-cua-tui`,externalId:t,sourceUrl:n.toString(),title:i.title,artist:i.artist,album:`Imported from NhacCuaTui`,durationSec:i.durationSec,imageUrl:i.imageUrl,streamUrl:i.streamUrl}}function K(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=e.match(RegExp(`<script\\b[^>]*\\bid=["']${n}["'][^>]*>([\\s\\S]*?)<\\/script>`,`i`));if(!r)return null;try{return JSON.parse(r[1])}catch{return null}}function pe(e,t){let n=e.indexOf(t);if(n<0)return null;let r=e.indexOf(`{`,n+t.length);if(r<0)return null;let i=0,a=!1,o=!1;for(let t=r;t<e.length;t+=1){let n=e[t];if(a){o?o=!1:n===`\\`?o=!0:n===`"`&&(a=!1);continue}if(n===`"`)a=!0;else if(n===`{`)i+=1;else if(n===`}`&&(--i,i===0))try{return JSON.parse(e.slice(r,t+1))}catch{return null}}return null}function q(e,t,n=0){if(!(n>20)){if(Array.isArray(e)){for(let r of e)q(r,t,n+1);return}if(F(e)){t(e);for(let r of Object.values(e))q(r,t,n+1)}}}function J(e){return typeof e==`string`?e.trim():F(e)?I(e.url)||I(e.uri)||I(e.playUrl)||(Array.isArray(e.urlList)?e.urlList.map(e=>I(e)).find(Boolean)??``:``):``}function Y(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?Math.max(0,Math.round(t)):0}function me(e){return e&&(J(e.coverLarge)||J(e.coverMedium)||J(e.coverThumb)||J(e.originCover)||J(e.dynamicCover)||J(e.cover))||null}function he(e){return e.replace(/&/gi,`&`).replace(/"/gi,`"`).replace(/'|'/gi,`'`).replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}function X(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=[RegExp(`<meta\\b[^>]*(?:property|name)=["']${n}["'][^>]*content=["']([^"']*)["'][^>]*>`,`i`),RegExp(`<meta\\b[^>]*content=["']([^"']*)["'][^>]*(?:property|name)=["']${n}["'][^>]*>`,`i`)];for(let t of r){let n=e.match(t);if(n)return he(n[1]).trim()}return``}function ge(e,t){let n=[],r=[];q(e,e=>{L(e.id)&&(F(e.music)||F(e.video))&&n.push(e),L(e.id)&&I(e.title)&&J(e.playUrl)&&r.push(e)});let i=t.kind===`video`?n.find(e=>L(e.id)===t.id)??null:n.find(e=>L((F(e.music)?e.music:null)?.id)===t.id)??null,a=i&&F(i.music)?i.music:null;return{item:i,music:t.kind===`video`||L(a?.id)===t.id?a:r.find(e=>L(e.id)===t.id)??null}}async function _e(e){le(e);let{text:t,url:n}=await _(e,`tiktok`,{headers:{accept:`text/html,application/xhtml+xml`,referer:`https://www.tiktok.com/`}}),r=ie(e,n);if(!r)throw new x(`The TikTok shared link did not resolve to a public video or music page.`,422);let{item:i,music:a}=ge(K(t,`__UNIVERSAL_DATA_FOR_REHYDRATION__`)??K(t,`SIGI_STATE`),r);if(r.kind===`video`&&!i)throw new x(`TikTok returned data for a different video.`,422);if(r.kind===`music`&&!a)throw new x(`TikTok returned data for a different sound.`,422);let o=i&&F(i.video)?i.video:null,s=i&&F(i.author)?i.author:null,c=J(a?.playUrl)||J(o?.playAddr)||J(o?.downloadAddr)||(r.kind===`video`?X(t,`og:video`):``);if(!c)throw new x(`This TikTok link does not expose a public music or video stream.`,422);let l=r.id,u=I(s?.uniqueId),d=I(a?.authorName)||I(s?.nickname)||u||`TikTok creator`,f=r.kind===`video`&&u?new URL(`/@${encodeURIComponent(u)}/video/${l}`,`https://www.tiktok.com/`):new URL(n);return f.search=``,f.hash=``,{provider:`tiktok`,externalId:l,sourceUrl:f.toString(),title:I(a?.title)||I(i?.desc)||X(t,`og:title`)||`TikTok audio`,artist:d,album:`Imported from TikTok`,durationSec:Y(a?.duration)||Y(o?.duration),imageUrl:me(a)||me(o)||X(t,`og:image`)||null,streamUrl:W(c)}}function Z(e){return F(e)&&I((Array.isArray(e.thumbnails)?e.thumbnails:Array.isArray(e.sources)?e.sources:[]).filter(F).at(-1)?.url)||null}function Q(e){return typeof e==`string`?e.trim():F(e)?I(e.simpleText)||I(e.content)||(Array.isArray(e.runs)?e.runs.filter(F).map(e=>I(e.text)).filter(Boolean).join(``):``):``}function ve(e){let t=e.trim().split(`:`).map(e=>Number(e));return t.length!==2&&t.length!==3||t.some(e=>!Number.isInteger(e)||e<0)||t.slice(1).some(e=>e>59)?0:t.reduce((e,t)=>e*60+t,0)}function ye(e){let t=[],n=new Set,r=``,i=``,a=``,o=null,s=``;return q(e,e=>{let c=F(e.playlistVideoRenderer)?e.playlistVideoRenderer:null;if(c){let e=L(c.videoId),n=Q(c.title);c.isPlayable!==!1&&/^[A-Za-z0-9_-]{11}$/.test(e)&&n&&t.push({externalId:e,title:n,artist:Q(c.shortBylineText)||Q(c.longBylineText)||`YouTube creator`,durationSec:ve(Q(c.lengthText)),imageUrl:Z(c.thumbnail)})}let l=F(e.lockupViewModel)?e.lockupViewModel:null;if(l&&I(l.contentType)===`LOCKUP_CONTENT_TYPE_VIDEO`){let e=F(l.metadata)?l.metadata:null,n=e&&F(e.lockupMetadataViewModel)?e.lockupMetadataViewModel:null,r=L(l.contentId),i=Q(n?.title),a=n&&F(n.metadata)?n.metadata:null,o=a&&F(a.contentMetadataViewModel)?a.contentMetadataViewModel:null,s=(Array.isArray(o?.metadataRows)?o.metadataRows.filter(F):[])[0],c=Q((s&&Array.isArray(s.metadataParts)?s.metadataParts.filter(F):[]).find(e=>F(e.text))?.text)||`YouTube creator`,u=F(l.contentImage)?l.contentImage:null,d=u&&F(u.thumbnailViewModel)?u.thumbnailViewModel:null,f=d&&F(d.image)?d.image:null,p=0;q(d,e=>{p||!F(e.thumbnailBadgeViewModel)||(p=ve(Q(e.thumbnailBadgeViewModel.text)))}),/^[A-Za-z0-9_-]{11}$/.test(r)&&i&&t.push({externalId:r,title:i,artist:c,durationSec:p,imageUrl:Z(f)})}let u=F(e.pageHeaderRenderer)?e.pageHeaderRenderer:null;r||=Q(u?.pageTitle);let d=F(e.playlistHeaderRenderer)?e.playlistHeaderRenderer:null;r||=Q(d?.title),i||=Q(d?.descriptionText),a||=Q(d?.ownerText);let f=F(e.playlistMetadataRenderer)?e.playlistMetadataRenderer:null;r||=Q(f?.title),i||=Q(f?.description);let p=F(e.microformatDataRenderer)?e.microformatDataRenderer:null;r||=Q(p?.title),i||=Q(p?.description),o||=Z(p?.thumbnail);let m=F(e.videoOwnerRenderer)?e.videoOwnerRenderer:null;a||=Q(m?.title);let h=Q((F(e.avatarStackViewModel)?e.avatarStackViewModel:null)?.text).replace(/^by\s+/i,``);a||=h;let g=F(e.contentPreviewImageViewModel)?e.contentPreviewImageViewModel:null;o||=Z(g?.image);let _=F(e.playlistHeaderBanner)?e.playlistHeaderBanner:null,v=_&&F(_.heroPlaylistThumbnailRenderer)?_.heroPlaylistThumbnailRenderer:null;o||=Z(v?.thumbnail);let y=I((F(e.nextContinuationData)?e.nextContinuationData:null)?.continuation);y&&n.add(y);let b=I((F(e.continuationCommand)?e.continuationCommand:null)?.token);b&&n.add(b);let x=F(e.alertRenderer)?e.alertRenderer:null;x&&(!I(x.type)||I(x.type).toUpperCase()===`ERROR`)&&(s||=Q(x.text))}),{title:r,description:i,curator:a,imageUrl:o,items:t,continuations:[...n],alert:s}}function be(e){let t=F(e)&&F(e.streamingData)?e.streamingData:null;return[...Array.isArray(t?.adaptiveFormats)?t.adaptiveFormats:[],...Array.isArray(t?.formats)?t.formats:[]].filter(F).map(e=>{let t=Number(e.contentLength);return{audioQuality:I(e.audioQuality),bitrate:typeof e.bitrate==`number`&&Number.isFinite(e.bitrate)?e.bitrate:0,contentLength:Number.isFinite(t)&&t>0?t:null,mime:I(e.mimeType).split(`;`,1)[0].toLowerCase(),url:I(e.url)}}).filter(e=>!!e.url&&(!e.contentLength||e.contentLength<=j)&&(e.mime.startsWith(`audio/`)||e.mime===`video/mp4`&&!!e.audioQuality)).sort((e,t)=>{let n=e=>e.mime===`video/mp4`?50:e.mime===`audio/mp4`?40:e.mime===`audio/webm`?30:e.mime.startsWith(`audio/`)?20:10;return n(t)-n(e)||t.bitrate-e.bitrate})}async function xe(e){let{text:t}=await _(new URL(`/youtubei/v1/player?prettyPrint=false`,`https://www.youtube.com/`),`youtube`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":`com.google.android.youtube/20.10.38 (Linux; U; Android 15) gzip`,"x-youtube-client-name":`3`,"x-youtube-client-version":`20.10.38`},body:JSON.stringify({context:{client:{androidSdkVersion:35,clientName:`ANDROID`,clientVersion:`20.10.38`,gl:`US`,hl:`en`,utcOffsetMinutes:0}},contentCheckOk:!0,racyCheckOk:!0,videoId:e})}),n;try{n=JSON.parse(t)}catch{throw new x(`YouTube returned malformed player data.`)}if(!F(n))throw new x(`YouTube returned invalid player data.`);return n}async function Se(e,t){let n=new URL(`/youtubei/v1/browse?prettyPrint=false`,`https://www.youtube.com/`),r;try{({text:r}=await _(n,`youtube`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":`com.google.android.youtube/20.10.38 (Linux; U; Android 15) gzip`,"x-youtube-client-name":`3`,"x-youtube-client-version":`20.10.38`},body:JSON.stringify({context:{client:{androidSdkVersion:35,clientName:`ANDROID`,clientVersion:`20.10.38`,gl:`US`,hl:`en`,utcOffsetMinutes:0}},...t?{continuation:t}:{browseId:`VL${e}`}})}))}catch(e){throw e instanceof x&&/HTTP (?:403|404)\b/.test(e.message)?new x(`This YouTube playlist is private, deleted, or unavailable. Make it Public or Unlisted and try again.`,422):e}let i;try{i=JSON.parse(r)}catch{throw new x(`YouTube returned malformed playlist data.`)}if(!F(i))throw new x(`YouTube returned invalid playlist data.`);return i}async function Ce(e){let t=k(e);if(!t)throw new x(`Enter a direct YouTube playlist link.`,400);let n=new URL(`/playlist?list=${encodeURIComponent(t)}`,`https://www.youtube.com/`).toString(),r=[],i=new Set,a,o=``,s=``,c=``,l=null;for(let e=0;e<se;e+=1){let e=ye(await Se(t,a));if(e.alert)throw new x(`This YouTube playlist is private, deleted, or unavailable. Make it Public or Unlisted and try again.`,422);o||=e.title,s||=e.description,c||=e.curator,l||=e.imageUrl,r.push(...e.items);let n=e.continuations.find(e=>!i.has(e));if(r.length>N)throw new x(`YouTube playlists can contain at most ${N} importable videos.`,413);if(!n){a=void 0;break}if(r.length>=N)throw new x(`YouTube playlists can contain at most ${N} importable videos.`,413);i.add(n),a=n}if(a)throw new x(`The YouTube playlist returned too many continuation pages.`,413);if(!r.length)throw new x(`This YouTube playlist has no public, playable videos.`,422);return{externalId:t,sourceUrl:n,title:o||`Imported YouTube playlist`,description:s||`${r.length} videos imported from YouTube`,curator:c||`YouTube`,imageUrl:l||r[0]?.imageUrl||null,items:r}}async function we(e){let t=B(e),n=new URL(`/watch?v=${encodeURIComponent(t)}`,`https://www.youtube.com/`),{text:r}=await _(n,`youtube`,{headers:{accept:`text/html,application/xhtml+xml`,cookie:`CONSENT=YES+cb`,referer:`https://www.youtube.com/`}}),i=pe(r,`ytInitialPlayerResponse`),a=i,o=be(a);o.length||(a=await xe(t),o=be(a));let s=F(a)&&F(a.videoDetails)?a.videoDetails:F(i)&&F(i.videoDetails)?i.videoDetails:null,c=o[0];if(!s||!c)throw new x(`This YouTube video does not expose a direct public audio stream.`,422);let l=L(s.videoId);if(l!==t)throw new x(`YouTube returned player data for a different video.`,422);let u=F(s.thumbnail)?s.thumbnail:null;return{provider:`youtube`,externalId:l,sourceUrl:n.toString(),title:I(s.title)||X(r,`og:title`)||`YouTube audio`,artist:I(s.author,`YouTube creator`),album:`Imported from YouTube`,durationSec:Y(s.lengthSeconds),imageUrl:Z(u)||X(r,`og:image`)||null,streamUrl:G(c.url)}}async function Te(e,t){switch(e){case`zing-mp3`:return ue(t);case`nhac-cua-tui`:return fe(t);case`tiktok`:return _e(t);case`youtube`:return we(t)}}function Ee(e,t){try{switch(t){case`zing-mp3`:H(e.toString());break;case`nhac-cua-tui`:U(e.toString());break;case`tiktok`:W(e.toString());break;case`youtube`:G(e.toString());break;default:return!1}return!0}catch{return!1}}function De(e,t){let n=e.hostname.toLowerCase(),r=/^(rr\d+---)(sn-[a-z0-9-]+)(\.googlevideo\.com)$/.exec(n);if(!r)return null;for(let i of(e.searchParams.get(`mn`)??``).split(`,`)){if(!/^sn-[a-z0-9-]+$/.test(i))continue;let a=`${r[1]}${i}${r[3]}`;if(a===n||t.has(a))continue;let o=new URL(e);return o.hostname=a,o}return null}async function Oe(e,t){let n=new URL(e),r=new Set;for(let e=0;e<=5;e+=1){if(!Ee(n,t))throw new x(`The media host redirected to an unsupported address.`);let e;try{e=await fetch(n,{redirect:`manual`,signal:AbortSignal.timeout(6e4),headers:{accept:`audio/mpeg,audio/*;q=0.9,video/mp4;q=0.6,*/*;q=0.1`,"accept-encoding":`identity`,referer:{"zing-mp3":`https://zingmp3.vn/`,"nhac-cua-tui":`https://www.nhaccuatui.com/`,tiktok:`https://www.tiktok.com/`,youtube:`https://www.youtube.com/`}[t],"user-agent":t===`youtube`?`com.google.android.youtube/20.10.38 (Linux; U; Android 15) gzip`:`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 Chrome/140.0.0.0 Safari/537.36`}})}catch{r.add(n.hostname.toLowerCase());let e=t===`youtube`?De(n,r):null;if(e){n=e;continue}throw new x(`The provider media host could not be reached.`)}if([301,302,303,307,308].includes(e.status)){let t=e.headers.get(`location`);if(await e.body?.cancel().catch(()=>void 0),!t)throw new x(`The audio host returned an invalid redirect.`);try{n=new URL(t,n)}catch{throw new x(`The audio host returned an invalid redirect.`)}continue}if(!e.ok)throw await e.body?.cancel().catch(()=>void 0),new x(`The audio host returned HTTP ${e.status}.`);return e}throw new x(`The audio host redirected too many times.`)}var ke=new Set([`application/octet-stream`,`audio/aac`,`audio/mp3`,`audio/mp4`,`audio/mpeg`,`audio/ogg`,`audio/webm`,`audio/x-m4a`,`video/mp4`,`video/webm`]);function Ae(e){return e===`audio/mp3`?`audio/mpeg`:e===`audio/x-m4a`?`audio/mp4`:e}function je(e,t){let n=t===`audio/mpeg`||t===`audio/mp3`?`mp3`:t===`audio/aac`?`aac`:t===`audio/mp4`||t===`audio/x-m4a`?`m4a`:t===`video/mp4`?`mp4`:t.endsWith(`/webm`)?`webm`:t===`audio/ogg`?`ogg`:`media`;return`${w(`sha256`).update(e).digest(`hex`)}.${n}`}function Me(e){let t=w(`sha256`).update(e).digest(`hex`).slice(0,24);return C.join(m,t)}function Ne(e,t){if(t<0||t+3>=e.length)return!1;let n=e[t+1],r=e[t+2];return e[t]===255&&(n&224)==224&&(n>>3&3)!=1&&(n>>1&3)!=0&&(r>>4&15)!=0&&(r>>4&15)!=15&&(r>>2&3)!=3}function Pe(e){if(e.length<10||e[0]!==73||e[1]!==68||e[2]!==51||e[3]<2||e[3]>4||e.slice(6,10).some(e=>(e&128)!=0))return-1;let t=e[6]<<21|e[7]<<14|e[8]<<7|e[9],n=e[3]===4&&(e[5]&16)!=0;return 10+t+(n?10:0)}function Fe(e){if(e.length<7)return!1;let t=e[2]>>2&15,n=(e[3]&3)<<11|e[4]<<3|e[5]>>5&7;return e[0]===255&&(e[1]&246)==240&&t!==15&&n>=7}function Ie(e){let t=Pe(e);return Ne(e,0)||t>=0&&Ne(e,t)?`audio/mpeg`:Fe(e)?`audio/aac`:e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83?`audio/ogg`:e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163?`audio/webm`:e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112?`audio/mp4`:``}function Le(e,t,n){if(!n)return null;if(!t||t===`application/octet-stream`)return n;let r=Ae(t);return r===n||r===`video/mp4`&&n===`audio/mp4`||r===`video/webm`&&n===`audio/webm`?r:e===`tiktok`&&r===`video/mp4`&&n===`audio/mpeg`||r===`audio/aac`&&n===`audio/mpeg`?n:null}async function Re(e,t,n,o,s){let c=null,l=null,u=null;try{if(!r(e,{status:`fetching`,error:null},s))throw Error(`The download job is no longer available.`);let d=o??await Te(n,t);if(c=i({id:`${n}:${d.externalId}`,provider:n,externalId:d.externalId,sourceUrl:d.sourceUrl,title:d.title,artist:d.artist,album:d.album,durationSec:d.durationSec,imageUrl:d.imageUrl},s).id,!r(e,{trackId:c,status:`downloading`},s))throw Error(`The download job is no longer available.`);a(c,s);let p=await Oe(d.streamUrl,n);if(!p.body)throw new x(`The audio host returned an empty response.`);let m=p.headers.get(`content-type`)?.split(`;`,1)[0].trim().toLowerCase()??``;if(m&&!ke.has(m))throw await p.body.cancel().catch(()=>void 0),new x(`The provider returned unsupported media type ${m}.`);let h=Number(p.headers.get(`content-length`)),g=Number.isFinite(h)&&h>0?h:null;if(g&&g>j)throw await p.body.cancel().catch(()=>void 0),new x(`The audio file exceeds the 100 MB limit.`,413);let _=`${w(`sha256`).update(c).digest(`hex`)}.${e}.part`,v=Me(s);await ee(v,{recursive:!0}),l=C.join(v,_),await E(l,{force:!0});let y=await te(l,`w`),b=0,S=0,T=-1,D=[];try{let t=p.body.getReader();for(;;){let{done:n,value:i}=await t.read();if(n)break;if(b+i.byteLength>j)throw await t.cancel(),new x(`The audio file exceeds the 100 MB limit.`,413);D.length<M&&D.push(...i.subarray(0,M-D.length));let a=0;for(;a<i.byteLength;){let{bytesWritten:e}=await y.write(i,a,i.byteLength-a,null);if(e<=0)throw Error(`The local audio file could not be written.`);a+=e}b+=i.byteLength;let o=g?Math.min(99,Math.floor(b/g*100)):0,c=Date.now();if(o!==T||c-S>=ae){if(!r(e,{status:`downloading`,progress:o,bytesDownloaded:b,totalBytes:g},s))throw Error(`The download job is no longer available.`);T=o,S=c}}await y.sync()}finally{await y.close()}if(b===0)throw new x(`The audio host returned an empty file.`);if(g!==null&&b!==g)throw new x(`The audio download ended before the complete file was received.`);let O=Le(n,m,Ie(D));if(!O)throw new x(`The provider response is not a valid supported audio or video file.`);let k=C.join(v,je(c,O));if(await ne(l,k),l=null,u=k,f(c,k,O,b,s),!r(e,{status:`completed`,progress:100,bytesDownloaded:b,totalBytes:g??b,error:null},s))throw Error(`The completed download job could not be updated.`);u=null}catch(t){if(l&&await E(l,{force:!0}).catch(()=>void 0),u&&await E(u,{force:!0}).catch(()=>void 0),c)try{d(c,s)}catch{}try{r(e,{status:`failed`,error:b(t)},s)}catch{}}}async function $(e,n){n??=t().id;let{provider:r,url:i}=y(e),a,d,f,m=null;try{switch(r){case`zing-mp3`:d=R(i),a=new URL(`/link/song/${encodeURIComponent(d)}`,`https://zingmp3.vn/`).toString();break;case`nhac-cua-tui`:d=z(i),a=new URL(`/song/${encodeURIComponent(d)}`,`https://www.nhaccuatui.com/`).toString();break;case`tiktok`:m=ce(),f=await _e(i),d=f.externalId,a=f.sourceUrl;break;case`youtube`:d=B(i),a=new URL(`/watch?v=${encodeURIComponent(d)}`,`https://www.youtube.com/`).toString();break}let e=p(a,n);if(e)return e;let t=h(r,d,n)??s(a,n);if(t){let e=o(t.track.id,n);if(e)return e}if(t?.status===`completed`&&t.audioPath)try{let e=await D(t.audioPath);if(e.isFile()&&e.size>0)return u(t.track.id,n)||l(T(),a,r,`completed`,t.track.id,e.size,n)}catch{}m??=ce();let g;try{g=l(T(),a,r,`queued`,null,0,n)}catch(e){let t=p(a,n);if(t)return t;throw e}let _=m;return m=null,Re(g.id,i,r,f,n).finally(_).catch(()=>void 0),c(g.id,n)??g}finally{m?.()}}async function ze(e,t){for(let n=0;n<2400;n+=1){let n=c(e,t);if(!n||n.status===`completed`||n.status===`failed`)return;await new Promise(e=>setTimeout(e,500))}}async function Be(e,t){let n=`youtube:${e.externalId}`,r=new URL(`/watch?v=${encodeURIComponent(e.externalId)}`,`https://www.youtube.com/`).toString();for(let e=0;e<2400;e+=1)try{await ze((await $(r,t)).id,t);return}catch(e){if(e instanceof x&&e.status===429){await new Promise(e=>setTimeout(e,500));continue}d(n,t);return}d(n,t)}function Ve(e,t,n){let r=P.spotifyPlaylistImportTokens??new Set;P.spotifyPlaylistImportTokens=r;let i=`${n??`active`}:${e.id}`;if(r.has(i))return;r.add(i);let a=0,o=async()=>{for(;a<t.length;){let e=t[a];a+=1,await Be(e,n)}};Promise.all([o(),o()]).finally(()=>r.delete(i)).catch(()=>void 0)}async function He(e,t){let n=await Ce(e),r=g({id:`youtube-playlist:${n.externalId}`,provider:`youtube`,externalId:n.externalId,sourceUrl:n.sourceUrl,title:n.title,description:n.description,curator:n.curator,imageUrl:n.imageUrl,tracks:n.items.map(e=>({id:`youtube:${e.externalId}`,provider:`youtube`,externalId:e.externalId,sourceUrl:new URL(`/watch?v=${encodeURIComponent(e.externalId)}`,`https://www.youtube.com/`).toString(),title:e.title,artist:e.artist,album:n.title,durationSec:e.durationSec,imageUrl:e.imageUrl}))},t);return Ve(r,n.items,t),r}async function Ue(e,n){n??=t().id;let{provider:r,url:i}=y(e);return r===`youtube`&&k(i)?{playlist:await He(i,n)}:{download:await $(e,n)}}var We=`nodejs`,Ge=`force-dynamic`;async function Ke(t){try{v(t,{json:!0});let r;try{r=await t.json()}catch{return e.json({error:`Send a JSON object containing a music URL.`},{status:400})}let i=r&&typeof r==`object`&&`url`in r?r.url:null;if(typeof i!=`string`||!i.trim())return e.json({error:`Enter a music link.`},{status:400});if(i.length>2048)return e.json({error:`The music link is too long.`},{status:400});let a=await Ue(i,n(t,r&&typeof r==`object`&&`profileId`in r?r.profileId:void 0));return e.json(a,{status:`playlist`in a||a.download.status!==`completed`?202:200,headers:{"cache-control":`no-store`}})}catch(t){return e.json({error:b(t)},{status:t instanceof x?t.status:500,headers:{"cache-control":`no-store`}})}}export{Ke as POST,Ge as dynamic,We as runtime};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{n as t,r as n,t as r}from"./input-platform-C0756QEt.js";import{execFile as i,spawn as a}from"node:child_process";import{createInterface as o}from"node:readline";var s={Escape:53,F1:122,F2:120,F3:99,F4:118,F5:96,F6:97,F7:98,F8:100,F9:101,F10:109,F11:103,F12:111,Delete:117,Home:115,End:119,PageUp:116,PageDown:121,Insert:114,ArrowUp:126,ArrowDown:125,ArrowLeft:123,ArrowRight:124,Backspace:51,Tab:48,Enter:36,NumpadEnter:76,Space:49,CapsLock:57,NumLock:71,NumpadDivide:75,NumpadMultiply:67,NumpadSubtract:78,NumpadAdd:69,NumpadDecimal:65,Numpad0:82,Numpad1:83,Numpad2:84,Numpad3:85,Numpad4:86,Numpad5:87,Numpad6:88,Numpad7:89,Numpad8:91,Numpad9:92,PrintScreen:105,ScrollLock:107,Pause:113,ContextMenu:110},c={Escape:{virtualKey:27},F1:{virtualKey:112},F2:{virtualKey:113},F3:{virtualKey:114},F4:{virtualKey:115},F5:{virtualKey:116},F6:{virtualKey:117},F7:{virtualKey:118},F8:{virtualKey:119},F9:{virtualKey:120},F10:{virtualKey:121},F11:{virtualKey:122},F12:{virtualKey:123},PrintScreen:{virtualKey:44,extended:!0},ScrollLock:{virtualKey:145},Pause:{virtualKey:19},Backquote:{virtualKey:192},Digit0:{virtualKey:48},Digit1:{virtualKey:49},Digit2:{virtualKey:50},Digit3:{virtualKey:51},Digit4:{virtualKey:52},Digit5:{virtualKey:53},Digit6:{virtualKey:54},Digit7:{virtualKey:55},Digit8:{virtualKey:56},Digit9:{virtualKey:57},Minus:{virtualKey:189},Equal:{virtualKey:187},Backspace:{virtualKey:8},Tab:{virtualKey:9},KeyA:{virtualKey:65},KeyB:{virtualKey:66},KeyC:{virtualKey:67},KeyD:{virtualKey:68},KeyE:{virtualKey:69},KeyF:{virtualKey:70},KeyG:{virtualKey:71},KeyH:{virtualKey:72},KeyI:{virtualKey:73},KeyJ:{virtualKey:74},KeyK:{virtualKey:75},KeyL:{virtualKey:76},KeyM:{virtualKey:77},KeyN:{virtualKey:78},KeyO:{virtualKey:79},KeyP:{virtualKey:80},KeyQ:{virtualKey:81},KeyR:{virtualKey:82},KeyS:{virtualKey:83},KeyT:{virtualKey:84},KeyU:{virtualKey:85},KeyV:{virtualKey:86},KeyW:{virtualKey:87},KeyX:{virtualKey:88},KeyY:{virtualKey:89},KeyZ:{virtualKey:90},BracketLeft:{virtualKey:219},BracketRight:{virtualKey:221},Backslash:{virtualKey:220},CapsLock:{virtualKey:20},Semicolon:{virtualKey:186},Quote:{virtualKey:222},Enter:{virtualKey:13},Comma:{virtualKey:188},Period:{virtualKey:190},Slash:{virtualKey:191},Space:{virtualKey:32},ContextMenu:{virtualKey:93,extended:!0},Insert:{virtualKey:45,extended:!0},Home:{virtualKey:36,extended:!0},PageUp:{virtualKey:33,extended:!0},Delete:{virtualKey:46,extended:!0},End:{virtualKey:35,extended:!0},PageDown:{virtualKey:34,extended:!0},ArrowUp:{virtualKey:38,extended:!0},ArrowDown:{virtualKey:40,extended:!0},ArrowLeft:{virtualKey:37,extended:!0},ArrowRight:{virtualKey:39,extended:!0},NumLock:{virtualKey:144,extended:!0},NumpadDivide:{virtualKey:111,extended:!0},NumpadMultiply:{virtualKey:106},NumpadSubtract:{virtualKey:109},NumpadAdd:{virtualKey:107},NumpadDecimal:{virtualKey:110},Numpad0:{virtualKey:96},Numpad1:{virtualKey:97},Numpad2:{virtualKey:98},Numpad3:{virtualKey:99},Numpad4:{virtualKey:100},Numpad5:{virtualKey:101},Numpad6:{virtualKey:102},Numpad7:{virtualKey:103},Numpad8:{virtualKey:104},Numpad9:{virtualKey:105},NumpadEnter:{virtualKey:13,extended:!0}},l={ShiftLeft:{virtualKey:160},ShiftRight:{virtualKey:161},ControlLeft:{virtualKey:162},ControlRight:{virtualKey:163,extended:!0},AltLeft:{virtualKey:164},AltRight:{virtualKey:165,extended:!0},MetaLeft:{virtualKey:91,extended:!0}},u=String.raw`
|
|
2
2
|
$source = @'
|
|
3
3
|
using System;
|
|
4
4
|
using System.Runtime.InteropServices;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./server-
|
|
1
|
+
import{n as e}from"./server-DwVU6UyP.js";import{n as t}from"./downloader-0G-gq1D-.js";import{createReadStream as n,statSync as r}from"node:fs";import{Readable as i}from"node:stream";var a=`nodejs`,o=`force-dynamic`,s={".m3u8":`application/vnd.apple.mpegurl`,".ts":`video/mp2t`,".mp4":`video/mp4`,".webm":`video/webm`,".mkv":`video/x-matroska`,".vtt":`text/vtt; charset=utf-8`};function c(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}async function l(a,o){let l=await o.params,u=l.path.join(`/`),d=t(l.id,u);if(!d)return e.json({error:`Media not found.`},{status:404});let f=r(d),p=s[c(d)]||`application/octet-stream`,m=a.headers.get(`range`);if(m&&!d.endsWith(`.m3u8`)){let e=m.match(/bytes=(\d+)-(\d*)/);if(!e)return new Response(null,{status:416});let t=Number(e[1]),r=e[2]?Math.min(Number(e[2]),f.size-1):f.size-1,a=n(d,{start:t,end:r});return new Response(i.toWeb(a),{status:206,headers:{"accept-ranges":`bytes`,"content-length":String(r-t+1),"content-range":`bytes ${t}-${r}/${f.size}`,"content-type":p,"cache-control":`private, max-age=86400`}})}let h=n(d);return new Response(i.toWeb(h),{headers:{"accept-ranges":`bytes`,"content-length":String(f.size),"content-type":p,"cache-control":d.endsWith(`.m3u8`)?`no-store`:`private, max-age=86400`}})}export{l as GET,o as dynamic,a as runtime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./instrumentation-BV3gg-L-.js";import{C as t,O as n,S as r,k as i,x as a}from"../../index.js";import{buildAppPageCacheTags as o}from"./app-page-cache-
|
|
1
|
+
import{n as e}from"./instrumentation-BV3gg-L-.js";import{C as t,O as n,S as r,k as i,x as a}from"../../index.js";import{buildAppPageCacheTags as o}from"./app-page-cache-CQaSjBaF.js";import s from"node:fs";function c(e){if(!s.existsSync(e))return null;try{return JSON.parse(s.readFileSync(e,`utf-8`))}catch(t){return console.warn(`[vinext] Failed to read prerender manifest at ${e}:`,t),null}}function l(e){return e.filter(e=>e.status===`rendered`&&e.router===`app`)}function u(e,t){return t?.fallback===!0?!0:t?.fallback===void 0?e.includes(`[`)||e.includes(`]`):!1}function d(e,t){if(e===`/`)return`index.html`;let n=e.replace(/^\//,``);return t?`${n}/index.html`:`${n}.html`}function f(e){return e===`/`?`index.rsc`:e.replace(/^\//,``)+`.rsc`}async function p(i,s){r();let d=c(e.join(i,`vinext-prerender.json`));if(!d)return 0;let{buildId:f,routes:p}=d;if(!f||!Array.isArray(p))return 0;let _=d.trailingSlash??!1,v=e.join(i,`prerendered-routes`),y=s?.writeAppPageEntry??m(),b=0,x=l(p);for(let e of x){let r=e.path??e.route;u(r,e)||a(e.route,r);let i=e.path??e.route,c=t(i),l=n(`app`,c,f),d=s?.buildAppPageHtmlKey?.(c)??l+`:html`,p=s?.buildAppPageRscKey?.(c)??l+`:rsc`,m=typeof e.revalidate==`number`?e.revalidate:void 0,x=typeof e.expire==`number`?e.expire:void 0,S=o(c,e.tags??[]);await h(y,v,d,i,_,e.headers,m,x,S)&&(await g(y,v,p,i,m,x,S),b++)}return b}function m(){return(e,t,n)=>i(e,t,n)}async function h(t,n,r,i,a,o,c,l,u){let f=d(i,a),p=e.join(n,f);return s.existsSync(p)?(await t(r,{kind:`APP_PAGE`,html:s.readFileSync(p,`utf-8`),rscData:void 0,headers:o,postponed:void 0,status:void 0},{expireSeconds:l,revalidateSeconds:c,tags:u}),!0):!1}async function g(t,n,r,i,a,o,c){let l=f(i),u=e.join(n,l);if(!s.existsSync(u))return;let d=s.readFileSync(u);await t(r,{kind:`APP_PAGE`,html:``,rscData:d.buffer.slice(d.byteOffset,d.byteOffset+d.byteLength),headers:void 0,postponed:void 0,status:void 0},{expireSeconds:o,revalidateSeconds:a,tags:c})}export{p as seedMemoryCacheFromPrerender};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./unified-request-context-CgIMz2dD.js";import{A as e,M as t,j as n,o as r,r as i,s as a}from"./request-context-C1ZJzkex.js";import{i as o,n as s}from"./base-path-Cmiu3HvG.js";var c=[`authorization`,`cookie`];function l(e,t){if(e instanceof Headers)return e.get(t);let n=e[t];return n===void 0?null:Array.isArray(n)?n[0]??null:n}function u(t){let n=l(t,e);return n===null?null:n.split(`,`).map(e=>e.trim()).filter(Boolean)}function d(e){let t=new Map;if(e instanceof Headers){for(let[r,i]of e.entries())r.startsWith(`x-middleware-request-`)&&t.set(r.slice(n.length),i);return t}for(let[r,i]of Object.entries(e)){if(!r.startsWith(`x-middleware-request-`))continue;let e=Array.isArray(i)?i[0]??``:i;t.set(r.slice(n.length),e)}return t}function f(e){let t=new Headers;for(let[n,r]of e.entries())t.append(n,r);return t}function p(t,r){let i=[...r.keys()];t.set(e,i.join(`,`));for(let[e,i]of r.entries())t.set(`${n}${e}`,i)}function m(e,t,n={}){let r=u(t),i=d(t);if(r===null&&i.size===0)return null;let a=r===null?f(e):new Headers;if(r===null){for(let[e,t]of i)a.set(e,t);return a}if(n.preserveCredentialHeaders){let t=new Set(r);for(let n of c){if(t.has(n))continue;let r=e.get(n);r!==null&&a.set(n,r)}}for(let e of r){let t=i.get(e);t!==void 0&&a.set(e,t)}return a}var h=/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/;function g(e){if(!e||!h.test(e))throw Error(`Invalid cookie name: ${JSON.stringify(e)}`)}function _(e,t){for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r<=31||r===127||e[n]===`;`)throw Error(`Invalid cookie ${t} value: ${JSON.stringify(e)}`)}}var v=`[\\u0000-\\u001F \\u200B\\uFEFF]*`,y=`[\\r\\n\\t]*`;function b(e){let t=e.split(``).join(y);return RegExp(`^${v}${t}${y}:`,`i`)}var x=[b(`javascript`),b(`data`),b(`vbscript`)],S=`Next.js has blocked a javascript: URL as a security precaution.`;function C(e){let t=``+e;return x.some(e=>e.test(t))}function w(){console.error(S)}function T(e,t=Error){if(C(e))throw w(),new t(S)}var E=class extends Request{_nextUrl;_url;_cookies;constructor(e,t){O(typeof e!=`string`&&`url`in e?e.url:String(e));let{nextConfig:n,...r}=t??{};if(e instanceof Request){let t=r.body===void 0&&e.body&&!e.bodyUsed?e.clone():e;super(t,r);let n=Reflect.get(e,`cf`);n!==void 0&&Object.defineProperty(this,"cf",{value:n,enumerable:!0,configurable:!0})}else super(e,r);let i=typeof e==`string`?new URL(e,`http://localhost`):e instanceof URL?e:new URL(e.url,`http://localhost`),a=n?.i18n?{locales:[...n.i18n.locales],defaultLocale:n.i18n.defaultLocale,domains:n.i18n.domains?.map(e=>({...e,locales:e.locales?[...e.locales]:void 0}))}:void 0,o=n?{basePath:n.basePath,nextConfig:{i18n:a,trailingSlash:n.trailingSlash}}:void 0;this._nextUrl=new A(i,void 0,o),this._url=process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE?i.toString():this._nextUrl.toString(),this._cookies=new j(this.headers)}get nextUrl(){return this._nextUrl}get url(){return this._url}get cookies(){return this._cookies}get page(){throw Error(`NextRequest.page has been removed; use URLPattern instead`)}get ua(){throw Error(`NextRequest.ua has been removed; use userAgent() instead`)}get ip(){return this.headers.get(`cf-connecting-ip`)??this.headers.get(`x-real-ip`)??this.headers.get(`x-forwarded-for`)?.split(`,`)[0]?.trim()??void 0}get geo(){let e=this.headers.get(`cf-ipcountry`)??this.headers.get(`x-vercel-ip-country`)??void 0;if(e)return{country:e,city:this.headers.get(`cf-ipcity`)??this.headers.get(`x-vercel-ip-city`)??void 0,region:this.headers.get(`cf-region`)??this.headers.get(`x-vercel-ip-country-region`)??void 0,latitude:this.headers.get(`cf-iplatitude`)??this.headers.get(`x-vercel-ip-latitude`)??void 0,longitude:this.headers.get(`cf-iplongitude`)??this.headers.get(`x-vercel-ip-longitude`)??void 0}}get buildId(){return this._nextUrl.buildId}},D=new Set([301,302,303,307,308]);function O(e){T(String(e));try{return String(new URL(String(e)))}catch(t){throw Error(`URL is malformed "${String(e)}". Please use only absolute URLs - https://nextjs.org/docs/messages/middleware-relative-urls`,{cause:t})}}var k=class e extends Response{_cookies;constructor(e,t){super(e,t),this._cookies=new R(this.headers)}get cookies(){return this._cookies}static json(t,n){let r=Response.json(t,n);return new e(r.body,r)}static redirect(t,n){let r=typeof n==`number`?n:n?.status??307;if(!D.has(r))throw RangeError(`Failed to execute "redirect" on "response": Invalid status code`);let i=new Headers(typeof n==`object`?n?.headers:void 0);return i.set(`Location`,O(t)),new e(null,{status:r,headers:i})}static rewrite(t,n){let r=new Headers(n?.headers);return r.set(a,O(t)),n?.request?.headers&&p(r,n.request.headers),new e(null,{...n,headers:r})}static next(t){let n=new Headers(t?.headers);return n.set(r,`1`),t?.request?.headers&&p(n,t.request.headers),new e(null,{...t,headers:n})}},A=class e{_url;_configBasePath;_basePath;_trailingSlash;_locale;_configDefaultLocale;_defaultLocale;_locales;_domains;_domainLocale;constructor(e,t,n){this._url=new URL(e.toString(),t),this._configBasePath=n?.basePath??``,this._basePath=this._configBasePath,this._trailingSlash=n?.nextConfig?.trailingSlash??!1,this._stripBasePath();let r=n?.nextConfig?.i18n;r&&(this._locales=[...r.locales],this._domains=r.domains?.map(e=>({...e,locales:e.locales?[...e.locales]:void 0})),this._configDefaultLocale=r.defaultLocale,this._analyzeI18n())}_stripBasePath(){if(this._configBasePath){if(!s(this._url.pathname,this._configBasePath)){this._basePath=``;return}this._basePath=this._configBasePath,this._url.pathname=o(this._url.pathname,this._configBasePath)}}_detectPathnameLocale(e){let t=this._url.pathname.split(`/`),n=t[1]?.toLowerCase(),r=e.find(e=>e.toLowerCase()===n);return r&&(this._url.pathname=`/`+t.slice(2).join(`/`)),r}_analyzeI18n(){if(!this._locales||!this._configDefaultLocale)return;let e=this._detectPathnameLocale(this._locales),t=e?.toLowerCase(),n=this._url.hostname.toLowerCase();this._domainLocale=this._domains?.find(e=>e.domain.split(`:`,1)[0].toLowerCase()===n||t===e.defaultLocale.toLowerCase()||e.locales?.some(e=>e.toLowerCase()===t)),this._defaultLocale=this._domainLocale?.defaultLocale??this._configDefaultLocale,this._locale=e??this._defaultLocale}_formatPathname(){let e=this._basePath,t=this._url.pathname,n=t.toLowerCase();!(n===`/api`||n.startsWith(`/api/`))&&this._locale&&this._locale!==this._defaultLocale&&(e+=`/`+this._locale);let r=e?t===`/`?e:e+t:t;return this._applyTrailingSlash(r)}_applyTrailingSlash(e){return e===``||e===`/`?e:this._trailingSlash?e.endsWith(`/`)?e:e+`/`:e.endsWith(`/`)?e.slice(0,-1):e}get href(){let e=this._formatPathname();if(e===this._url.pathname)return this._url.href;let{href:t,pathname:n,search:r,hash:i}=this._url,a=t.length-n.length-r.length-i.length;return t.slice(0,a)+e+r+i}set href(e){this._url.href=e,this._stripBasePath(),this._analyzeI18n()}get origin(){return this._url.origin}get protocol(){return this._url.protocol}set protocol(e){this._url.protocol=e}get username(){return this._url.username}set username(e){this._url.username=e}get password(){return this._url.password}set password(e){this._url.password=e}get host(){return this._url.host}set host(e){this._url.host=e}get hostname(){return this._url.hostname}set hostname(e){this._url.hostname=e}get port(){return this._url.port}set port(e){this._url.port=e}get pathname(){return this._url.pathname}set pathname(e){this._url.pathname=e}get search(){return this._url.search}set search(e){this._url.search=e}get searchParams(){return this._url.searchParams}get hash(){return this._url.hash}set hash(e){this._url.hash=e}get basePath(){return this._basePath}set basePath(e){this._basePath=e===``?``:e.startsWith(`/`)?e:`/`+e}get locale(){return this._locale??``}set locale(e){if(this._locales){if(!e){this._locale=this._defaultLocale;return}if(!this._locales.includes(e))throw TypeError(`The locale "${e}" is not in the configured locales: ${this._locales.join(`, `)}`)}this._locale=this._locales?e:this._locale}get defaultLocale(){return this._defaultLocale}get domainLocale(){if(this._domainLocale)return{...this._domainLocale,locales:this._domainLocale.locales?[...this._domainLocale.locales]:void 0}}get locales(){return this._locales?[...this._locales]:void 0}clone(){let t={};this._locales&&(t.i18n={locales:[...this._locales],defaultLocale:this._configDefaultLocale,domains:this._domains?.map(e=>({...e,locales:e.locales?[...e.locales]:void 0}))}),this._trailingSlash&&(t.trailingSlash=!0);let n={basePath:this._configBasePath,nextConfig:Object.keys(t).length>0?t:void 0};return new e(this.href,void 0,n)}toString(){return this.href}toJSON(){return this.href}get buildId(){return`e1ce9af7-d770-43d6-845a-511443f19971`}},j=class{_headers;_parsed;constructor(e){this._headers=e,this._parsed=i(e.get(`cookie`)??``)}get(e){let t=this._parsed.get(e);return t===void 0?void 0:{name:e,value:t}}getAll(e){let t=typeof e==`string`?e:e?.name;return[...this._parsed.entries()].filter(([e])=>t===void 0||e===t).map(([e,t])=>({name:e,value:t}))}has(e){return this._parsed.has(e)}set(e,t){let n,r;return typeof e==`string`?(n=e,r=t??``):(n=e.name,r=e.value),g(n),this._parsed.set(n,r),this._syncHeader(),this}delete(e){if(Array.isArray(e)){let t=e.map(e=>(g(e),this._parsed.delete(e)));return this._syncHeader(),t}g(e);let t=this._parsed.delete(e);return this._syncHeader(),t}clear(){return this._parsed.clear(),this._syncHeader(),this}get size(){return this._parsed.size}toString(){return this._serialize()}_serialize(){return[...this._parsed.entries()].map(([e,t])=>`${e}=${encodeURIComponent(t)}`).join(`; `)}_syncHeader(){this._parsed.size===0?this._headers.delete(`cookie`):this._headers.set(`cookie`,this._serialize())}[Symbol.iterator](){return new Map(this.getAll().map(e=>[e.name,e])).entries()}},M=class e extends Error{constructor(){super(`Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#options`)}static callable(){throw new e}},N=new Set([`set`,`delete`,`append`]),P=class e extends Error{constructor(){super(`Headers cannot be modified. Read more: https://nextjs.org/docs/app/api-reference/functions/headers`)}static callable(){throw new e}};function F(e){return new Proxy(e,{get(e,t){if(typeof t==`string`&&N.has(t))return P.callable;let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}})}function I(e){return new Proxy(e,{get(e,t){if(t===`set`||t===`delete`||t===`clear`)return M.callable;let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}})}var L=class{_headers;_parsed=new Map;constructor(e){this._headers=e;let t=e.getSetCookie?.()??e.get(`set-cookie`)??[],n=Array.isArray(t)?t:q(t);for(let e of n){let t=B(e);t&&this._parsed.set(t.name,t)}}set(...e){let[t,n,r]=J(e);g(t);let i=z(t,n,r);return G(i),this._parsed.set(t,i),this._syncHeaders(),this}get(...e){let t=typeof e[0]==`string`?e[0]:e[0].name;return this._parsed.get(t)}has(e){return this._parsed.has(e)}getAll(...e){let t=[...this._parsed.values()];if(e.length===0)return t;let n=typeof e[0]==`string`?e[0]:e[0].name;return t.filter(e=>e.name===n)}delete(...e){let[t,n]=typeof e[0]==`string`?[e[0],void 0]:[e[0].name,e[0]];return this.set({...n,name:t,value:``,expires:new Date(0)})}[Symbol.iterator](){return new Map([...this._parsed.values()].map(e=>[e.name,e])).entries()}toString(){return[...this._parsed.values()].map(K).join(`; `)}_syncHeaders(){this._headers.delete(`Set-Cookie`);for(let e of this._parsed.values())this._headers.append(`Set-Cookie`,K(e))}},R=class extends L{_responseHeaders;constructor(e){super(e),this._responseHeaders=e}set(...e){return super.set(...e),this._syncMiddlewareCookieHeader(),this}delete(...e){return super.delete(...e),this._syncMiddlewareCookieHeader(),this}_syncMiddlewareCookieHeader(){let e=this._responseHeaders.getSetCookie();if(e.length===0){this._responseHeaders.delete(t);return}this._responseHeaders.set(t,e.join(`,`))}};function z(e,t,n){let r={name:e,value:t,...n};return typeof r.expires==`number`&&(r.expires=new Date(r.expires)),r.maxAge&&(r.expires=new Date(Date.now()+r.maxAge*1e3)),r.path??=`/`,r}function B(e){if(!e)return;let[[t,n],...r]=V(e),{domain:i,expires:a,httponly:o,maxage:s,path:c,samesite:l,secure:u,partitioned:d,priority:f}=Object.fromEntries(r.map(([e,t])=>[e.toLowerCase().replaceAll(`-`,``),t]));return H({name:t,value:decodeURIComponent(n),domain:i,...a&&{expires:new Date(a)},...o&&{httpOnly:!0},...typeof s==`string`&&{maxAge:Number(s)},path:c,...l&&{sameSite:U(l)},...u&&{secure:!0},...f&&{priority:W(f)},...d&&{partitioned:!0}})}function V(e){let t=new Map;for(let n of e.split(/; */)){if(!n)continue;let e=n.indexOf(`=`);if(e===-1){t.set(n,`true`);continue}let r=n.slice(0,e),i=n.slice(e+1);try{t.set(r,decodeURIComponent(i??`true`))}catch{}}return t}function H(e){let t={};for(let n in e)e[n]&&(t[n]=e[n]);return t}function U(e){let t=e.toLowerCase();return t===`strict`||t===`lax`||t===`none`?t:void 0}function W(e){let t=e.toLowerCase();return t===`low`||t===`medium`||t===`high`?t:void 0}function G(e){e.path&&_(e.path,`Path`),e.domain&&_(e.domain,`Domain`)}function K(e){let t=[e.path&&`Path=${e.path}`,(e.expires||e.expires===0)&&`Expires=${(typeof e.expires==`number`?new Date(e.expires):e.expires).toUTCString()}`,typeof e.maxAge==`number`&&`Max-Age=${e.maxAge}`,e.domain&&`Domain=${e.domain}`,e.secure&&`Secure`,e.httpOnly&&`HttpOnly`,e.sameSite&&`SameSite=${e.sameSite}`,e.partitioned&&`Partitioned`,e.priority&&`Priority=${e.priority}`].filter(Boolean),n=`${e.name}=${encodeURIComponent(e.value??``)}`;return t.length===0?n:`${n}; ${t.join(`; `)}`}function q(e){let t=[],n=0,r=0,i=()=>{for(;n<e.length&&/\s/.test(e.charAt(n));)n++;return n<e.length};for(;n<e.length;){r=n;let a=!1;for(;i();){if(e.charAt(n)!==`,`){n++;continue}let o=n++;i();let s=n;for(;n<e.length&&!`=;,`.includes(e.charAt(n));)n++;n<e.length&&e.charAt(n)===`=`?(a=!0,n=s,t.push(e.substring(r,o)),r=n):n=o+1}(!a||n>=e.length)&&t.push(e.substring(r))}return t}function J(e){if(typeof e[0]==`string`)return[e[0],e[1],e[2]];let{name:t,value:n,...r}=e[0];return[t,n,r]}globalThis.URLPattern;export{F as a,I as i,k as n,m as o,j as r,E as t};
|
|
1
|
+
import"./unified-request-context-CgIMz2dD.js";import{A as e,M as t,j as n,o as r,r as i,s as a}from"./request-context-C1ZJzkex.js";import{i as o,n as s}from"./base-path-Cmiu3HvG.js";var c=[`authorization`,`cookie`];function l(e,t){if(e instanceof Headers)return e.get(t);let n=e[t];return n===void 0?null:Array.isArray(n)?n[0]??null:n}function u(t){let n=l(t,e);return n===null?null:n.split(`,`).map(e=>e.trim()).filter(Boolean)}function d(e){let t=new Map;if(e instanceof Headers){for(let[r,i]of e.entries())r.startsWith(`x-middleware-request-`)&&t.set(r.slice(n.length),i);return t}for(let[r,i]of Object.entries(e)){if(!r.startsWith(`x-middleware-request-`))continue;let e=Array.isArray(i)?i[0]??``:i;t.set(r.slice(n.length),e)}return t}function f(e){let t=new Headers;for(let[n,r]of e.entries())t.append(n,r);return t}function p(t,r){let i=[...r.keys()];t.set(e,i.join(`,`));for(let[e,i]of r.entries())t.set(`${n}${e}`,i)}function m(e,t,n={}){let r=u(t),i=d(t);if(r===null&&i.size===0)return null;let a=r===null?f(e):new Headers;if(r===null){for(let[e,t]of i)a.set(e,t);return a}if(n.preserveCredentialHeaders){let t=new Set(r);for(let n of c){if(t.has(n))continue;let r=e.get(n);r!==null&&a.set(n,r)}}for(let e of r){let t=i.get(e);t!==void 0&&a.set(e,t)}return a}var h=/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/;function g(e){if(!e||!h.test(e))throw Error(`Invalid cookie name: ${JSON.stringify(e)}`)}function _(e,t){for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r<=31||r===127||e[n]===`;`)throw Error(`Invalid cookie ${t} value: ${JSON.stringify(e)}`)}}var v=`[\\u0000-\\u001F \\u200B\\uFEFF]*`,y=`[\\r\\n\\t]*`;function b(e){let t=e.split(``).join(y);return RegExp(`^${v}${t}${y}:`,`i`)}var x=[b(`javascript`),b(`data`),b(`vbscript`)],S=`Next.js has blocked a javascript: URL as a security precaution.`;function C(e){let t=``+e;return x.some(e=>e.test(t))}function w(){console.error(S)}function T(e,t=Error){if(C(e))throw w(),new t(S)}var E=class extends Request{_nextUrl;_url;_cookies;constructor(e,t){O(typeof e!=`string`&&`url`in e?e.url:String(e));let{nextConfig:n,...r}=t??{};if(e instanceof Request){let t=r.body===void 0&&e.body&&!e.bodyUsed?e.clone():e;super(t,r);let n=Reflect.get(e,`cf`);n!==void 0&&Object.defineProperty(this,"cf",{value:n,enumerable:!0,configurable:!0})}else super(e,r);let i=typeof e==`string`?new URL(e,`http://localhost`):e instanceof URL?e:new URL(e.url,`http://localhost`),a=n?.i18n?{locales:[...n.i18n.locales],defaultLocale:n.i18n.defaultLocale,domains:n.i18n.domains?.map(e=>({...e,locales:e.locales?[...e.locales]:void 0}))}:void 0,o=n?{basePath:n.basePath,nextConfig:{i18n:a,trailingSlash:n.trailingSlash}}:void 0;this._nextUrl=new A(i,void 0,o),this._url=process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE?i.toString():this._nextUrl.toString(),this._cookies=new j(this.headers)}get nextUrl(){return this._nextUrl}get url(){return this._url}get cookies(){return this._cookies}get page(){throw Error(`NextRequest.page has been removed; use URLPattern instead`)}get ua(){throw Error(`NextRequest.ua has been removed; use userAgent() instead`)}get ip(){return this.headers.get(`cf-connecting-ip`)??this.headers.get(`x-real-ip`)??this.headers.get(`x-forwarded-for`)?.split(`,`)[0]?.trim()??void 0}get geo(){let e=this.headers.get(`cf-ipcountry`)??this.headers.get(`x-vercel-ip-country`)??void 0;if(e)return{country:e,city:this.headers.get(`cf-ipcity`)??this.headers.get(`x-vercel-ip-city`)??void 0,region:this.headers.get(`cf-region`)??this.headers.get(`x-vercel-ip-country-region`)??void 0,latitude:this.headers.get(`cf-iplatitude`)??this.headers.get(`x-vercel-ip-latitude`)??void 0,longitude:this.headers.get(`cf-iplongitude`)??this.headers.get(`x-vercel-ip-longitude`)??void 0}}get buildId(){return this._nextUrl.buildId}},D=new Set([301,302,303,307,308]);function O(e){T(String(e));try{return String(new URL(String(e)))}catch(t){throw Error(`URL is malformed "${String(e)}". Please use only absolute URLs - https://nextjs.org/docs/messages/middleware-relative-urls`,{cause:t})}}var k=class e extends Response{_cookies;constructor(e,t){super(e,t),this._cookies=new R(this.headers)}get cookies(){return this._cookies}static json(t,n){let r=Response.json(t,n);return new e(r.body,r)}static redirect(t,n){let r=typeof n==`number`?n:n?.status??307;if(!D.has(r))throw RangeError(`Failed to execute "redirect" on "response": Invalid status code`);let i=new Headers(typeof n==`object`?n?.headers:void 0);return i.set(`Location`,O(t)),new e(null,{status:r,headers:i})}static rewrite(t,n){let r=new Headers(n?.headers);return r.set(a,O(t)),n?.request?.headers&&p(r,n.request.headers),new e(null,{...n,headers:r})}static next(t){let n=new Headers(t?.headers);return n.set(r,`1`),t?.request?.headers&&p(n,t.request.headers),new e(null,{...t,headers:n})}},A=class e{_url;_configBasePath;_basePath;_trailingSlash;_locale;_configDefaultLocale;_defaultLocale;_locales;_domains;_domainLocale;constructor(e,t,n){this._url=new URL(e.toString(),t),this._configBasePath=n?.basePath??``,this._basePath=this._configBasePath,this._trailingSlash=n?.nextConfig?.trailingSlash??!1,this._stripBasePath();let r=n?.nextConfig?.i18n;r&&(this._locales=[...r.locales],this._domains=r.domains?.map(e=>({...e,locales:e.locales?[...e.locales]:void 0})),this._configDefaultLocale=r.defaultLocale,this._analyzeI18n())}_stripBasePath(){if(this._configBasePath){if(!s(this._url.pathname,this._configBasePath)){this._basePath=``;return}this._basePath=this._configBasePath,this._url.pathname=o(this._url.pathname,this._configBasePath)}}_detectPathnameLocale(e){let t=this._url.pathname.split(`/`),n=t[1]?.toLowerCase(),r=e.find(e=>e.toLowerCase()===n);return r&&(this._url.pathname=`/`+t.slice(2).join(`/`)),r}_analyzeI18n(){if(!this._locales||!this._configDefaultLocale)return;let e=this._detectPathnameLocale(this._locales),t=e?.toLowerCase(),n=this._url.hostname.toLowerCase();this._domainLocale=this._domains?.find(e=>e.domain.split(`:`,1)[0].toLowerCase()===n||t===e.defaultLocale.toLowerCase()||e.locales?.some(e=>e.toLowerCase()===t)),this._defaultLocale=this._domainLocale?.defaultLocale??this._configDefaultLocale,this._locale=e??this._defaultLocale}_formatPathname(){let e=this._basePath,t=this._url.pathname,n=t.toLowerCase();!(n===`/api`||n.startsWith(`/api/`))&&this._locale&&this._locale!==this._defaultLocale&&(e+=`/`+this._locale);let r=e?t===`/`?e:e+t:t;return this._applyTrailingSlash(r)}_applyTrailingSlash(e){return e===``||e===`/`?e:this._trailingSlash?e.endsWith(`/`)?e:e+`/`:e.endsWith(`/`)?e.slice(0,-1):e}get href(){let e=this._formatPathname();if(e===this._url.pathname)return this._url.href;let{href:t,pathname:n,search:r,hash:i}=this._url,a=t.length-n.length-r.length-i.length;return t.slice(0,a)+e+r+i}set href(e){this._url.href=e,this._stripBasePath(),this._analyzeI18n()}get origin(){return this._url.origin}get protocol(){return this._url.protocol}set protocol(e){this._url.protocol=e}get username(){return this._url.username}set username(e){this._url.username=e}get password(){return this._url.password}set password(e){this._url.password=e}get host(){return this._url.host}set host(e){this._url.host=e}get hostname(){return this._url.hostname}set hostname(e){this._url.hostname=e}get port(){return this._url.port}set port(e){this._url.port=e}get pathname(){return this._url.pathname}set pathname(e){this._url.pathname=e}get search(){return this._url.search}set search(e){this._url.search=e}get searchParams(){return this._url.searchParams}get hash(){return this._url.hash}set hash(e){this._url.hash=e}get basePath(){return this._basePath}set basePath(e){this._basePath=e===``?``:e.startsWith(`/`)?e:`/`+e}get locale(){return this._locale??``}set locale(e){if(this._locales){if(!e){this._locale=this._defaultLocale;return}if(!this._locales.includes(e))throw TypeError(`The locale "${e}" is not in the configured locales: ${this._locales.join(`, `)}`)}this._locale=this._locales?e:this._locale}get defaultLocale(){return this._defaultLocale}get domainLocale(){if(this._domainLocale)return{...this._domainLocale,locales:this._domainLocale.locales?[...this._domainLocale.locales]:void 0}}get locales(){return this._locales?[...this._locales]:void 0}clone(){let t={};this._locales&&(t.i18n={locales:[...this._locales],defaultLocale:this._configDefaultLocale,domains:this._domains?.map(e=>({...e,locales:e.locales?[...e.locales]:void 0}))}),this._trailingSlash&&(t.trailingSlash=!0);let n={basePath:this._configBasePath,nextConfig:Object.keys(t).length>0?t:void 0};return new e(this.href,void 0,n)}toString(){return this.href}toJSON(){return this.href}get buildId(){return`7c810a6d-59fd-41d6-b465-cf61efaea04f`}},j=class{_headers;_parsed;constructor(e){this._headers=e,this._parsed=i(e.get(`cookie`)??``)}get(e){let t=this._parsed.get(e);return t===void 0?void 0:{name:e,value:t}}getAll(e){let t=typeof e==`string`?e:e?.name;return[...this._parsed.entries()].filter(([e])=>t===void 0||e===t).map(([e,t])=>({name:e,value:t}))}has(e){return this._parsed.has(e)}set(e,t){let n,r;return typeof e==`string`?(n=e,r=t??``):(n=e.name,r=e.value),g(n),this._parsed.set(n,r),this._syncHeader(),this}delete(e){if(Array.isArray(e)){let t=e.map(e=>(g(e),this._parsed.delete(e)));return this._syncHeader(),t}g(e);let t=this._parsed.delete(e);return this._syncHeader(),t}clear(){return this._parsed.clear(),this._syncHeader(),this}get size(){return this._parsed.size}toString(){return this._serialize()}_serialize(){return[...this._parsed.entries()].map(([e,t])=>`${e}=${encodeURIComponent(t)}`).join(`; `)}_syncHeader(){this._parsed.size===0?this._headers.delete(`cookie`):this._headers.set(`cookie`,this._serialize())}[Symbol.iterator](){return new Map(this.getAll().map(e=>[e.name,e])).entries()}},M=class e extends Error{constructor(){super(`Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#options`)}static callable(){throw new e}},N=new Set([`set`,`delete`,`append`]),P=class e extends Error{constructor(){super(`Headers cannot be modified. Read more: https://nextjs.org/docs/app/api-reference/functions/headers`)}static callable(){throw new e}};function F(e){return new Proxy(e,{get(e,t){if(typeof t==`string`&&N.has(t))return P.callable;let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}})}function I(e){return new Proxy(e,{get(e,t){if(t===`set`||t===`delete`||t===`clear`)return M.callable;let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}})}var L=class{_headers;_parsed=new Map;constructor(e){this._headers=e;let t=e.getSetCookie?.()??e.get(`set-cookie`)??[],n=Array.isArray(t)?t:q(t);for(let e of n){let t=B(e);t&&this._parsed.set(t.name,t)}}set(...e){let[t,n,r]=J(e);g(t);let i=z(t,n,r);return G(i),this._parsed.set(t,i),this._syncHeaders(),this}get(...e){let t=typeof e[0]==`string`?e[0]:e[0].name;return this._parsed.get(t)}has(e){return this._parsed.has(e)}getAll(...e){let t=[...this._parsed.values()];if(e.length===0)return t;let n=typeof e[0]==`string`?e[0]:e[0].name;return t.filter(e=>e.name===n)}delete(...e){let[t,n]=typeof e[0]==`string`?[e[0],void 0]:[e[0].name,e[0]];return this.set({...n,name:t,value:``,expires:new Date(0)})}[Symbol.iterator](){return new Map([...this._parsed.values()].map(e=>[e.name,e])).entries()}toString(){return[...this._parsed.values()].map(K).join(`; `)}_syncHeaders(){this._headers.delete(`Set-Cookie`);for(let e of this._parsed.values())this._headers.append(`Set-Cookie`,K(e))}},R=class extends L{_responseHeaders;constructor(e){super(e),this._responseHeaders=e}set(...e){return super.set(...e),this._syncMiddlewareCookieHeader(),this}delete(...e){return super.delete(...e),this._syncMiddlewareCookieHeader(),this}_syncMiddlewareCookieHeader(){let e=this._responseHeaders.getSetCookie();if(e.length===0){this._responseHeaders.delete(t);return}this._responseHeaders.set(t,e.join(`,`))}};function z(e,t,n){let r={name:e,value:t,...n};return typeof r.expires==`number`&&(r.expires=new Date(r.expires)),r.maxAge&&(r.expires=new Date(Date.now()+r.maxAge*1e3)),r.path??=`/`,r}function B(e){if(!e)return;let[[t,n],...r]=V(e),{domain:i,expires:a,httponly:o,maxage:s,path:c,samesite:l,secure:u,partitioned:d,priority:f}=Object.fromEntries(r.map(([e,t])=>[e.toLowerCase().replaceAll(`-`,``),t]));return H({name:t,value:decodeURIComponent(n),domain:i,...a&&{expires:new Date(a)},...o&&{httpOnly:!0},...typeof s==`string`&&{maxAge:Number(s)},path:c,...l&&{sameSite:U(l)},...u&&{secure:!0},...f&&{priority:W(f)},...d&&{partitioned:!0}})}function V(e){let t=new Map;for(let n of e.split(/; */)){if(!n)continue;let e=n.indexOf(`=`);if(e===-1){t.set(n,`true`);continue}let r=n.slice(0,e),i=n.slice(e+1);try{t.set(r,decodeURIComponent(i??`true`))}catch{}}return t}function H(e){let t={};for(let n in e)e[n]&&(t[n]=e[n]);return t}function U(e){let t=e.toLowerCase();return t===`strict`||t===`lax`||t===`none`?t:void 0}function W(e){let t=e.toLowerCase();return t===`low`||t===`medium`||t===`high`?t:void 0}function G(e){e.path&&_(e.path,`Path`),e.domain&&_(e.domain,`Domain`)}function K(e){let t=[e.path&&`Path=${e.path}`,(e.expires||e.expires===0)&&`Expires=${(typeof e.expires==`number`?new Date(e.expires):e.expires).toUTCString()}`,typeof e.maxAge==`number`&&`Max-Age=${e.maxAge}`,e.domain&&`Domain=${e.domain}`,e.secure&&`Secure`,e.httpOnly&&`HttpOnly`,e.sameSite&&`SameSite=${e.sameSite}`,e.partitioned&&`Partitioned`,e.priority&&`Priority=${e.priority}`].filter(Boolean),n=`${e.name}=${encodeURIComponent(e.value??``)}`;return t.length===0?n:`${n}; ${t.join(`; `)}`}function q(e){let t=[],n=0,r=0,i=()=>{for(;n<e.length&&/\s/.test(e.charAt(n));)n++;return n<e.length};for(;n<e.length;){r=n;let a=!1;for(;i();){if(e.charAt(n)!==`,`){n++;continue}let o=n++;i();let s=n;for(;n<e.length&&!`=;,`.includes(e.charAt(n));)n++;n<e.length&&e.charAt(n)===`=`?(a=!0,n=s,t.push(e.substring(r,o)),r=n):n=o+1}(!a||n>=e.length)&&t.push(e.substring(r))}return t}function J(e){if(typeof e[0]==`string`)return[e[0],e[1],e[2]];let{name:t,value:n,...r}=e[0];return[t,n,r]}globalThis.URLPattern;export{F as a,I as i,k as n,m as o,j as r,E as t};
|