isdata-customer-sdk 0.3.2 → 0.3.4

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/esm/utils.js CHANGED
@@ -1 +1 @@
1
- import e from"axios";var t={},n=Object.prototype.hasOwnProperty;function r(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}function o(e){try{return encodeURIComponent(e)}catch(e){return null}}t.stringify=function(e,t){t=t||"";var r,s,a=[];for(s in"string"!=typeof t&&(t="?"),e)if(n.call(e,s)){if((r=e[s])||null!=r&&!isNaN(r)||(r=""),s=o(s),r=o(r),null===s||null===r)continue;a.push(s+"="+r)}return a.length?t+a.join("&"):""},t.parse=function(e){for(var t,n=/([^=?#&]+)=?([^&]*)/g,o={};t=n.exec(e);){var s=r(t[1]),a=r(t[2]);null===s||null===a||s in o||(o[s]=a)}return o};const s="development"===process.env.NODE_ENV,a="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;window.isDevopmentMode=s,window.isOnlineDevelopmentMode=a;var i=((n="")=>{n&&(n.startsWith("/")&&(n=n.slice(1,n.length)),n.endsWith("/")&&(n=n.slice(0,-1)));const r=e.create({baseURL:`/${n?n+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(e){return e>=200&&e<300},headers:window.location.search&&t.parse(window.location.search).token||window.token?{token:t.parse(window.location.search).token||window.token}:{}});let o=r.post;return r.post=(e,t,n)=>{let s=window.VITE_SERVICE_BASE_URL||"";if(s){let a=s+e;return o.call(r,a,t,n)}return o.call(r,e,t,n)},r.interceptors.request.use(e=>{if(!a&&s){let t=window.mockData.PORTAL_SERVER_ADDRESS,n=window.mockData.VITE_SERVICE_BASE_URL;e.url=`${t}${n}${e.url}`}return e},e=>Promise.reject(e)),r.defaults.headers.post["Content-Type"]="application/json",r.interceptors.response.use(e=>{let{data:t}=e;return"string"==typeof t&&(t=JSON.parse(t)),!t||200===t.status||t instanceof Blob?t instanceof Blob?(e.data=t,e):(e.data=t&&t.result,e):Promise.reject(e)},e=>{if(!e.response||401!==e.response.status)return Promise.reject(e.response)}),r})(window.prefixPath||"");const c=(e,t=200)=>i.post(`/asset/getAssetData?asset_id=${e}&count=${t}`,{filters:[]}),l=(e,t)=>{try{const n=new URL(e).searchParams.get(t);return n&&-1!==n.indexOf("#")?n.split("#")[0]:n}catch(e){return console.error("URL 格式错误:",e),""}},u=async(e,t)=>{try{const n=await fetch(e);if(!n.ok)throw new Error(`网络请求失败: ${n.status} ${n.statusText}`);const r=await n.blob(),o=t||p(e);return new File([r],o,{type:r.type,lastModified:Date.now()})}catch(e){throw console.error("创建 File 失败:",e),e}},p=e=>{try{return new URL(e).pathname.split("/").pop()||"downloaded_file"}catch(e){return"downloaded_file"}},d=(e,t)=>e.filter(e=>!t.includes(e)),w=async e=>{try{const t=await fetch(e,{method:"GET",headers:{Range:"bytes=0-0"}});if(206!==t.status)throw new Error("不支持 Range 请求");const n=t.headers.get("Content-Range"),r=n?.match(/\/(\d+)$/)?.[1];return r?parseInt(r,10):-1}catch(e){return console.error("获取文件大小失败:",e),-1}},f=e=>{let t=/\$L\{([^}]+)\}/g.exec(e);return t?t[1]:e},h=(e,t)=>{let n=e;for(;n;){if(n.classList&&n.classList.contains(t))return n;n=n.parentElement}return null},E=e=>{try{return new URL(e,window.location.href).search.length>0}catch(e){return!1}},R=async()=>{let e=await i.post("/ext/getClientIp"),t=e?.data?.clientIp;return t},y=async(e,t)=>await i.post(e,t),_=e=>{if(!e)return;let t;t="[object String]"===Object.prototype.toString.call(e)?JSON.parse(e):e;let n=`/storage_area/public${(t[0]||{}).url}`,r="";if(!window.isOnlineDevelopmentMode&&window.isDevopmentMode){r=window.mockData.PORTAL_SERVER_ADDRESS}return`${r}${n}`},m=e=>{for(const t of document.styleSheets)try{for(const n of t.cssRules||[])if(n.selectorText===e)return!0}catch(e){continue}return!1};export{u as createFileFromUrl,y as doRestPost,p as extractFilenameFromUrl,d as extractNewItems,h as findClosestAncestorByClass,R as getClientIp,w as getFileSize,f as getI18nKey,l as getUrlParamValue,_ as getWebURL,m as hasCssRule,E as hasUrlParams,c as queryAssetById};
1
+ import e from"axios";var t={},n=Object.prototype.hasOwnProperty;function r(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}function o(e){try{return encodeURIComponent(e)}catch(e){return null}}t.stringify=function(e,t){t=t||"";var r,s,a=[];for(s in"string"!=typeof t&&(t="?"),e)if(n.call(e,s)){if((r=e[s])||null!=r&&!isNaN(r)||(r=""),s=o(s),r=o(r),null===s||null===r)continue;a.push(s+"="+r)}return a.length?t+a.join("&"):""},t.parse=function(e){for(var t,n=/([^=?#&]+)=?([^&]*)/g,o={};t=n.exec(e);){var s=r(t[1]),a=r(t[2]);null===s||null===a||s in o||(o[s]=a)}return o};const s="development"===process.env.NODE_ENV,a="true"===process.env.VUE_APP_ONLINE_DEVELOPMENT_MODE||"true"===process.env.REACT_APP_ONLINE_DEVELOPMENT_MODE;window.isDevopmentMode=s,window.isOnlineDevelopmentMode=a;var i=((n="")=>{n&&(n.startsWith("/")&&(n=n.slice(1,n.length)),n.endsWith("/")&&(n=n.slice(0,-1)));const r=e.create({baseURL:`/${n?n+"/":""}sdata/rest`,timeout:6e4,validateStatus:function(e){return e>=200&&e<300},headers:window.location.search&&t.parse(window.location.search).token||window.token?{token:t.parse(window.location.search).token||window.token}:{}});let o=r.post;return r.post=(e,t,n)=>{let s=window.VITE_SERVICE_BASE_URL||"";if(s){let a=s+e;return o.call(r,a,t,n)}return o.call(r,e,t,n)},r.interceptors.request.use(e=>{if(!a&&s){let t=window.mockData.PORTAL_SERVER_ADDRESS,n=window.mockData.VITE_SERVICE_BASE_URL;e.url=`${t}${n}${e.url}`}return e},e=>Promise.reject(e)),r.defaults.headers.post["Content-Type"]="application/json",r.interceptors.response.use(e=>{let{data:t}=e;return"string"==typeof t&&(t=JSON.parse(t)),!t||200===t.status||t instanceof Blob?t instanceof Blob?(e.data=t,e):(e.data=t&&t.result,e):Promise.reject(e)},e=>{if(!e.response||401!==e.response.status)return Promise.reject(e.response)}),r})(window.prefixPath||"");const c=(e,t=200)=>i.post(`/asset/getAssetData?asset_id=${e}&count=${t}`,{filters:[]}),l=(e,t)=>{try{const n=new URL(e).searchParams.get(t);return n&&-1!==n.indexOf("#")?n.split("#")[0]:n}catch(e){return console.error("URL 格式错误:",e),""}},u=async(e,t)=>{try{const n=await fetch(e);if(!n.ok)throw new Error(`网络请求失败: ${n.status} ${n.statusText}`);const r=await n.blob(),o=t||d(e);return new File([r],o,{type:r.type,lastModified:Date.now()})}catch(e){throw console.error("创建 File 失败:",e),e}},d=e=>{try{return new URL(e).pathname.split("/").pop()||"downloaded_file"}catch(e){return"downloaded_file"}},p=(e,t)=>e.filter(e=>!t.includes(e)),w=async e=>{try{const t=await fetch(e,{method:"GET",headers:{Range:"bytes=0-0"}});if(206!==t.status)throw new Error("不支持 Range 请求");const n=t.headers.get("Content-Range"),r=n?.match(/\/(\d+)$/)?.[1];return r?parseInt(r,10):-1}catch(e){return console.error("获取文件大小失败:",e),-1}},f=e=>{let t=/\$L\{([^}]+)\}/g.exec(e);return t?t[1]:e},h=(e,t)=>{let n=e;for(;n;){if(n.classList&&n.classList.contains(t))return n;n=n.parentElement}return null},E=e=>{try{return new URL(e,window.location.href).search.length>0}catch(e){return!1}},m=async()=>{let e=await i.post("/ext/getClientIp"),t=e?.data?.clientIp;return t},y=async(e,t)=>await i.post(e,t),R=e=>{if(!e)return;let t;t="[object String]"===Object.prototype.toString.call(e)?JSON.parse(e):e;let n=`/storage_area/public${(t[0]||{}).url}`,r="";if(!window.isOnlineDevelopmentMode&&window.isDevopmentMode){r=window.mockData.PORTAL_SERVER_ADDRESS}return`${r}${n}`},g=e=>{if(!e)return;let t;return t="[object String]"===Object.prototype.toString.call(e)?JSON.parse(e):e,(t[0]||{}).name},_=e=>{for(const t of document.styleSheets)try{for(const n of t.cssRules||[])if(n.selectorText===e)return!0}catch(e){continue}return!1},O=(e,t)=>{L(R(e),g(e),t)};async function L(e,t,n={}){try{t||(t=function(e){const t=e.split("?")[0].split("#")[0];return t.substring(t.lastIndexOf("/")+1)||"downloaded-file"}(e));const r=await fetch(e,{method:"GET",headers:new Headers(n)});if(!r.ok)throw new Error(`下载失败: HTTP ${r.status} ${r.statusText}`);const o=r.headers.get("Content-Disposition");if(o){const e=o.match(/filename="?(.+)"?/i);e&&e[1]&&(t=e[1])}const s=await r.blob(),a=URL.createObjectURL(s),i=document.createElement("a");i.href=a,i.download=t,document.body.appendChild(i),i.click(),setTimeout(()=>{document.body.removeChild(i),URL.revokeObjectURL(a)},100)}catch(e){throw console.error("下载出错:",e),e}}export{u as createFileFromUrl,y as doRestPost,O as downloadFile,L as downloadWithFetch,d as extractFilenameFromUrl,p as extractNewItems,h as findClosestAncestorByClass,m as getClientIp,g as getFileNameByWebURL,w as getFileSize,f as getI18nKey,l as getUrlParamValue,R as getWebURL,_ as hasCssRule,E as hasUrlParams,c as queryAssetById};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isdata-customer-sdk",
3
- "version": "0.3.02",
3
+ "version": "0.3.04",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",