@mateosuarezdev/brpc 1.0.67 → 1.0.68
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/storage/index.js +2 -2
- package/dist/storage/types.d.ts +29 -1
- package/package.json +1 -1
package/dist/storage/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var S=($)=>$.startsWith("image/"),j=($)=>$.startsWith("video/"),q=($)=>$.startsWith("audio/"),F=($)=>$.startsWith("text/")||$.includes("pdf")||$.includes("word")||$.includes("sheet")||$.includes("presentation")||$.includes("opendocument")||$==="application/rtf",N=($)=>$.includes("zip")||$.includes("rar")||$.includes("tar")||$.includes("7z")||$.includes("gzip"),T=($)=>$==="application/javascript"||$==="application/json"||$==="text/html"||$==="text/css"||$==="application/xml"||$.includes("javascript"),z=($)=>$.startsWith("font/")||$.includes("font"),O=($)=>{if(!$)return"other";let W=$.toLowerCase();if(S(W))return"image";if(j(W))return"video";if(q(W))return"audio";if(F(W))return"document";if(N(W))return"archive";if(T(W))return"code";if(z(W))return"font";return"other"},_={isImage:S,isVideo:j,isAudio:q,isDocument:F,isArchive:N,isCode:T,isFont:z};function o(){let W=Buffer.from("Hello, this is a test file for S3 upload!","utf-8");return new File([W],"test.txt",{type:"text/plain"})}function r($,W){if($.url)return $.url;if($.key)if($.isPrivate)return`/storage/${$.key}`;else return`https://${W?.bucket??process.env.AWS_BUCKET}.s3.amazonaws.com/${$.key}`;throw Error("Invalid storage object")}function G($,W){if(!$||$<1||!W||W<1)return"1:1";let H=(L,Q)=>Q===0?L:H(Q,L%Q),J=H($,W);return`${$/J}:${W/J}`}function a($,W){if(!$||!W||$<1||W<1)return"1:1";let H=$/W,J=[{ratio:1,label:"1:1"},{ratio:0.8,label:"4:5"},{ratio:0.75,label:"3:4"},{ratio:0.6666666666666666,label:"2:3"},{ratio:0.5625,label:"9:16"},{ratio:1.5,label:"3:2"},{ratio:1.3333333333333333,label:"4:3"},{ratio:1.7777777777777777,label:"16:9"},{ratio:2.3333333333333335,label:"21:9"}],L=0.03;for(let{ratio:X,label:Z}of J)if(Math.abs(H-X)/X<L)return Z;let Q=(X,Z)=>Z===0?X:Q(Z,X%Z),Y=Q($,W);return`${$/Y}:${W/Y}`}class M extends Error{code;clientCode;httpStatus;data;cause;static STATUS_MAP={BAD_REQUEST:400,UNAUTHORIZED:401,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_SUPPORTED:405,TIMEOUT:408,CONFLICT:409,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,UNPROCESSABLE_CONTENT:422,TOO_MANY_REQUESTS:429,CLIENT_CLOSED_REQUEST:499,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504};constructor($){super($.message);if(this.name="BRPCError",this.code=$.code,this.clientCode=$.clientCode,this.httpStatus=M.STATUS_MAP[$.code],this.data=$.data,this.cause=$.cause,Error.captureStackTrace)Error.captureStackTrace(this,M)}toJSON(){return{name:this.name,code:this.code,clientCode:this.clientCode,message:this.message,data:this.data,httpStatus:this.httpStatus}}static badRequest($,W,H){return new M({code:"BAD_REQUEST",message:$,clientCode:W,data:H})}static unauthorized($="Unauthorized",W,H){return new M({code:"UNAUTHORIZED",message:$,clientCode:W,data:H})}static forbidden($="Forbidden",W,H){return new M({code:"FORBIDDEN",message:$,clientCode:W,data:H})}static notFound($="Not Found",W,H){return new M({code:"NOT_FOUND",message:$,clientCode:W,data:H})}static preconditionFailed($="Precondition failed",W,H){return new M({code:"NOT_FOUND",message:$,clientCode:W,data:H})}static conflict($,W,H){return new M({code:"CONFLICT",message:$,clientCode:W,data:H})}static unprocessableContent($,W,H){return new M({code:"UNPROCESSABLE_CONTENT",message:$,clientCode:W,data:H})}static tooManyRequests($="Too many requests",W,H){return new M({code:"TOO_MANY_REQUESTS",message:$,clientCode:W,data:H})}static internalServerError($="Internal Server Error",W,H){return new M({code:"INTERNAL_SERVER_ERROR",message:$,clientCode:W,data:H})}static timeout($="Request timeout",W,H){return new M({code:"TIMEOUT",message:$,clientCode:W,data:H})}}import P from"sharp";var w={xs:200,sm:400,md:800,lg:1200},V=1920;async function D($,W,H,J,L){try{let{data:Q,info:Y}=await P($,{limitInputPixels:1e8}).rotate().resize({width:W,height:W,fit:"inside",withoutEnlargement:!0}).webp({quality:H}).toBuffer({resolveWithObject:!0});return{buffer:Q,object:{name:J.replace(/\.[^/.]+$/,".webp"),resolvedType:"image",metadata:{type:"image/webp",size:Q.length,extension:".webp",width:Y.width,height:Y.height,aspectRatio:Y.width&&Y.height?Y.width/Y.height:1,aspectRatioStr:Y.width&&Y.height?G(Y.width,Y.height):"1:1",acl:L}}}}catch(Q){throw M.conflict(`Failed to optimize image: ${Q instanceof Error?Q.message:"Unknown error"}`)}}async function I($){if(!$)throw M.conflict("A file must be provided");let W,H="unknown.webp";if(typeof $==="string"){if(console.log("I'm going to fail here for file",$),!$.startsWith("data:"))throw console.log("I never got here"),M.conflict("Invalid base64 format");let[,J]=$.split(",");if(!J)throw M.conflict("Invalid base64 data");W=Buffer.from(J,"base64")}else{if(!_.isImage($.type))throw M.conflict("File must be an image");let J=await $.arrayBuffer();W=Buffer.from(J),H=$.name??H}return{buffer:W,name:H}}async function L0($,{size:W,quality:H,acl:J}={}){let L=await I($);return D(L.buffer,W??V,H??80,L.name,J??"public-read")}async function M0($,{name:W="unknown.webp",size:H,quality:J,acl:L}={}){if(!$?.length)throw M.conflict("A buffer must be provided");return D($,H??V,J??80,W,L??"public-read")}async function k($,{quality:W=80,acl:H="public-read"}={}){console.log("Going to normalizeImageInput");let J=await I($);console.log("Going to processSharpImage for original");let L=await D(J.buffer,V,W,J.name,H);console.log("Going to processSharpImage for variantsEntries");let Q=await Promise.all(Object.entries(w).map(async([Y,X])=>{let Z=await D(J.buffer,X,W,J.name,H);return[Y,Z]}));return{original:L,variants:Object.fromEntries(Q)}}import h from"sharp";import{randomUUID as b}from"crypto";import{extname as C}from"path";async function v($,W,H){if(!W)return{data:null,error:Error("File not found")};let J=$.replace(/^\/+|\/+$/g,""),L=C(W.name),Q=`${b()}${L}`,Y=`${J}/${Q}`,X=`./buckets/${J}/${Q}`;try{let Z=await Bun.write(X,W);return{data:{key:Y,file:W,bytesWritten:Z},error:null}}catch(Z){return{data:null,error:Error(`Failed to upload ${W.name} to local filesystem`)}}}async function g($,W,H){if(!W||W.length===0)return[];let J=W.map((Q)=>{let Y=H?.(Q)??Q.name;return v($,Q,Y)});return await Promise.all(J)}async function m($){let W=Bun.file(`./buckets/${$}`);if(!await W.exists())return null;return W}async function u($){let W=Bun.file(`./buckets/${$}`);if(!await W.exists())return!1;return await W.delete(),!0}var U={uploadOne:v,uploadMany:g,getOne:m,deleteOne:u};async function D0($){let W=`./cache/images/${$.key}_${$.width}_${$.quality}.webp`,H=await U.getOne(W);if(H){if(!_.isImage(H.type))return null;return H}let J=$.key,L=await U.getOne(J);if(!L)return null;if(!_.isImage(L.type))return null;let Q=await L.arrayBuffer(),Y=await h(Q).resize($.width,null,{withoutEnlargement:!0}).webp({quality:$.quality??75}).toBuffer();await Bun.write(W,Y);let X=Bun.file(W);if(!await X.exists())return null;return X}import c from"sharp";async function j0($){if(!$?.length)return null;try{let W=await c($).metadata(),H=W.width??0,J=W.height??0,L=W.height>0?H/J:1;return{type:`image/${W.format}`,size:W.size??0,extension:`.${W.format}`,width:H,height:J,aspectRatio:L,aspectRatioStr:G(H,J)}}catch(W){return console.warn("Failed to read image metadata:",W),null}}var R=process.env.AWS_FOLDER,B=R?`${R}/`:"";var{s3:y}=globalThis.Bun;import{extname as d}from"path";async function A($,W,H){let J="buffer"in W?W:{buffer:W,object:{name:W.name,resolvedType:O(W.type),metadata:{type:W.type,extension:d(W.name),size:W.size,acl:H?.acl??"public-read"}}};if("buffer"in W){if(!W.object?.name||!W.object?.metadata)throw M.badRequest("Complete metadata required when uploading buffer")}let L=$.length>1?`${$.replace(/^\/+|\/+$/g,"")}/`:"",Q=J.object.metadata.extension.startsWith(".")?J.object.metadata.extension:`.${J.object.metadata.extension}`,Y=J.object.name?J.object.name:`${crypto.randomUUID()}${Q}`,X=`${B}${L}${Y}`,Z=y.file(X),K=J?.object?.metadata?.acl??"public-read",x=K!=="public-read"&&K!=="public-read-write",E=await Z.write(J.buffer,{acl:K,type:J.object.metadata.type});return{uploadedBy:H?.uploadedBy??null,key:X,url:null,name:J.object.name,thumbnail:null,resolvedType:J.object.resolvedType,provider:"s3",isPrivate:x,metadata:{...J.object.metadata,size:E,acl:K},isActive:!0}}async function k0($,W,H={throwIf:"any"}){let J=await Promise.allSettled(W.map((Y)=>A($,Y,{acl:H?.acl,uploadedBy:H?.uploadedBy}))),L=[],Q=[];if(J.forEach((Y)=>{if(Y.status==="fulfilled"){if(L.push(Y.value),H?.externalKeys)H.externalKeys.push(Y.value.key)}else Q.push(Y.reason)}),H?.throwIf==="any"&&Q.length>0||H?.throwIf==="all"&&Q.length===W.length)throw M.internalServerError(`Upload failed: ${Q.length} of ${W.length}`);return{data:L,errors:Q.length?Q:void 0}}async function f($,W,H){let J=H?.baseId??crypto.randomUUID(),L=W.original.object.metadata.extension,Q=await A($,{...W.original,object:{...W.original.object,name:`${J}${L}`}},H),Y=await Promise.all(Object.entries(W.variants).map(async([X,Z])=>{if(!Z)return[X,null];let K=Z.object.metadata.extension,x=await A($,{...Z,object:{...Z.object,name:`${J}_${X}${K}`}},H);return[X,x]}));return{original:Q,variants:Object.fromEntries(Y.filter(([,X])=>X!==null))}}async function v0($,W,H){if(Array.isArray(W))throw Error("File can't be an array, pass a single file");let J=await k(W,{quality:H?.quality,acl:H?.acl});return f($,J,{acl:H?.acl,uploadedBy:H?.uploadedBy})}var{s3:p}=globalThis.Bun;async function n($,W){if(!$||typeof $!=="string")throw M.badRequest("Key is required");let H=$.trim();if(!H||H.length===0)throw M.badRequest("Key must be a non-empty string");try{return await p.delete($),{key:$,deleted:!0,error:null}}catch(J){return{key:$,deleted:!1,error:J}}}async function P0($,W){return(await Promise.allSettled($.map((J)=>n(J,W)))).map((J,L)=>{if(J.status==="fulfilled")return J.value;return{key:$[L],deleted:!1,error:J.reason}})}var{s3:s}=globalThis.Bun;async function g0($,W={debug:!0}){try{return{exists:await s.exists($),error:null}}catch(H){if(W?.debug)console.error("There was an error checking for file existance",H);return{exists:null,error:H}}}export{A as uploadOne,k0 as uploadMany,f as uploadGeneratedVariants,M0 as optimizeImageBuffer,L0 as optimizeImage,O as mimeTypeToResolvedType,D0 as getOptimizedImage,r as getObjectUrl,j0 as getImageMetadata,a as getAspectRatioStringRound,G as getAspectRatioString,k as generateVariants,o as generateTestFile,v0 as generateAndUploadImage,_ as fileTypePredicates,n as deleteOne,P0 as deleteMany,g0 as checkFileExistance};
|
|
2
|
+
var S=($)=>$.startsWith("image/"),j=($)=>$.startsWith("video/"),q=($)=>$.startsWith("audio/"),F=($)=>$.startsWith("text/")||$.includes("pdf")||$.includes("word")||$.includes("sheet")||$.includes("presentation")||$.includes("opendocument")||$==="application/rtf",N=($)=>$.includes("zip")||$.includes("rar")||$.includes("tar")||$.includes("7z")||$.includes("gzip"),T=($)=>$==="application/javascript"||$==="application/json"||$==="text/html"||$==="text/css"||$==="application/xml"||$.includes("javascript"),z=($)=>$.startsWith("font/")||$.includes("font"),O=($)=>{if(!$)return"other";let W=$.toLowerCase();if(S(W))return"image";if(j(W))return"video";if(q(W))return"audio";if(F(W))return"document";if(N(W))return"archive";if(T(W))return"code";if(z(W))return"font";return"other"},x={isImage:S,isVideo:j,isAudio:q,isDocument:F,isArchive:N,isCode:T,isFont:z};function o(){let W=Buffer.from("Hello, this is a test file for S3 upload!","utf-8");return new File([W],"test.txt",{type:"text/plain"})}function r($,W){if($.url)return $.url;if($.key)if($.isPrivate)return`/storage/${$.key}`;else return`https://${W?.bucket??process.env.AWS_BUCKET}.s3.amazonaws.com/${$.key}`;throw Error("Invalid storage object")}function G($,W){if(!$||$<1||!W||W<1)return"1:1";let H=(L,Q)=>Q===0?L:H(Q,L%Q),J=H($,W);return`${$/J}:${W/J}`}function a($,W){if(!$||!W||$<1||W<1)return"1:1";let H=$/W,J=[{ratio:1,label:"1:1"},{ratio:0.8,label:"4:5"},{ratio:0.75,label:"3:4"},{ratio:0.6666666666666666,label:"2:3"},{ratio:0.5625,label:"9:16"},{ratio:1.5,label:"3:2"},{ratio:1.3333333333333333,label:"4:3"},{ratio:1.7777777777777777,label:"16:9"},{ratio:2.3333333333333335,label:"21:9"}],L=0.03;for(let{ratio:X,label:Z}of J)if(Math.abs(H-X)/X<L)return Z;let Q=(X,Z)=>Z===0?X:Q(Z,X%Z),Y=Q($,W);return`${$/Y}:${W/Y}`}class M extends Error{code;clientCode;httpStatus;data;cause;static STATUS_MAP={BAD_REQUEST:400,UNAUTHORIZED:401,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_SUPPORTED:405,TIMEOUT:408,CONFLICT:409,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,UNPROCESSABLE_CONTENT:422,TOO_MANY_REQUESTS:429,CLIENT_CLOSED_REQUEST:499,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504};constructor($){super($.message);if(this.name="BRPCError",this.code=$.code,this.clientCode=$.clientCode,this.httpStatus=M.STATUS_MAP[$.code],this.data=$.data,this.cause=$.cause,Error.captureStackTrace)Error.captureStackTrace(this,M)}toJSON(){return{name:this.name,code:this.code,clientCode:this.clientCode,message:this.message,data:this.data,httpStatus:this.httpStatus}}static badRequest($,W,H){return new M({code:"BAD_REQUEST",message:$,clientCode:W,data:H})}static unauthorized($="Unauthorized",W,H){return new M({code:"UNAUTHORIZED",message:$,clientCode:W,data:H})}static forbidden($="Forbidden",W,H){return new M({code:"FORBIDDEN",message:$,clientCode:W,data:H})}static notFound($="Not Found",W,H){return new M({code:"NOT_FOUND",message:$,clientCode:W,data:H})}static preconditionFailed($="Precondition failed",W,H){return new M({code:"NOT_FOUND",message:$,clientCode:W,data:H})}static conflict($,W,H){return new M({code:"CONFLICT",message:$,clientCode:W,data:H})}static unprocessableContent($,W,H){return new M({code:"UNPROCESSABLE_CONTENT",message:$,clientCode:W,data:H})}static tooManyRequests($="Too many requests",W,H){return new M({code:"TOO_MANY_REQUESTS",message:$,clientCode:W,data:H})}static internalServerError($="Internal Server Error",W,H){return new M({code:"INTERNAL_SERVER_ERROR",message:$,clientCode:W,data:H})}static timeout($="Request timeout",W,H){return new M({code:"TIMEOUT",message:$,clientCode:W,data:H})}}import P from"sharp";var w={xs:200,sm:400,md:800,lg:1200},V=1920;async function D($,W,H,J,L){try{let{data:Q,info:Y}=await P($,{limitInputPixels:1e8}).rotate().resize({width:W,height:W,fit:"inside",withoutEnlargement:!0}).webp({quality:H}).toBuffer({resolveWithObject:!0});return{buffer:Q,object:{name:J.replace(/\.[^/.]+$/,".webp"),resolvedType:"image",metadata:{type:"image/webp",size:Q.length,extension:".webp",width:Y.width,height:Y.height,aspectRatio:Y.width&&Y.height?Y.width/Y.height:1,aspectRatioStr:Y.width&&Y.height?G(Y.width,Y.height):"1:1",acl:L}}}}catch(Q){throw M.conflict(`Failed to optimize image: ${Q instanceof Error?Q.message:"Unknown error"}`)}}async function I($){if(!$)throw M.conflict("A file must be provided");let W,H="unknown.webp";if(typeof $==="string"){if(console.log("I'm going to fail here for file",$),!$.startsWith("data:"))throw console.log("I never got here"),M.conflict("Invalid base64 format");let[,J]=$.split(",");if(!J)throw M.conflict("Invalid base64 data");W=Buffer.from(J,"base64")}else{if(!x.isImage($.type))throw M.conflict("File must be an image");let J=await $.arrayBuffer();W=Buffer.from(J),H=$.name??H}return{buffer:W,name:H}}async function L0($,{size:W,quality:H,acl:J}={}){let L=await I($);return D(L.buffer,W??V,H??80,L.name,J??"public-read")}async function M0($,{name:W="unknown.webp",size:H,quality:J,acl:L}={}){if(!$?.length)throw M.conflict("A buffer must be provided");return D($,H??V,J??80,W,L??"public-read")}async function k($,{quality:W=80,acl:H="public-read"}={}){console.log("Going to normalizeImageInput");let J=await I($);console.log("Going to processSharpImage for original");let L=await D(J.buffer,V,W,J.name,H);console.log("Going to processSharpImage for variantsEntries");let Q=await Promise.all(Object.entries(w).map(async([Y,X])=>{let Z=await D(J.buffer,X,W,J.name,H);return[Y,Z]}));return{original:L,variants:Object.fromEntries(Q)}}import c from"sharp";import{randomUUID as b}from"crypto";import{extname as C}from"path";async function v($,W,H){if(!W)return{data:null,error:Error("File not found")};let J=$.replace(/^\/+|\/+$/g,""),L=C(W.name),Q=`${b()}${L}`,Y=`${J}/${Q}`,X=`./buckets/${J}/${Q}`;try{let Z=await Bun.write(X,W);return{data:{key:Y,file:W,bytesWritten:Z},error:null}}catch(Z){return{data:null,error:Error(`Failed to upload ${W.name} to local filesystem`)}}}async function g($,W,H){if(!W||W.length===0)return[];let J=W.map((Q)=>{let Y=H?.(Q)??Q.name;return v($,Q,Y)});return await Promise.all(J)}async function m($){let W=Bun.file(`./buckets/${$}`);if(!await W.exists())return null;return W}async function h($){let W=Bun.file(`./buckets/${$}`);if(!await W.exists())return!1;return await W.delete(),!0}var U={uploadOne:v,uploadMany:g,getOne:m,deleteOne:h};async function D0($){let W=`./cache/images/${$.key}_${$.width}_${$.quality}.webp`,H=await U.getOne(W);if(H){if(!x.isImage(H.type))return null;return H}let J=$.key,L=await U.getOne(J);if(!L)return null;if(!x.isImage(L.type))return null;let Q=await L.arrayBuffer(),Y=await c(Q).resize($.width,null,{withoutEnlargement:!0}).webp({quality:$.quality??75}).toBuffer();await Bun.write(W,Y);let X=Bun.file(W);if(!await X.exists())return null;return X}import u from"sharp";async function j0($){if(!$?.length)return null;try{let W=await u($).metadata(),H=W.width??0,J=W.height??0,L=W.height>0?H/J:1;return{type:`image/${W.format}`,size:W.size??0,extension:`.${W.format}`,width:H,height:J,aspectRatio:L,aspectRatioStr:G(H,J)}}catch(W){return console.warn("Failed to read image metadata:",W),null}}var R=process.env.AWS_FOLDER,B=R?`${R}/`:"";var{s3:y}=globalThis.Bun;import{extname as d}from"path";async function A($,W,H){let J="buffer"in W?W:{buffer:W,object:{name:W.name,resolvedType:O(W.type),metadata:{type:W.type,extension:d(W.name),size:W.size,acl:H?.acl??"public-read"}}};if("buffer"in W){if(!W.object?.name||!W.object?.metadata)throw M.badRequest("Complete metadata required when uploading buffer")}let L=$.length>1?`${$.replace(/^\/+|\/+$/g,"")}/`:"",Q=J.object.metadata.extension.startsWith(".")?J.object.metadata.extension:`.${J.object.metadata.extension}`,Y=J.object.name?J.object.name:`${crypto.randomUUID()}${Q}`,X=`${B}${L}${Y}`,Z=y.file(X),_=J?.object?.metadata?.acl??"public-read",K=_!=="public-read"&&_!=="public-read-write",E=await Z.write(J.buffer,{acl:_,type:J.object.metadata.type});return{uploadedBy:H?.uploadedBy??null,key:X,url:null,name:J.object.name,thumbnail:null,resolvedType:J.object.resolvedType,provider:"s3",isPrivate:K,metadata:{...J.object.metadata,size:E,acl:_},isActive:!0}}async function k0($,W,H={throwIf:"any"}){let J=await Promise.allSettled(W.map((Y)=>A($,Y,{acl:H?.acl,uploadedBy:H?.uploadedBy}))),L=[],Q=[];if(J.forEach((Y)=>{if(Y.status==="fulfilled"){if(L.push(Y.value),H?.externalKeys)H.externalKeys.push(Y.value.key)}else Q.push(Y.reason)}),H?.throwIf==="any"&&Q.length>0||H?.throwIf==="all"&&Q.length===W.length)throw M.internalServerError(`Upload failed: ${Q.length} of ${W.length}`);return{data:L,errors:Q.length?Q:void 0}}async function f($,W,H){let J=H?.baseId??crypto.randomUUID(),L=W.original.object.metadata.extension,Q=await A($,{...W.original,object:{...W.original.object,name:`${J}${L}`}},H),Y=await Promise.all(Object.entries(W.variants).map(async([X,Z])=>{if(!Z)return[X,null];let _=Z.object.metadata.extension,K=await A($,{...Z,object:{...Z.object,name:`${J}_${X}${_}`}},H);return[X,{key:K.key,url:K.url,name:K.name,metadata:{type:K.metadata?.type,size:K.metadata?.size,extension:K.metadata?.extension,width:K.metadata?.width,height:K.metadata?.height,aspectRatio:K.metadata?.aspectRatio,aspectRatioStr:K.metadata?.aspectRatioStr,resolution:K.metadata?.resolution,bitrate:K.metadata?.bitrate,codec:K.metadata?.codec,fps:K.metadata?.fps}}]}));return{original:Q,variants:Object.fromEntries(Y.filter(([,X])=>X!==null))}}async function v0($,W,H){if(Array.isArray(W))throw Error("File can't be an array, pass a single file");let J=await k(W,{quality:H?.quality,acl:H?.acl});return f($,J,{acl:H?.acl,uploadedBy:H?.uploadedBy})}var{s3:n}=globalThis.Bun;async function p($,W){if(!$||typeof $!=="string")throw M.badRequest("Key is required");let H=$.trim();if(!H||H.length===0)throw M.badRequest("Key must be a non-empty string");try{return await n.delete($),{key:$,deleted:!0,error:null}}catch(J){return{key:$,deleted:!1,error:J}}}async function P0($,W){return(await Promise.allSettled($.map((J)=>p(J,W)))).map((J,L)=>{if(J.status==="fulfilled")return J.value;return{key:$[L],deleted:!1,error:J.reason}})}var{s3:s}=globalThis.Bun;async function g0($,W={debug:!0}){try{return{exists:await s.exists($),error:null}}catch(H){if(W?.debug)console.error("There was an error checking for file existance",H);return{exists:null,error:H}}}export{A as uploadOne,k0 as uploadMany,f as uploadGeneratedVariants,M0 as optimizeImageBuffer,L0 as optimizeImage,O as mimeTypeToResolvedType,D0 as getOptimizedImage,r as getObjectUrl,j0 as getImageMetadata,a as getAspectRatioStringRound,G as getAspectRatioString,k as generateVariants,o as generateTestFile,v0 as generateAndUploadImage,x as fileTypePredicates,p as deleteOne,P0 as deleteMany,g0 as checkFileExistance};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=5E1C8B325A3FF69364756E2164756E21
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -35,6 +35,28 @@ type StorageObjectMetadata = {
|
|
|
35
35
|
alt?: string;
|
|
36
36
|
colorPalette?: string[];
|
|
37
37
|
};
|
|
38
|
+
type StorageObjectVariantMetadata = {
|
|
39
|
+
/**
|
|
40
|
+
* Mime type
|
|
41
|
+
*/
|
|
42
|
+
type: string;
|
|
43
|
+
/**
|
|
44
|
+
* File size in bytes
|
|
45
|
+
*/
|
|
46
|
+
size: number;
|
|
47
|
+
/**
|
|
48
|
+
* File extension
|
|
49
|
+
*/
|
|
50
|
+
extension: string;
|
|
51
|
+
width?: number;
|
|
52
|
+
height?: number;
|
|
53
|
+
aspectRatio?: number;
|
|
54
|
+
aspectRatioStr?: AspectRatioStr;
|
|
55
|
+
resolution?: string;
|
|
56
|
+
bitrate?: number;
|
|
57
|
+
codec?: string;
|
|
58
|
+
fps?: number;
|
|
59
|
+
};
|
|
38
60
|
/**
|
|
39
61
|
* s3 for s3 compatible provider
|
|
40
62
|
* local for local filesystem
|
|
@@ -64,6 +86,12 @@ type StorageObject = {
|
|
|
64
86
|
isActive: boolean;
|
|
65
87
|
referenceCount: number;
|
|
66
88
|
};
|
|
89
|
+
type StorageObjectVariant = {
|
|
90
|
+
key: string | null;
|
|
91
|
+
url: string | null;
|
|
92
|
+
name: string | null;
|
|
93
|
+
metadata: StorageObjectVariantMetadata;
|
|
94
|
+
};
|
|
67
95
|
type InsertStorageObjet = Omit<StorageObject, "id" | "createdAt" | "updatedAt" | "referenceCount"> & {
|
|
68
96
|
key: string;
|
|
69
97
|
};
|
|
@@ -75,4 +103,4 @@ export type UploadableObjectBuffer = {
|
|
|
75
103
|
metadata: StorageObjectMetadata;
|
|
76
104
|
};
|
|
77
105
|
};
|
|
78
|
-
export type { ResolvedFileType, StorageObject, StorageObjectMetadata, Acl, StorageProvider, InsertStorageObjet, };
|
|
106
|
+
export type { ResolvedFileType, StorageObject, StorageObjectMetadata, StorageObjectVariant, StorageObjectVariantMetadata, Acl, StorageProvider, InsertStorageObjet, };
|