Files
my_openplace/frontend/_app/immutable/chunks/C4PhwnwB.js
T
2025-10-02 02:40:11 -07:00

2 lines
5.3 KiB
JavaScript

var d=Object.defineProperty;var h=(s,e,t)=>e in s?d(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>h(s,typeof e!="symbol"?e+"":e,t);import{d as c,w as y}from"./DgYqO0BT.js";import{A as g,n as m}from"./D8zjZoA1.js";class o extends Error{constructor(e,t){super(t),this.status=e,this.name="ApiError"}}class p{constructor(e=g){i(this,"baseUrl");i(this,"online",!0);this.baseUrl=e}async request(e,t={}){try{const r=await fetch(`${this.baseUrl}${e}`,{credentials:"include",...t,headers:{"Content-Type":"application/json",...t.headers}});if(this.online=!0,!r.ok){const a=await r.json().catch(()=>({error:"Unknown error"}));throw new o(r.status,a.error||"Request failed")}const n=await r.text();return n?JSON.parse(n):null}catch(r){throw r instanceof o?r:(this.online=!1,new o(0,r instanceof Error?r.message:"Network error"))}}async logout(){return this.request("/auth/logout",{method:"POST"})}async getMe(){return this.request("/me")}async updateMe(e){return this.request("/me/update",{method:"POST",body:JSON.stringify(e)})}async getProfilePictures(){return this.request("/me/profile-pictures")}async getRandomTile(e){return this.request(`/${e}/tile/random`)}async getPixelInfo(e,t,r,n,a){return this.request(`/${e}/pixel/${t}/${r}?x=${n}&y=${a}`)}async paintPixels(e,t,r,n){return this.request(`/${e}/pixel/${t}/${r}`,{method:"POST",body:JSON.stringify(n)})}getTileImageUrl(e,t,r){return`${this.baseUrl}/files/${e}/tiles/${t}/${r}.png`}async getAlliance(){return this.request("/alliance")}async createAlliance(e){return this.request("/alliance",{method:"POST",body:JSON.stringify({name:e})})}async updateAllianceDescription(e){return this.request("/alliance/update-description",{method:"POST",body:JSON.stringify({description:e})})}async updateAllianceHeadquarters(e,t){return this.request("/alliance/update-headquarters",{method:"POST",body:JSON.stringify({latitude:e,longitude:t})})}async getAllianceInvites(){return this.request("/alliance/invites")}async joinAlliance(e){return this.request(`/alliance/join/${e}`)}async getAllianceMembers(e){return this.request(`/alliance/members/${e}`)}async getBannedMembers(e){return this.request(`/alliance/members/banned/${e}`)}async promoteUser(e){return this.request("/alliance/give-admin",{method:"POST",body:JSON.stringify({promotedUserId:e})})}async banUser(e){return this.request("/alliance/ban",{method:"POST",body:JSON.stringify({bannedUserId:e})})}async unbanUser(e){return this.request("/alliance/unban",{method:"POST",body:JSON.stringify({unbannedUserId:e})})}async getAllianceLeaderboard(e){return this.request(`/alliance/leaderboard/${e}`)}async getPlayerLeaderboard(e){return this.request(`/leaderboard/player/${e}`)}async getAllianceLeaderboardGlobal(e){return this.request(`/leaderboard/alliance/${e}`)}async getCountryLeaderboard(e){return this.request(`/leaderboard/country/${e}`)}async getRegionLeaderboard(e,t){return this.request(`/leaderboard/region/${e}/${t}`)}async purchase(e){return this.request("/purchase",{method:"POST",body:JSON.stringify({product:e})})}async equipFlag(e){return this.request(`/flag/equip/${e}`,{method:"POST"})}async addFavoriteLocation(e){return this.request("/favorite-location",{method:"POST",body:JSON.stringify(e)})}async updateFavoriteLocation(e,t){return this.request("/favorite-location/update",{method:"POST",body:JSON.stringify({id:e,...t})})}async getModeratorTickets(){return this.request("/moderator/tickets")}async getSevereTicketsCount(){return this.request("/moderator/severe-open-tickets-count",{method:"POST"})}async getOpenTicketsCount(){return this.request("/moderator/open-tickets-count")}async getUser(e){return this.request(`/admin/users?id=${e}`)}async getUserNotes(e){return this.request(`/admin/users/notes?userId=${e}`)}async addUserNote(e,t){return this.request("/admin/users/notes",{method:"POST",body:JSON.stringify({userId:e,note:t})})}async setUserDroplets(e,t){return this.request("/admin/users/set-user-droplets",{method:"POST",body:JSON.stringify({userId:e,droplets:t})})}async getAdminTickets(){return this.request("/admin/tickets")}async getClosedTickets(){return this.request("/admin/closed-tickets")}async getOpenTicketsCountAdmin(){return this.request("/admin/open-tickets-count")}async countAllTickets(){return this.request("/admin/count-all-tickets")}async searchAlliances(e){return this.request(`/admin/alliances/search?q=${encodeURIComponent(e)}`)}async getAllianceById(e){return this.request(`/admin/alliances/${e}`)}async getAllianceByIdFull(e){return this.request(`/admin/alliances/${e}/full`)}}const u=new p;function q(s,e,t,r){if(s>=e)return s;const n=Date.now()-t.getTime(),a=Math.floor(n/r);return Math.min(e,s+a)}function f(s){return Math.floor(Math.sqrt(s/100))+1}function b(){const{subscribe:s,set:e,update:t}=y(null);return{subscribe:s,set:e,update:t,async fetch(){try{const r=await u.getMe();return e(r),r}catch(r){return console.error("Failed to fetch user:",r),e(null),null}},async updateProfile(r){try{const n=await u.updateMe(r);return e(n),n}catch(n){throw console.error("Failed to update profile:",n),n}},async logout(){try{await u.logout(),e(null)}catch(r){throw console.error("Failed to logout:",r),r}},clear(){e(null)}}}const l=b(),$=c([l,m],([s,e])=>s?q(s.currentCharges,s.maxCharges,new Date(s.chargesLastUpdatedAt),s.chargesCooldownMs):0);c(l,s=>s!==null);c(l,s=>s?f(s.pixelsPainted):1);export{o as A,u as a,f as b,l as c,$ as d};