-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi-client-BXEMiUh7.chunk.mjs
More file actions
2 lines (2 loc) · 4.45 KB
/
Copy pathapi-client-BXEMiUh7.chunk.mjs
File metadata and controls
2 lines (2 loc) · 4.45 KB
1
2
import{f as i,A as c,o as u}from"./oc-compat-hVqZy-MX.chunk.mjs";const w=(t,e)=>{const n=!t||t==="/"?"":String(t),r=String(e||"").replace(/^\/+/,"").replace(/\s+\.pad$/i,".pad");return n===""?"/"+r:n+"/"+r},g=t=>typeof t=="string"&&t.toLowerCase().endsWith(".pad"),y=t=>{if(!t||typeof t!="string")return"/";const e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)||"/"},U=()=>{const t=(new URLSearchParams(window.location.search||"").get("dir")||"/").trim();return t===""?"/":t},R=t=>{const e=y(t);if(e!=="/")return e;const n=U();return n===""?"/":n},I=t=>i("/apps/"+c+"/?file="+encodeURIComponent(t)),C=(t,e)=>{const n=i("/apps/files/files/"+encodeURIComponent(String(t))),r=new URLSearchParams;return r.set("dir",R(e)),r.set("editing","false"),r.set("openfile","true"),n+"?"+r.toString()},P=(t,e)=>{const n=i("/apps/"+c+"/public/"+encodeURIComponent(t));return e?n+"?file="+encodeURIComponent(e):n},L=()=>{const t=(window.location.pathname||"").match(/(?:\/index\.php)?\/s\/([^/]+)(?:\/.*)?$/);return t&&t[1]||null},x=t=>{if(!t||typeof t!="string")return null;let e;try{e=new URL(t,window.location.origin)}catch{return null}const n=e.pathname||"",r=n.match(/\/apps\/files\/files\/(\d+)\/?$/);if(!r){const s=n.match(/\/f\/(\d+)\/?$/);if(!s){const d=Number(e.searchParams.get("fileid")||"");return Number.isFinite(d)&&d>0?d:null}const l=parseInt(s[1],10);return Number.isFinite(l)&&l>0?l:null}const a=parseInt(r[1],10);return Number.isFinite(a)&&a>0?a:null},A=()=>{const t=(window.location.pathname||"").match(/\/apps\/files\/files\/(\d+)\/?$/);if(!t)return null;const e=parseInt(t[1],10);return Number.isFinite(e)&&e>0?e:null},T=t=>{if(!t||typeof t!="string")return null;let e;try{e=new URL(t,window.location.origin)}catch{return null}const n=(e.pathname||"").match(/(?:\/index\.php)?\/s\/([^/]+)\/download\/?$/);if(!n)return null;const r=(e.searchParams.get("files")||"").trim();if(!g(r))return null;const a=(e.searchParams.get("path")||"/").trim()||"/";return{token:n[1],path:w(a,r)}},j=t=>{if(!t||typeof t!="string")return null;let e;try{e=new URL(t,window.location.origin)}catch{return null}let n;try{n=decodeURIComponent(e.pathname||"")}catch{return null}if(!n.endsWith(".pad"))return null;const r=["/remote.php/dav/files/","/public.php/dav/files/"].find(d=>n.includes(d));if(!r)return null;const a=n.indexOf(r),s=n.substring(a+r.length),l=s.indexOf("/");return l===-1?null:"/"+s.substring(l+1)},o=new Map,S=50,v=300*1e3,k=async t=>{const e=String(t),n=f(e);if(n!==null)return n;const r=i("/apps/"+c+"/api/v1/pads/resolve")+"?fileId="+encodeURIComponent(e),a=p(r,{method:"GET",headers:{Accept:"application/json"}},"Pad resolve failed.").catch(s=>{throw o.delete(e),s});return m(e,a),a},O=async t=>{const e="path:"+String(t),n=f(e);if(n!==null)return n;const r=i("/apps/"+c+"/api/v1/pads/resolve")+"?file="+encodeURIComponent(t),a=p(r,{method:"GET",headers:{Accept:"application/json"}},"Pad resolve by path failed.").catch(s=>{throw o.delete(e),s});return m(e,a),a},F=async(t,e)=>{const n=i("/apps/"+c+"/api/v1/pads/from-url"),r=new URLSearchParams;return r.set("file",t),r.set("padUrl",e),p(n,{method:"POST",headers:h(),body:r.toString()},"Could not import public pad URL.")},N=async t=>{const e=i("/apps/"+c+"/api/v1/pads/find-original/"+encodeURIComponent(String(t)));return p(e,{method:"GET",headers:{Accept:"application/json"}},"Lookup failed.")},$=async t=>{const e=i("/apps/"+c+"/api/v1/pads/recover-from-snapshot/"+encodeURIComponent(String(t))),n=await p(e,{method:"POST",headers:{Accept:"application/json",requesttoken:u()}},"Recovery failed.");return o.delete(String(t)),n},E=async t=>{const e=i("/apps/"+c+"/api/v1/pads"),n=new URLSearchParams;return n.set("file",t),n.set("accessMode","public"),p(e,{method:"POST",headers:h(),body:n.toString()},"Could not create public pad.")},h=()=>({Accept:"application/json","Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",requesttoken:u()}),f=t=>{const e=o.get(t);return e?Date.now()-e.createdAt>v?(o.delete(t),null):e.request:null},m=(t,e)=>{if(!o.has(t)&&o.size>=S){const n=o.keys().next().value;n!==void 0&&o.delete(n)}o.set(t,{createdAt:Date.now(),request:e})},p=async(t,e,n)=>{const r=await fetch(t,{...e,credentials:"same-origin"}),a=await r.json().catch(()=>({}));if(!r.ok){const s=new Error(a&&a.message||n);throw a&&typeof a.code=="string"&&(s.code=a.code),s.status=r.status,s}return a};export{L as a,k as b,O as c,A as d,I as e,C as f,U as g,E as h,F as i,g as j,T as k,j as l,$ as m,w as n,N as o,x as p,R as r,P as v};
//# sourceMappingURL=api-client-BXEMiUh7.chunk.mjs.map