1import{c as C,e as L}from"./chunk-UB7IYPFH.js";import{a as U}from"./chunk-XRWMWB3K.js";import{a as N}from"./chunk-YIKHX72X.js";import{a as O,c as k}from"./chunk-HLOHHFCD.js";import{a as _}from"./chunk-CXWAFE77.js";import{$ as l,F as m,H as p,I as R,Ja as q,L as d,P as A,X as Y,Y as $,_ as j,a as c,b as g,ba as f,ca as y,ea as S,ja as u,l as T,m as b,o as Q,q as n,r as w,u as s,v as h,z as P}from"./chunk-P5UROMFP.js";var D=class v{constructor(e,t,a,i,r,o){this.platformId=e;this.route=t;this.router=a;this.metadatatoolService=i;this.httpClient=r;this.localStorageService=o;this.#e=new b(this.localStorageService.get("qytoken")),this.token$=this.#e.asObservable()}#e;token$;login(){h([this.metadatatoolService.metadata$.pipe(s(e=>e.quantyoo)),this.route.queryParamMap.pipe(m(e=>e.has("code")),s(e=>e.get("code")))]).pipe(d(1),l(([e,t])=>this.createToken(e.qyclient,t??""))).subscribe(e=>{this.setToken(e),this.router.navigate([],{replaceUrl:!0,relativeTo:this.route})})}logout(){this.setToken(null)}refreshToken(){return h([this.metadatatoolService.metadata$.pipe(s(e=>e.quantyoo)),this.#e.pipe(m(e=>!!e))]).pipe(d(1),l(([e,t])=>{let a=new O().set("refresh_token",t?.refresh_token).set("grant_type","refresh_token").set("client_id",e.qyclient);return this.requestToken(a)}),p(e=>n(null)),f(e=>this.setToken(e)))}setToken(e){e?this.localStorageService.set("qytoken",e):this.localStorageService.delete("qytoken"),this.#e.next(e)}createToken(e,t){let a=new O().set("code",t).set("client_id",e).set("grant_type","authorization_code").set("redirect_uri",window.location.protocol+"//"+window.location.host+window.location.pathname);return this.requestToken(a)}requestToken(e){return this.httpClient.post("/oauth/token",e,{headers:{"Content-Type":"application/x-www-form-urlencoded"}})}static \u0275fac=function(t){return new(t||v)(u(q),u(C),u(L),u(N),u(k),u(U))};static \u0275prov=S({token:v,factory:v.\u0275fac,providedIn:"root"})};var M=class v{constructor(e,t,a,i){this.document=e;this.httpClient=t;this.quantyooAuthService=a;this.localStorageService=i;this.loggedIn$=this.quantyooAuthService.token$.pipe(s(r=>!(r===null||(r.created_at+r.expires_in)*1e3<new Date().getTime())),$(1)),this.user$=h([this.quantyooAuthService.token$,this.#t]).pipe(s(([r,o])=>r),l(r=>r?this.me().pipe(l(o=>o?this.getPlayerState(o):n(null))):n(null)),$(1)),this.likedsongs$=h([this.user$.pipe(l(r=>r?n(this.localStorageService.get("qyreactions")).pipe(s(o=>o===null||o[r.uuid]===void 0?{reactions:{},since:r.createdon}:o[r.uuid]),l(o=>P({qyreactions:n(o),reactions:this.getAllUserLikedSongs(r.uuid,o.since)})),s(o=>({user:r,qyreactions:{since:this.getQYTimestamp(),reactions:c(c({},o.qyreactions.reactions),o.reactions)}}))):w(()=>n(null)))),this.#e.pipe(j(null))]).pipe(s(([r,o])=>({userData:r,reacton:o})),s(r=>(r.reacton&&(r.userData.qyreactions.reactions=g(c({},r.userData.qyreactions.reactions),{[r.reacton.datakey]:r.reacton.datavalue}),r.userData.qyreactions.since=this.getQYTimestamp()),r)),f(r=>this.localStorageService.set("qyreactions",g(c({},this.localStorageService.get("qyreactions")),{[r.userData.user.uuid]:r.userData.qyreactions}))),s(r=>r.userData.qyreactions.reactions),p(r=>n({})),Y())}likedsongs$;loggedIn$;user$;#e=new T;#t=new b(!0);logout(e){this.quantyooAuthService.logout(),this.document.defaultView.location.href=e}me(){return this.httpClient.get("/v2/users/me").pipe(s(e=>e.success?e.data:null),p(e=>n(null)))}reaction(e,t){this.loggedIn$.pipe(y(this.user$),s(([a,i])=>({loggedIn:a,user:i})),m(a=>a.loggedIn),l(a=>a.loggedIn?this.upsertUserData(a.user.uuid,"likedsongs",{datakey:t,datavalue:e==="like"?"1":"0"}):n({success:!1})),d(1)).subscribe(a=>{a.success&&this.#e.next(a.data)})}trackDislike(e){this.loggedIn$.pipe(y(this.user$),s(([t,a])=>({loggedIn:t,user:a})),m(t=>t.loggedIn),l(t=>t.loggedIn?this.deleteUserData(t.user.uuid,"mylikedsongs",e):n({success:!1})),d(1)).subscribe()}trackLike(e,t){this.loggedIn$.pipe(y(this.user$),s(([a,i])=>({loggedIn:a,user:i})),m(a=>a.loggedIn),l(a=>a.loggedIn?this.upsertUserData(a.user.uuid,"mylikedsongs",{datakey:e,datavalue:JSON.stringify(t)}):n({success:!1})),d(1)).subscribe()}trackPlayerStart(e,t){this.loggedIn$.pipe(y(this.user$),s(([a,i])=>({loggedIn:a,user:i})),m(a=>a.loggedIn),l(a=>a.loggedIn?this.upsertUserData(a.user.uuid,"myaudios",{datakey:e,datavalue:JSON.stringify(t)}):n({success:!1})),d(1)).subscribe()}savePlayerState(e,t){return this.loggedIn$.pipe(y(this.user$),s(([a,i])=>({loggedIn:a,user:i})),l(a=>a.loggedIn?this.upsertUserData(a.user.uuid,"metadata",{datakey:"player",datavalue:JSON.stringify({player:e,progress:t})}):n(null)),d(1))}getNewsCategories(e){return this.getUserData(e.uuid,"metadata","newscategories").pipe(s(t=>JSON.parse(t.data.datavalue)),p(t=>n([])))}setNewsCategories(e,t){return this.upsertUserData(e.uuid,"metadata",{datakey:"newscategories",datavalue:JSON.stringify(t)})}getMyAudios(e,t,a){return this.getAllUserData(e.uuid,"myaudios",{offset:t,limit:a}).pipe(s(i=>i.data),s(i=>i.map(r=>g(c({},r),{datavalue:JSON.parse(r.datavalue)}))),p(i=>n([])))}deleteUserDataJSON(e,t,a){return this.deleteUserData(e,t,a).pipe(s(i=>g(c({},i.data),{datavalue:JSON.parse(i.data.datavalue)})),p(i=>n(null)),d(1))}getMyLikedSongs(e,t,a){return this.getAllUserData(e.uuid,"mylikedsongs",{offset:t,limit:a}).pipe(s(i=>i.data),s(i=>i.map(r=>g(c({},r),{datavalue:JSON.parse(r.datavalue)}))),p(i=>n([])))}setQYUUID(e,t=!1){try{window.Qyjs("tracking.setUuid",e,t)}catch(a){console.error(a)}}getPlayerState(e){return this.getUserData(e.uuid,"metadata","player").pipe(s(t=>JSON.parse(t.data.datavalue)),p(t=>n(null)),s(t=>g(c({},e),{_meta:g(c({},e._meta),{playerState:t})})))}getAllUserLikedSongs(e,t){let i=0;return this.getAllUserData(e,"likedsongs",{limit:5,since:t,offset:i}).pipe(A(r=>r.success&&r.data.length?this.getAllUserData(e,"likedsongs",{limit:5,since:t,offset:i=i+5}
1):Q),s(r=>r.data),R((r,o)=>[...r,...o]),s(r=>r.reduce((o,I)=>g(c({},o),{[I.datakey]:I.datavalue}),{})))}getQYTimestamp(e=new Date().getTime()){return Math.ceil(e/1e3)}upsertUserData(e,t,a){return this.httpClient.post(`/v2/users/${e}/data/${t}`,a)}getAllUserData(e,t,a={}){return this.httpClient.get(`/v2/users/${e}/data/${t}?${Object.keys(a).map(i=>`${i}=${a[i]}`).join("&")}`).pipe(d(1))}getUserData(e,t,a){return this.httpClient.get(`/v2/users/${e}/data/${t}/${a}`)}deleteUserData(e,t,a){return this.httpClient.delete(`/v2/users/${e}/data/${t}/${a}`)}static \u0275fac=function(t){return new(t||v)(u(_),u(k),u(D),u(U))};static \u0275prov=S({token:v,factory:v.\u0275fac,providedIn:"root"})};export{D as a,M as b};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.