@wellesley/uploads 1.0.191 → 1.0.192
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 Td,handleBasicResponse as dr,usePostApiV1UploadsMutation as Od,useDeleteApiV1UploadsByIdMutation as Cd,usePostApiV1UploadsByIdMetaMutation as Ud}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@1.0.
|
|
1
|
+
import{api as Td,handleBasicResponse as dr,usePostApiV1UploadsMutation as Od,useDeleteApiV1UploadsByIdMutation as Cd,usePostApiV1UploadsByIdMetaMutation as Ud}from"https://cdn.jsdelivr.net/npm/@wellesley/openapi@1.0.307";import{useSelector as Yt}from"https://cdn.jsdelivr.net/npm/react-redux@9.1.0/+esm";import{toast as Gi}from"https://cdn.jsdelivr.net/npm/react-toastify@10.0.5/+esm";import{logErrorToSentry as bd}from"https://cdn.jsdelivr.net/npm/@wellesley/sentry@1.0.173";import{platformSettingsSlice as Jt}from"https://cdn.jsdelivr.net/npm/@wellesley/settings@1.0.264";import Md,{useRef as Fd,useState as Pd,useEffect as Bd,forwardRef as Wd}from"https://cdn.jsdelivr.net/npm/react@18.2.0/+esm";import{useIsMobile as Dd}from"https://cdn.jsdelivr.net/npm/@wellesley/ui@1.0.269";const Nd=Td.enhanceEndpoints({endpoints:{postApiV1UploadsByIdMeta:{async onQueryStarted(n,{queryFulfilled:t}){await dr(t,"Updated")}},postApiV1UploadsList:{async onQueryStarted(n,{queryFulfilled:t}){await dr(t)}},postApiV1UploadsBatch:{async onQueryStarted(n,{queryFulfilled:t}){await dr(t,"Deleted")}},putApiV1UploadsByIdTags:{async onQueryStarted(n,{queryFulfilled:t}){await dr(t)}}}}),{usePostApiV1UploadsByIdMetaMutation:v_,usePostApiV1UploadsListMutation:w_,usePutApiV1UploadsByIdTagsMutation:x_,usePostApiV1UploadsBatchMutation:m_}=Nd;var Xt=(n=>(n.done="done",n.inprogress="inprogress",n))(Xt||{}),Ct=(n=>(n.image="image",n.video="video",n.audio="audio",n))(Ct||{}),Uo=(n=>(n.post="$post",n.album="$album",n.avatar="$avatar",n.header="$header",n))(Uo||{});const Hi=n=>{const t=n.toLowerCase().match(/\.([a-zA-Z0-9]{2,4})(\?|$)+/);return t?t[1]:void 0},$d=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},zd=n=>n.replace(/\.[^.]*$/,""),bo=()=>"object"!=typeof window,Gd=()=>!bo()&&/iPhone|iPod|iPad/gi.test(window.navigator.userAgent),So=["debug","info","warn","error"],Hd=(n,t)=>{const r=So.indexOf(n);return So.indexOf(t)>=r},_r=(n,t,r,...e)=>{Hd(t,n)&&console.log(`[${n}] ${r}`,...e)},qd=()=>null==window?void 0:window.localStorage.getItem("logger_lvl"),Kd=(n=!bo()&&qd()||"warn")=>{let t=n;return{debug:(n,...r)=>_r("debug",t,n,...r),info:(n,...r)=>_r("info",t,n,...r),warn:(n,...r)=>_r("warn",t,n,...r),error:(n,...r)=>(bd(n,...r),_r("error",t,n,...r)),setLevel:n=>{t=n},getLevel:()=>t}},Mo=Kd(),Fo=({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=zd(t);(!n||!i||!o||!a)&&e(),r({src:a,name:f,width:o,height:i,duration:Math.floor(n)})},o=()=>{Mo.warn("Failed to load video"),r(null)};return Gd()&&u.load(),u.addEventListener("error",o),u.addEventListener("loadeddata",i),()=>{u.removeEventListener("error",o),u.removeEventListener("loadeddata",i)}})),Po=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=()=>{Mo.warn("Failed to load image"),r(null),URL.revokeObjectURL(u)},e.src=u})),Lo=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`},Zd=async({media:n,docPolicy:t,imgPolicy:r,videoPolicy:e,audioPolicy:u})=>{if(!r||!e)return"Media policy is not defined";const i={IMAGE:r.extensions,VIDEO:e.extensions,AUDIO:u.extensions,DOCUMENT:t.extensions},o=Hi(n.file.name)||"",a=Object.keys(i).find((n=>{var t;return null==(t=i[n])?void 0:t.includes(o)}));if(!a)return`Extension ${o} is not supported`;const f="VIDEO"===a;if("IMAGE"===a){const t=await Po(n.file),e=n.file.size>r.maxSize,u=t&&Math.max(t.width,t.height)>r.maxResolution,i=t&&t.width*t.height>r.maxMatrix;switch(!0){case e:return`Image is too big. Max size is ${Lo(r.maxSize)}`;case u:return`Image resolution is too high. Max resolution is ${r.maxResolution} 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 ${r.maxMatrix} pixels`}}if(f){const t=await Fo({src:n.objectUrl}),r=t&&t.duration>e.maxDuration,u=t&&Math.max(t.width,t.height)>e.maxResolution,i=n.file.size>e.maxSize,o=t&&t.width*t.height>e.maxMatrix;switch(!0){case r:return`Video is too long. Max duration is ${e.maxDuration} seconds`;case i:return`Video is too big. Max size is ${Lo(e.maxSize)}`;case u:return`Video resolution is too high. Max resolution is ${e.maxResolution} 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 ${e.maxMatrix} pixels`}}},Yd=()=>{const[n]=Od(),t=new AbortController,r=t.signal,e=Yt(Jt.selectors.selectImagePolicy),u=Yt(Jt.selectors.selectVideoPolicy),i=Yt(Jt.selectors.selectDocPolicy),o=Yt(Jt.selectors.selectAudioPolicy);return[async({media:t,tag:a,onError:f,onUpload:c})=>{var l;const s=Hi(t.file.name),p=await Zd({imgPolicy:e,docPolicy:i,videoPolicy:u,audioPolicy:o,media:t});if(p)return Gi.error(p),void(null==f||f());try{const e=await n({createUpload:{extension:s,tags:[a],meta:{name:t.file.name}}});if("error"in e)throw new Error(e.error);const u=null==(l=e.data)?void 0:l.uri;return await $d({url:u,method:"PUT",body:t.file,signal:r}),null==c||c(),e.data.upload.uploadId}catch(n){null==f||f(n),Gi(`Could not upload file. ${n}`)}},()=>t.abort("Upload canceled")]};var Eo,vr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},me={exports:{}},Jd=me.exports;
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Lodash <https://lodash.com/>
|