@mateosuarezdev/brpc 1.0.78 → 1.0.79
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var U=($)=>$.startsWith("image/"),V=($)=>$.startsWith("video/"),q=($)=>$.startsWith("audio/"),A=($)=>$.startsWith("text/")||$.includes("pdf")||$.includes("word")||$.includes("sheet")||$.includes("presentation")||$.includes("opendocument")||$==="application/rtf",F=($)=>$.includes("zip")||$.includes("rar")||$.includes("tar")||$.includes("7z")||$.includes("gzip"),S=($)=>$==="application/javascript"||$==="application/json"||$==="text/html"||$==="text/css"||$==="application/xml"||$.includes("javascript"),N=($)=>$.startsWith("font/")||$.includes("font"),z=($)=>{if(!$)return"other";let W=$.toLowerCase();if(U(W))return"image";if(V(W))return"video";if(q(W))return"audio";if(A(W))return"document";if(F(W))return"archive";if(S(W))return"code";if(N(W))return"font";return"other"},D={isImage:U,isVideo:V,isAudio:q,isDocument:A,isArchive:F,isCode:S,isFont:N};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 x($,W){if(!$||$<1||!W||W<1)return"1:1";let j=(Q,J)=>J===0?Q:j(J,Q%J),H=j($,W);return`${$/H}:${W/H}`}function t($,W){if(!$||!W||$<1||W<1)return"1:1";let j=$/W,H=[{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"}],Q=0.03;for(let{ratio:X,label:K}of H)if(Math.abs(j-X)/X<Q)return K;let J=(X,K)=>K===0?X:J(K,X%K),Y=J($,W);return`${$/Y}:${W/Y}`}class L 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=L.STATUS_MAP[$.code],this.data=$.data,this.cause=$.cause,Error.captureStackTrace)Error.captureStackTrace(this,L)}toJSON(){return{name:this.name,code:this.code,clientCode:this.clientCode,message:this.message,data:this.data,httpStatus:this.httpStatus}}static badRequest($,W,j){return new L({code:"BAD_REQUEST",message:$,clientCode:W,data:j})}static unauthorized($="Unauthorized",W,j){return new L({code:"UNAUTHORIZED",message:$,clientCode:W,data:j})}static forbidden($="Forbidden",W,j){return new L({code:"FORBIDDEN",message:$,clientCode:W,data:j})}static notFound($="Not Found",W,j){return new L({code:"NOT_FOUND",message:$,clientCode:W,data:j})}static preconditionFailed($="Precondition failed",W,j){return new L({code:"NOT_FOUND",message:$,clientCode:W,data:j})}static conflict($,W,j){return new L({code:"CONFLICT",message:$,clientCode:W,data:j})}static unprocessableContent($,W,j){return new L({code:"UNPROCESSABLE_CONTENT",message:$,clientCode:W,data:j})}static tooManyRequests($="Too many requests",W,j){return new L({code:"TOO_MANY_REQUESTS",message:$,clientCode:W,data:j})}static internalServerError($="Internal Server Error",W,j){return new L({code:"INTERNAL_SERVER_ERROR",message:$,clientCode:W,data:j})}static timeout($="Request timeout",W,j){return new L({code:"TIMEOUT",message:$,clientCode:W,data:j})}}import B from"sharp";var T={xs:200,sm:400,md:800,lg:1200,xl:1920},_=1920;async function G($,W,j,H,Q){try{let{data:J,info:Y}=await B($,{limitInputPixels:1e8}).rotate().resize({width:W,height:W,fit:"inside",withoutEnlargement:!0}).webp({quality:j}).toBuffer({resolveWithObject:!0});return{buffer:J,object:{name:H.replace(/\.[^/.]+$/,".webp"),resolvedType:"image",metadata:{type:"image/webp",size:J.length,extension:".webp",width:Y.width,height:Y.height,aspectRatio:Y.width&&Y.height?Y.width/Y.height:1,aspectRatioStr:Y.width&&Y.height?x(Y.width,Y.height):"1:1",acl:Q}}}}catch(J){throw L.conflict(`Failed to optimize image: ${J instanceof Error?J.message:"Unknown error"}`)}}async function w($){if(!$)throw L.conflict("A file must be provided");let W,j="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"),L.conflict("Invalid base64 format");let[,H]=$.split(",");if(!H)throw L.conflict("Invalid base64 data");W=Buffer.from(H,"base64")}else{if(!D.isImage($.type))throw L.conflict("File must be an image");let H=await $.arrayBuffer();W=Buffer.from(H),j=$.name??j}return{buffer:W,name:j}}async function Q0($,{size:W,quality:j,acl:H}={}){let Q=await w($);return G(Q.buffer,W??_,j??80,Q.name,H??"public-read")}async function Y0($,{name:W="unknown.webp",size:j,quality:H,acl:Q}={}){if(!$?.length)throw L.conflict("A buffer must be provided");return G($,j??_,H??80,W,Q??"public-read")}async function I($,{quality:W=80,acl:j="public-read"}={}){let H=await w($),Q=await Promise.all(Object.entries(T).map(async([J,Y])=>{let X=await G(H.buffer,Y,W,H.name,j);return[J,X]}));return{variants:Object.fromEntries(Q)}}import m from"sharp";import{randomUUID as P}from"crypto";import{extname as C}from"path";async function k($,W,j){if(!W)return{data:null,error:Error("File not found")};let H=$.replace(/^\/+|\/+$/g,""),Q=C(W.name),J=`${P()}${Q}`,Y=`${H}/${J}`,X=`./buckets/${H}/${J}`;try{let K=await Bun.write(X,W);return{data:{key:Y,file:W,bytesWritten:K},error:null}}catch(K){return{data:null,error:Error(`Failed to upload ${W.name} to local filesystem`)}}}async function g($,W,j){if(!W||W.length===0)return[];let H=W.map((J)=>{let Y=j?.(J)??J.name;return k($,J,Y)});return await Promise.all(H)}async function c($){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 O={uploadOne:k,uploadMany:g,getOne:c,deleteOne:h};async function _0($){let W=`./cache/images/${$.key}_${$.width}_${$.quality}.webp`,j=await O.getOne(W);if(j){if(!D.isImage(j.type))return null;return j}let H=$.key,Q=await O.getOne(H);if(!Q)return null;if(!D.isImage(Q.type))return null;let J=await Q.arrayBuffer(),Y=await m(J).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 V0($){if(!$?.length)return null;try{let W=await u($).metadata(),j=W.width??0,H=W.height??0,Q=W.height>0?j/H:1;return{type:`image/${W.format}`,size:W.size??0,extension:`.${W.format}`,width:j,height:H,aspectRatio:Q,aspectRatioStr:x(j,H)}}catch(W){return console.warn("Failed to read image metadata:",W),null}}var v=process.env.AWS_FOLDER,b=v?`${v}/`:"";var{s3:y}=globalThis.Bun;import{extname as d}from"path";async function R($,W,j){let H="buffer"in W?W:{buffer:W,object:{name:W.name,resolvedType:z(W.type),metadata:{type:W.type,extension:d(W.name),size:W.size,acl:j?.acl??"public-read"}}};if("buffer"in W){if(!W.object?.name||!W.object?.metadata)throw L.badRequest("Complete metadata required when uploading buffer")}let Q=$.length>1?`${$.replace(/^\/+|\/+$/g,"")}/`:"",J=H.object.metadata.extension.startsWith(".")?H.object.metadata.extension:`.${H.object.metadata.extension}`,Y=H.object.name?H.object.name:`${crypto.randomUUID()}${J}`,X=`${b}${Q}${Y}`,K=y.file(X),M=H?.object?.metadata?.acl??"public-read",Z=M!=="public-read"&&M!=="public-read-write",E=await K.write(H.buffer,{acl:M,type:H.object.metadata.type});return{uploadedBy:j?.uploadedBy??null,key:X,url:null,name:H.object.name,resolvedType:H.object.resolvedType,provider:"s3",isPrivate:Z,metadata:{...H.object.metadata,size:E,acl:M},isActive:!0}}async function I0($,W,j={throwIf:"any"}){let H=await Promise.allSettled(W.map((Y)=>R($,Y,{acl:j?.acl,uploadedBy:j?.uploadedBy}))),Q=[],J=[];if(H.forEach((Y)=>{if(Y.status==="fulfilled"){if(Q.push(Y.value),j?.externalKeys)j.externalKeys.push(Y.value.key)}else J.push(Y.reason)}),j?.throwIf==="any"&&J.length>0||j?.throwIf==="all"&&J.length===W.length)throw L.internalServerError(`Upload failed: ${J.length} of ${W.length}`);return{data:Q,errors:J.length?J:void 0}}async function f($,W,j){let H=j?.baseId??crypto.randomUUID(),Q=Object.values(W.variants).find(Boolean),J=await Promise.all(Object.entries(W.variants).map(async([X,K])=>{if(!K)return[X,null];let M=K.object.metadata.extension,Z=await R($,{...K,object:{...K.object,name:`${H}_${X}${M}`}},j);return[X,{key:Z.key,url:Z.url,name:Z.name,metadata:{type:Z.metadata?.type,extension:Z.metadata?.extension,size:Z.metadata?.size,hash:null,width:Z.metadata?.width,height:Z.metadata?.height,aspectRatio:Z.metadata?.aspectRatio,aspectRatioStr:Z.metadata?.aspectRatioStr,resolution:Z.metadata?.resolution,bitrate:Z.metadata?.bitrate,codec:Z.metadata?.codec,fps:Z.metadata?.fps}}]})),Y=(j?.acl??"public-read")!=="public-read"&&(j?.acl??"public-read")!=="public-read-write";return{shared:{name:Q.object.name,resolvedType:Q.object.resolvedType,provider:"s3",acl:j?.acl??"public-read",isPrivate:Y,uploadedBy:j?.uploadedBy??null},variants:Object.fromEntries(J.filter(([,X])=>X!==null))}}async function k0($,W,j){if(Array.isArray(W))throw Error("File can't be an array, pass a single file");let H=await I(W,{quality:j?.quality,acl:j?.acl});return f($,H,{acl:j?.acl,uploadedBy:j?.uploadedBy})}var{s3:n}=globalThis.Bun;async function p($,W){if(!$||typeof $!=="string")throw L.badRequest("Key is required");let j=$.trim();if(!j||j.length===0)throw L.badRequest("Key must be a non-empty string");try{return await n.delete($),{key:$,deleted:!0,error:null}}catch(H){return{key:$,deleted:!1,error:H}}}async function E0($,W){return(await Promise.allSettled($.map((H)=>p(H,W)))).map((H,Q)=>{if(H.status==="fulfilled")return H.value;return{key:$[Q],deleted:!1,error:H.reason}})}var{s3:s}=globalThis.Bun;async function C0($,W={debug:!0}){try{return{exists:await s.exists($),error:null}}catch(j){if(W?.debug)console.error("There was an error checking for file existance",j);return{exists:null,error:j}}}export{R as uploadOne,I0 as uploadMany,f as uploadGeneratedVariants,Y0 as optimizeImageBuffer,Q0 as optimizeImage,z as mimeTypeToResolvedType,_0 as getOptimizedImage,V0 as getImageMetadata,t as getAspectRatioStringRound,x as getAspectRatioString,I as generateVariants,o as generateTestFile,k0 as generateAndUploadImage,D as fileTypePredicates,p as deleteOne,E0 as deleteMany,C0 as checkFileExistance};
|
|
2
|
+
var V=($)=>$.startsWith("image/"),q=($)=>$.startsWith("video/"),O=($)=>$.startsWith("audio/"),A=($)=>$.startsWith("text/")||$.includes("pdf")||$.includes("word")||$.includes("sheet")||$.includes("presentation")||$.includes("opendocument")||$==="application/rtf",F=($)=>$.includes("zip")||$.includes("rar")||$.includes("tar")||$.includes("7z")||$.includes("gzip"),S=($)=>$==="application/javascript"||$==="application/json"||$==="text/html"||$==="text/css"||$==="application/xml"||$.includes("javascript"),z=($)=>$.startsWith("font/")||$.includes("font"),N=($)=>{if(!$)return"other";let W=$.toLowerCase();if(V(W))return"image";if(q(W))return"video";if(O(W))return"audio";if(A(W))return"document";if(F(W))return"archive";if(S(W))return"code";if(z(W))return"font";return"other"},x={isImage:V,isVideo:q,isAudio:O,isDocument:A,isArchive:F,isCode:S,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 _($,W){if(!$||$<1||!W||W<1)return"1:1";let j=(Q,J)=>J===0?Q:j(J,Q%J),H=j($,W);return`${$/H}:${W/H}`}function t($,W){if(!$||!W||$<1||W<1)return"1:1";let j=$/W,H=[{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"}],Q=0.03;for(let{ratio:X,label:K}of H)if(Math.abs(j-X)/X<Q)return K;let J=(X,K)=>K===0?X:J(K,X%K),Y=J($,W);return`${$/Y}:${W/Y}`}class L 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=L.STATUS_MAP[$.code],this.data=$.data,this.cause=$.cause,Error.captureStackTrace)Error.captureStackTrace(this,L)}toJSON(){return{name:this.name,code:this.code,clientCode:this.clientCode,message:this.message,data:this.data,httpStatus:this.httpStatus}}static badRequest($,W,j){return new L({code:"BAD_REQUEST",message:$,clientCode:W,data:j})}static unauthorized($="Unauthorized",W,j){return new L({code:"UNAUTHORIZED",message:$,clientCode:W,data:j})}static forbidden($="Forbidden",W,j){return new L({code:"FORBIDDEN",message:$,clientCode:W,data:j})}static notFound($="Not Found",W,j){return new L({code:"NOT_FOUND",message:$,clientCode:W,data:j})}static preconditionFailed($="Precondition failed",W,j){return new L({code:"NOT_FOUND",message:$,clientCode:W,data:j})}static conflict($,W,j){return new L({code:"CONFLICT",message:$,clientCode:W,data:j})}static unprocessableContent($,W,j){return new L({code:"UNPROCESSABLE_CONTENT",message:$,clientCode:W,data:j})}static tooManyRequests($="Too many requests",W,j){return new L({code:"TOO_MANY_REQUESTS",message:$,clientCode:W,data:j})}static internalServerError($="Internal Server Error",W,j){return new L({code:"INTERNAL_SERVER_ERROR",message:$,clientCode:W,data:j})}static timeout($="Request timeout",W,j){return new L({code:"TIMEOUT",message:$,clientCode:W,data:j})}}import E from"sharp";var T={xs:200,sm:400,md:800,lg:1200,xl:1920},G=1920;async function D($,W,j,H,Q){try{let{data:J,info:Y}=await E($,{limitInputPixels:1e8}).rotate().resize({width:W,height:W,fit:"inside",withoutEnlargement:!0}).webp({quality:j}).toBuffer({resolveWithObject:!0});return{buffer:J,object:{name:H.replace(/\.[^/.]+$/,".webp"),resolvedType:"image",metadata:{type:"image/webp",size:J.length,extension:".webp",width:Y.width,height:Y.height,aspectRatio:Y.width&&Y.height?Y.width/Y.height:1,aspectRatioStr:Y.width&&Y.height?_(Y.width,Y.height):"1:1",acl:Q}}}}catch(J){throw L.conflict(`Failed to optimize image: ${J instanceof Error?J.message:"Unknown error"}`)}}async function w($){if(!$)throw L.conflict("A file must be provided");let W,j="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"),L.conflict("Invalid base64 format");let[,H]=$.split(",");if(!H)throw L.conflict("Invalid base64 data");W=Buffer.from(H,"base64")}else{if(!x.isImage($.type))throw L.conflict("File must be an image");let H=await $.arrayBuffer();W=Buffer.from(H),j=$.name??j}return{buffer:W,name:j}}async function Q0($,{size:W,quality:j,acl:H}={}){let Q=await w($);return D(Q.buffer,W??G,j??80,Q.name,H??"public-read")}async function Y0($,{name:W="unknown.webp",size:j,quality:H,acl:Q}={}){if(!$?.length)throw L.conflict("A buffer must be provided");return D($,j??G,H??80,W,Q??"public-read")}async function I($,{quality:W=80,acl:j="public-read"}={}){let H=await w($),Q=await Promise.all(Object.entries(T).map(async([J,Y])=>{let X=await D(H.buffer,Y,W,H.name,j);return[J,X]}));return{variants:Object.fromEntries(Q)}}import m from"sharp";import{randomUUID as B}from"crypto";import{extname as C}from"path";async function k($,W,j){if(!W)return{data:null,error:Error("File not found")};let H=$.replace(/^\/+|\/+$/g,""),Q=C(W.name),J=`${B()}${Q}`,Y=`${H}/${J}`,X=`./buckets/${H}/${J}`;try{let K=await Bun.write(X,W);return{data:{key:Y,file:W,bytesWritten:K},error:null}}catch(K){return{data:null,error:Error(`Failed to upload ${W.name} to local filesystem`)}}}async function g($,W,j){if(!W||W.length===0)return[];let H=W.map((J)=>{let Y=j?.(J)??J.name;return k($,J,Y)});return await Promise.all(H)}async function c($){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:k,uploadMany:g,getOne:c,deleteOne:h};async function G0($){let W=`./cache/images/${$.key}_${$.width}_${$.quality}.webp`,j=await U.getOne(W);if(j){if(!x.isImage(j.type))return null;return j}let H=$.key,Q=await U.getOne(H);if(!Q)return null;if(!x.isImage(Q.type))return null;let J=await Q.arrayBuffer(),Y=await m(J).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 q0($){if(!$?.length)return null;try{let W=await u($).metadata(),j=W.width??0,H=W.height??0,Q=W.height>0?j/H:1;return{type:`image/${W.format}`,size:W.size??0,extension:`.${W.format}`,width:j,height:H,aspectRatio:Q,aspectRatioStr:_(j,H)}}catch(W){return console.warn("Failed to read image metadata:",W),null}}var v=process.env.AWS_FOLDER,b=v?`${v}/`:"";var{s3:y}=globalThis.Bun;import{extname as d}from"path";async function R($,W,j){let H="buffer"in W?W:{buffer:W,object:{name:W.name,resolvedType:N(W.type),metadata:{type:W.type,extension:d(W.name),size:W.size,acl:j?.acl??"public-read"}}};if("buffer"in W){if(!W.object?.name||!W.object?.metadata)throw L.badRequest("Complete metadata required when uploading buffer")}let Q=$.length>1?`${$.replace(/^\/+|\/+$/g,"")}/`:"",J=H.object.metadata.extension.startsWith(".")?H.object.metadata.extension:`.${H.object.metadata.extension}`,Y=H.object.name?H.object.name:`${crypto.randomUUID()}${J}`,X=`${b}${Q}${Y}`,K=y.file(X),M=H?.object?.metadata?.acl??"public-read",Z=M!=="public-read"&&M!=="public-read-write",P=await K.write(H.buffer,{acl:M,type:H.object.metadata.type});return{uploadedBy:j?.uploadedBy,key:X,url:void 0,name:H.object.name,resolvedType:H.object.resolvedType,provider:"s3",isPrivate:Z,metadata:{...H.object.metadata,size:P,acl:M},isActive:!0}}async function I0($,W,j={throwIf:"any"}){let H=await Promise.allSettled(W.map((Y)=>R($,Y,{acl:j?.acl,uploadedBy:j?.uploadedBy}))),Q=[],J=[];if(H.forEach((Y)=>{if(Y.status==="fulfilled"){if(Q.push(Y.value),j?.externalKeys)j.externalKeys.push(Y.value.key)}else J.push(Y.reason)}),j?.throwIf==="any"&&J.length>0||j?.throwIf==="all"&&J.length===W.length)throw L.internalServerError(`Upload failed: ${J.length} of ${W.length}`);return{data:Q,errors:J.length?J:void 0}}async function f($,W,j){let H=j?.baseId??crypto.randomUUID(),Q=Object.values(W.variants).find(Boolean),J=await Promise.all(Object.entries(W.variants).map(async([X,K])=>{if(!K)return[X,null];let M=K.object.metadata.extension,Z=await R($,{...K,object:{...K.object,name:`${H}_${X}${M}`}},j);return[X,{key:Z.key,url:Z.url,name:Z.name,metadata:{type:Z.metadata?.type,extension:Z.metadata?.extension,size:Z.metadata?.size,hash:void 0,width:Z.metadata?.width,height:Z.metadata?.height,aspectRatio:Z.metadata?.aspectRatio,aspectRatioStr:Z.metadata?.aspectRatioStr,resolution:Z.metadata?.resolution,bitrate:Z.metadata?.bitrate,codec:Z.metadata?.codec,fps:Z.metadata?.fps}}]})),Y=(j?.acl??"public-read")!=="public-read"&&(j?.acl??"public-read")!=="public-read-write";return{shared:{name:Q.object.name,resolvedType:Q.object.resolvedType,provider:"s3",acl:j?.acl??"public-read",isPrivate:Y,uploadedBy:j?.uploadedBy},variants:Object.fromEntries(J.filter(([,X])=>X!==null))}}async function k0($,W,j){if(Array.isArray(W))throw Error("File can't be an array, pass a single file");let H=await I(W,{quality:j?.quality,acl:j?.acl});return f($,H,{acl:j?.acl,uploadedBy:j?.uploadedBy})}var{s3:n}=globalThis.Bun;async function p($,W){if(!$||typeof $!=="string")throw L.badRequest("Key is required");let j=$.trim();if(!j||j.length===0)throw L.badRequest("Key must be a non-empty string");try{return await n.delete($),{key:$,deleted:!0,error:null}}catch(H){return{key:$,deleted:!1,error:H}}}async function P0($,W){return(await Promise.allSettled($.map((H)=>p(H,W)))).map((H,Q)=>{if(H.status==="fulfilled")return H.value;return{key:$[Q],deleted:!1,error:H.reason}})}var{s3:s}=globalThis.Bun;async function C0($,W={debug:!0}){try{return{exists:await s.exists($),error:null}}catch(j){if(W?.debug)console.error("There was an error checking for file existance",j);return{exists:null,error:j}}}export{R as uploadOne,I0 as uploadMany,f as uploadGeneratedVariants,Y0 as optimizeImageBuffer,Q0 as optimizeImage,N as mimeTypeToResolvedType,G0 as getOptimizedImage,q0 as getImageMetadata,t as getAspectRatioStringRound,_ as getAspectRatioString,I as generateVariants,o as generateTestFile,k0 as generateAndUploadImage,x as fileTypePredicates,p as deleteOne,P0 as deleteMany,C0 as checkFileExistance};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=A02A7765CCE245F964756E2164756E21
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ type StorageObjectVariantMetadata = {
|
|
|
51
51
|
/**
|
|
52
52
|
* Integrity checksum — reserved for future use, not yet populated
|
|
53
53
|
*/
|
|
54
|
-
hash?: string
|
|
54
|
+
hash?: string;
|
|
55
55
|
width?: number;
|
|
56
56
|
height?: number;
|
|
57
57
|
aspectRatio?: number;
|
|
@@ -79,25 +79,25 @@ type StorageObject = {
|
|
|
79
79
|
isPrivate: boolean | null;
|
|
80
80
|
isActive: boolean;
|
|
81
81
|
thumbnail: string | null;
|
|
82
|
-
alt
|
|
82
|
+
alt?: string | null;
|
|
83
83
|
colorPalette: string[] | null;
|
|
84
84
|
variants: Partial<Record<string, StorageObjectVariant>>;
|
|
85
85
|
};
|
|
86
86
|
type StorageObjectVariant = {
|
|
87
|
-
key
|
|
88
|
-
url
|
|
89
|
-
name
|
|
87
|
+
key?: string;
|
|
88
|
+
url?: string;
|
|
89
|
+
name?: string;
|
|
90
90
|
metadata: StorageObjectVariantMetadata;
|
|
91
91
|
};
|
|
92
92
|
type InsertStorageObject = Omit<StorageObject, "id" | "createdAt" | "updatedAt">;
|
|
93
93
|
type RawUploadResult = {
|
|
94
|
-
uploadedBy
|
|
94
|
+
uploadedBy?: string;
|
|
95
95
|
key: string;
|
|
96
|
-
url
|
|
97
|
-
name
|
|
96
|
+
url?: string;
|
|
97
|
+
name?: string;
|
|
98
98
|
resolvedType: ResolvedFileType;
|
|
99
99
|
provider: StorageProvider;
|
|
100
|
-
isPrivate: boolean
|
|
100
|
+
isPrivate: boolean;
|
|
101
101
|
metadata: StorageObjectMetadata | null;
|
|
102
102
|
isActive: boolean;
|
|
103
103
|
};
|