Files
nademitex_user/dist/assets/http-CeONvUNq.js
T
mohmdsdgandCopilot adb6ca47cd fix(auth): secure sessions and app routing
Validate sessions against the API, honor configurable base paths, and route unknown pages to 404. Keep development ports stable so user and admin apps cannot be confused.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-24 20:14:11 +03:30

1 line
8.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{B as e,Ct as t,H as n,St as r,at as i,dt as a,ft as o,gt as s,ht as c,mt as l,pt as u,ut as d,vt as f,w as p,wt as m,z as h}from"./_plugin-vue_export-helper-Bo3WtfwJ.js";var g=typeof window<`u`,_,v=e=>_=e,y=Symbol();function b(e){return e&&typeof e==`object`&&Object.prototype.toString.call(e)===`[object Object]`&&typeof e.toJSON!=`function`}var x=typeof window==`object`&&window.window===window?window:typeof self==`object`&&self.self===self?self:typeof global==`object`&&global.global===global?global:typeof globalThis==`object`?globalThis:{HTMLElement:null};function S(e,{autoBom:t=!1}={}){return t&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([``,e],{type:e.type}):e}function C(e,t,n){let r=new XMLHttpRequest;r.open(`GET`,e),r.responseType=`blob`,r.onload=function(){O(r.response,t,n)},r.onerror=function(){console.error(`could not download file`)},r.send()}function w(e){let t=new XMLHttpRequest;t.open(`HEAD`,e,!1);try{t.send()}catch{}return t.status>=200&&t.status<=299}function T(e){try{e.dispatchEvent(new MouseEvent(`click`))}catch{let t=new MouseEvent(`click`,{bubbles:!0,cancelable:!0,view:window,detail:0,screenX:80,screenY:20,clientX:80,clientY:20,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,button:0,relatedTarget:null});e.dispatchEvent(t)}}var E=typeof navigator==`object`?navigator:{userAgent:``},D=/Macintosh/.test(E.userAgent)&&/AppleWebKit/.test(E.userAgent)&&!/Safari/.test(E.userAgent),O=g?typeof HTMLAnchorElement<`u`&&`download`in HTMLAnchorElement.prototype&&!D?k:`msSaveOrOpenBlob`in E?A:j:()=>{};function k(e,t=`download`,n){let r=document.createElement(`a`);r.download=t,r.rel=`noopener`,typeof e==`string`?(r.href=e,r.origin===location.origin?T(r):w(r.href)?C(e,t,n):(r.target=`_blank`,T(r))):(r.href=URL.createObjectURL(e),setTimeout(function(){URL.revokeObjectURL(r.href)},4e4),setTimeout(function(){T(r)},0))}function A(e,t=`download`,n){if(typeof e==`string`)if(w(e))C(e,t,n);else{let t=document.createElement(`a`);t.href=e,t.target=`_blank`,setTimeout(function(){T(t)})}else navigator.msSaveOrOpenBlob(S(e,n),t)}function j(e,t,n,r){if(r||=open(``,`_blank`),r&&(r.document.title=r.document.body.innerText=`downloading...`),typeof e==`string`)return C(e,t,n);let i=e.type===`application/octet-stream`,a=/constructor/i.test(String(x.HTMLElement))||`safari`in x,o=/CriOS\/[\d]+/.test(navigator.userAgent);if((o||i&&a||D)&&typeof FileReader<`u`){let t=new FileReader;t.onloadend=function(){let e=t.result;if(typeof e!=`string`)throw r=null,Error(`Wrong reader.result type`);e=o?e:e.replace(/^data:[^;]*;/,`data:attachment/file;`),r?r.location.href=e:location.assign(e),r=null},t.readAsDataURL(e)}else{let t=URL.createObjectURL(e);r?r.location.assign(t):location.href=t,r=null,setTimeout(function(){URL.revokeObjectURL(t)},4e4)}}var{assign:ee}=Object;function M(){let e=d(!0),t=e.run(()=>f({})),n=[],r=[],i=l({install(e){v(i),i._a=e,e.provide(y,i),e.config.globalProperties.$pinia=i,r.forEach(e=>n.push(e)),r=[]},use(e){return this._a?n.push(e):r.push(e),this},_p:n,_a:null,_e:e,_s:new Map,state:t});return i}var N=()=>{};function P(e,t,n,r=N){e.add(t);let i=()=>{e.delete(t)&&r()};return!n&&a()&&c(i),i}function F(e,...t){e.forEach(e=>{e(...t)})}var I=e=>e(),L=Symbol(),R=Symbol();function z(e,t){e instanceof Map&&t instanceof Map?t.forEach((t,n)=>e.set(n,t)):e instanceof Set&&t instanceof Set&&t.forEach(e.add,e);for(let n in t){if(!Object.hasOwn(t,n))continue;let r=t[n],i=e[n];e[n]=b(i)&&b(r)&&Object.hasOwn(e,n)&&!u(r)&&!o(r)?z(i,r):r}return e}var B=Symbol();function V(e){return!e||typeof e!=`object`||!Object.hasOwn(e,B)}var{assign:H}=Object;function U(e){return!!(u(e)&&e.effect)}function W(e,t,n,r){let{state:i,actions:a,getters:o}=t,s=n.state.value[e],c;function u(){return s||(n.state.value[e]=i?i():{}),H(m(n.state.value[e]),a,Object.keys(o||{}).reduce((t,r)=>(t[r]=l(p(()=>{v(n);let t=n._s.get(e);return o[r].call(t,t)})),t),{}))}return c=G(e,u,t,n,r,!0),c}function G(e,t,a={},c,l,f){let p,m=H({actions:{}},a),h={deep:!0},g,_,y=new Set,b=new Set,x,S=c.state.value[e];!f&&!S&&(c.state.value[e]={});let C;function w(t){let r;g=_=!1,typeof t==`function`?(t(c.state.value[e]),r={type:`patch function`,storeId:e,events:x}):(z(c.state.value[e],t),r={type:`patch object`,payload:t,storeId:e,events:x});let i=C=Symbol();n().then(()=>{C===i&&(g=!0)}),_=!0,F(y,r,c.state.value[e])}let T=f?function(){let{state:e}=a,t=e?e():{};this.$patch(e=>{H(e,t)})}:N;function E(){p.stop(),y.clear(),b.clear(),c._s.delete(e)}let D=(t,n=``)=>{if(L in t)return t[R]=n,t;let r=function(){v(c);let n=Array.from(arguments),i=new Set,a=new Set;function o(e){i.add(e)}function s(e){a.add(e)}F(b,{args:n,name:r[R],store:k,after:o,onError:s});let l;try{l=t.apply(this&&this.$id===e?this:k,n)}catch(e){throw F(a,e),e}return l instanceof Promise?l.then(e=>(F(i,e),e)).catch(e=>(F(a,e),Promise.reject(e))):(F(i,l),l)};return r[L]=!0,r[R]=n,r},O={_p:c,$id:e,$onAction:P.bind(null,b),$patch:w,$reset:T,$subscribe(t,n={}){if(y.has(t))return N;let r=P(y,t,n.detached,()=>a()),a=p.run(()=>i(()=>c.state.value[e],r=>{(n.flush===`sync`?_:g)&&t({storeId:e,type:`direct`,events:x},r)},H({},h,n)));return r},$dispose:E},k=s(O);c._s.set(e,k);let A=(c._a&&c._a.runWithContext||I)(()=>c._e.run(()=>(p=d()).run(()=>t({action:D}))));for(let t in A){let n=A[t];u(n)&&!U(n)||o(n)?f||(S&&V(n)&&(u(n)?n.value=S[t]:z(n,S[t])),c.state.value[e][t]=n):typeof n==`function`&&(A[t]=D(n,t),m.actions[t]=n)}return H(k,A),H(r(k),A),Object.defineProperty(k,"$state",{get:()=>c.state.value[e],set:e=>{w(t=>{H(t,e)})}}),c._p.forEach(e=>{let t=p.run(()=>e({store:k,app:c._a,pinia:c,options:m}));H(k,t)}),S&&f&&a.hydrate&&a.hydrate(k.$state,S),g=!0,_=!0,k}function K(t,n,r){let i,a=typeof n==`function`;i=a?r:n;function o(r,o){let s=h();return r||=s?e(y,null):null,r&&v(r),r=_,r._s.has(t)||(a?G(t,n,i,r):W(t,i,r)),r._s.get(t)}return o.$id=t,o}function q(e){let n=r(e),i={};for(let r in n){let a=n[r];a?.effect?i[r]=p({get:()=>e[r],set(t){e[r]=t}}):(u(a)||o(a))&&(i[r]=t(e,r))}return i}var J=`ft_access_token`;function Y(){return`https://nademitex.montest.ir/server/api`.replace(/\/$/,``)||`https://nademitex.montest.ir/server/api`}function X(){return localStorage.getItem(J)}function Z(e){e?localStorage.setItem(J,e):localStorage.removeItem(J)}var Q=class extends Error{status;constructor(e,t){super(t),this.status=e}};function $(e,t){let n=Y(),r=e.startsWith(`http`)?e:`${n.replace(/\/$/,``)}/${e.replace(/^\//,``)}`,i=r.startsWith(`http`)?new URL(r):new URL(r,typeof window<`u`?window.location.origin:`http://127.0.0.1`);if(t)for(let[e,n]of Object.entries(t))n!=null&&n!==``&&i.searchParams.set(e,String(n));return i.toString()}function te(e,t){if(typeof e==`object`&&e){if(`message`in e){let t=e.message;if(Array.isArray(t))return t.join(`، `);if(t!=null&&String(t).trim())return String(t)}if(`error`in e){let n=e.error;if(typeof n==`string`&&n.trim())return`${n} (${t})`}}if(typeof e==`string`){if(/upstream error/i.test(e))return`سرور API در دسترس نیست. کمی بعد دوباره تلاش کنید.`;if(e.trim()&&!e.trimStart().startsWith(`<`))return e.trim().slice(0,200)}return t===400?`درخواست نامعتبر است. اطلاعات سفارش را بررسی کنید.`:t===401?`نشست شما منقضی شده است. دوباره وارد شوید.`:`خطای سرور (${t})`}async function ne(e,t={}){let n={Accept:`application/json`};if(t.body!==void 0&&(n[`Content-Type`]=`application/json`),t.auth!==!1){let e=X();e&&(n.Authorization=`Bearer ${e}`)}let r;try{r=await fetch($(e,t.query),{method:t.method??(t.body===void 0?`GET`:`POST`),headers:n,body:t.body===void 0?void 0:JSON.stringify(t.body),signal:AbortSignal.timeout(2e4)})}catch(e){throw new Q(0,e instanceof DOMException&&e.name===`TimeoutError`||e instanceof Error&&e.name===`TimeoutError`?`پاسخ سرور طول کشید. دوباره تلاش کنید.`:`اتصال به سرور برقرار نشد. اینترنت یا آدرس API را بررسی کنید.`)}let i=await r.text(),a=null;if(i)try{a=JSON.parse(i)}catch{a=i}if(!r.ok){if(r.status===401&&t.auth!==!1){Z(null);try{localStorage.removeItem(`ft_user`)}catch{}let e=`/login`;if(typeof window<`u`&&!window.location.pathname.startsWith(e)){let t=encodeURIComponent(`${window.location.pathname}${window.location.search}`);window.location.assign(`${e}?redirect=${t}`)}}throw new Q(r.status,te(a,r.status))}return a}export{M as a,Z as i,ne as n,K as o,X as r,q as s,Q as t};