@wellesley/uploads 1.0.26 → 1.0.29
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/index.mjs +1 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{api as x_,handleBasicResponse as cr,usePostApiV1UploadsMutation as m_,useDeleteApiV1UploadsByIdMutation as A_,usePostApiV1UploadsByIdMetaMutation as y_}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@1.0.
|
|
1
|
+
import{api as x_,handleBasicResponse as cr,usePostApiV1UploadsMutation as m_,useDeleteApiV1UploadsByIdMutation as A_,usePostApiV1UploadsByIdMetaMutation as y_}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@1.0.144";import{toast as Wi}from"https://cdn.jsdelivr.net/npm/react-toastify@10.0.5/+esm";import{logErrorToSentry as I_}from"https://cdn.jsdelivr.net/npm/@wellesley/sentry@1.0.17";import{useSelector as Pi}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{useRef as L_,useState as R_,useEffect as S_}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{instanceInfoSlice as Bi}from"https://cdn.jsdelivr.net/npm/@wellesley/instanceinfo@1.0.17";const E_=x_.enhanceEndpoints({endpoints:{postApiV1UploadsByIdMeta:{async onQueryStarted(n,{queryFulfilled:t}){await cr(t,"Updated")}},postApiV1UploadsList:{async onQueryStarted(n,{queryFulfilled:t}){await cr(t)}},deleteApiV1UploadsBatch:{async onQueryStarted(n,{queryFulfilled:t}){await cr(t,"Deleted")}},putApiV1UploadsByIdTags:{async onQueryStarted(n,{queryFulfilled:t}){await cr(t)}}}}),{usePostApiV1UploadsByIdMetaMutation:j_,usePostApiV1UploadsListMutation:nd,usePutApiV1UploadsByIdTagsMutation:td,useDeleteApiV1UploadsBatchMutation:ed}=E_;var Zt=(n=>(n.done="done",n.inprogress="inprogress",n))(Zt||{}),_e=(n=>(n.image="image",n.video="video",n.audio="audio",n))(_e||{}),yo=(n=>(n.post="$post",n.album="$album",n.avatar="$avatar",n.header="$header",n))(yo||{});const Io=n=>{const t=n.toLowerCase().match(/\.([a-zA-Z0-9]{2,4})(\?|$)+/);return t?t[1]:void 0},T_=async({url:n,...t})=>{const r=await fetch(n,t);if(!r.ok)throw new Error(r.statusText);if("PUT"===t.method)return;const e=await r.json(),u=e;if(u.errorCode)throw new Error(u.message);return e},C_=n=>n.replace(/\.[^.]*$/,""),Lo=()=>"object"!=typeof window,O_=()=>!Lo()&&/iPhone|iPod|iPad/gi.test(window.navigator.userAgent),xo=["debug","info","warn","error"],U_=(n,t)=>{const r=xo.indexOf(n);return xo.indexOf(t)>=r},hr=(n,t,r,...e)=>{U_(t,n)&&console.log(`[${n}] ${r}`,...e)},b_=()=>null==window?void 0:window.localStorage.getItem("logger_lvl"),F_=(n=!Lo()&&b_()||"warn")=>{let t=n;return{debug:(n,...r)=>hr("debug",t,n,...r),info:(n,...r)=>hr("info",t,n,...r),warn:(n,...r)=>hr("warn",t,n,...r),error:(n,...r)=>(I_(n,...r),hr("error",t,n,...r)),setLevel:n=>{t=n},getLevel:()=>t}},Ro=F_(),M_=({src:n,name:t=""})=>new Promise(((r,e)=>{const u=document.createElement("video");u.src=n;const i=()=>{const{duration:n,videoHeight:i,videoWidth:o,src:a}=u,f=C_(t);(!n||!i||!o||!a)&&e(),r({src:a,name:f,width:o,height:i,duration:Math.floor(n)})},o=()=>{Ro.warn("Failed to load video"),r(null)};return O_()&&u.load(),u.addEventListener("error",o),u.addEventListener("loadeddata",i),()=>{u.removeEventListener("error",o),u.removeEventListener("loadeddata",i)}})),P_=n=>new Promise(((t,r)=>{const e=new Image,u=URL.createObjectURL(n);e.onload=()=>{t({width:e.naturalWidth,height:e.naturalHeight}),URL.revokeObjectURL(u)},e.onerror=()=>{Ro.warn("Failed to load image"),r(null),URL.revokeObjectURL(u)},e.src=u})),mo=n=>{if(!n)return;const t="number"==typeof n?n:parseInt(n,10);if(isNaN(t))throw new Error("Can not get number from income argument");const r=t/1048576;return`${Math.floor(r)} MB`},B_=async({media:n,config:t})=>{if(!t)return"Instance configuration is missing";const r={IMAGE:t.image_extensions,VIDEO:t.video_extensions,AUDIO:t.audio_extensions,DOCUMENT:t.doc_extensions},e=Io(n.file.name)||"",u=Object.keys(r).find((n=>{var t;return null==(t=r[n])?void 0:t.includes(e)}));if(!u)return`Extenssion ${e} is not supported`;const i="VIDEO"===u;if("IMAGE"===u){const r=await P_(n.file),e=n.file.size>t.image_size_limit,u=r&&Math.max(r.width,r.height)>t.image_resolution_limit,i=r&&r.width*r.height>t.image_matrix_limit;switch(!0){case e:return`Image is too big. Max size is ${mo(t.image_size_limit)}`;case u:return`Image resolution is too high. Max resolution is ${t.image_resolution_limit} pixels`;case i:return`The uploaded image exceeds the maximum size allowed. Please choose an image with smaller dimensions or reduce the resolution and try again. Max resolution is ${t.image_matrix_limit} pixels`}}if(i){const r=await M_({src:n.objectUrl}),e=r&&r.duration>t.video_duration_limit,u=r&&Math.max(r.width,r.height)>t.video_resolution_limit,i=n.file.size>t.video_size_limit,o=r&&r.width*r.height>t.video_matrix_limit;switch(!0){case e:return`Video is too long. Max duration is ${t.video_duration_limit} seconds`;case i:return`Video is too big. Max size is ${mo(t.video_size_limit)}`;case u:return`Video resolution is too high. Max resolution is ${t.video_resolution_limit} pixels`;case o:return`The uploaded video exceeds the maximum size allowed. Please choose a video with smaller dimensions or reduce the resolution and try again. Max resolution is ${t.image_matrix_limit} pixels`}}},W_=({config:n})=>{const[t]=m_(),r=new AbortController,e=r.signal;return[async({media:r,tag:u,onError:i,onUpload:o})=>{var a;const f=Io(r.file.name),c=await B_({config:n,media:r});if(c)return Wi.error(c),void(null==i||i());try{const n=await t({request1:{extension:f,tags:[u],meta:{name:r.file.name}}});if("error"in n)throw new Error(n.error);const i=null==(a=n.data)?void 0:a.uri;return await T_({url:i,method:"PUT",body:r.file,signal:e}),null==o||o(),n.data.upload.uploadId}catch(n){null==i||i(n),Wi(`Could not upload file. ${n}`)}},()=>r.abort("Upload canceled")]};var Ao,gr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},de={exports:{}},D_=de.exports;
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Lodash <https://lodash.com/>
|