@lunora/storage 1.0.0-alpha.97 → 1.0.0-alpha.98
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";import{Rest as u,Multipart as m,Tus as h}from"@visulima/storage/handler/http/fetch";import{AwsLightStorage as p}from"@visulima/storage/provider/aws-light";const E=100*1024*1024,T="1.0.0",i=(e,t,r)=>{const o={"content-type":"application/json"};return e==="tus"&&(o["Tus-Resumable"]=T),Response.json({error:r},{headers:o,status:t})},d=e=>i(e,403,{code:"FORBIDDEN",message:"Upload denied by authorization policy",name:"ForbiddenError"}),f=e=>i(e,413,{code:"REQUEST_ENTITY_TOO_LARGE",message:"Upload exceeds the configured maxFileSize",name:"RequestEntityTooLargeError"}),g=e=>{const t=i(e,405,{code:"METHOD_NOT_ALLOWED",message:"DELETE is not allowed on this upload route",name:"MethodNotAllowedError"});return t.headers.set("Allow",e==="multipart"?"GET, OPTIONS, POST":"GET, HEAD, OPTIONS, PATCH, POST, PUT"),t},S=(e,t)=>{if(t==="multipart")return;let r;for(const o of["Upload-Length","X-Total-Size","Content-Length"]){const s=e.headers.get(o);if(s===null)continue;const n=Number(s);Number.isFinite(n)&&(r===void 0||n>r)&&(r=n)}return r},w=(e,t)=>e==="chunked-rest"?new u(t):e==="multipart"?new m(t):new h(t),z=e=>{const t=e.protocol??"tus",r=e.maxFileSize??E;if(!Number.isFinite(r)||r<0)throw new l("VALIDATION_ERROR",`@lunora/storage: maxFileSize must be a finite, non-negative number (received ${String(r)})`);const o={disableTerminationForFinishedUploads:!0,maxFileSize:r,storage:e.storage},s=w(t,o),{authorize:n}=e;return n===void 0&&!e.silent&&!e.public&&console.warn("@lunora/storage: createUploadHandler() has no `authorize` — this mounts an unauthenticated, unbounded-write endpoint. Pass an RLS `authorize` gate, or set `public: true` (or `silent: true`) to confirm this bucket is intentionally open."),{fetch:async a=>{if(t!=="tus"&&a.method==="DELETE")return g(t);const c=S(a,t);if(c!==void 0&&c>r)return f(t);if(n!==void 0)try{if(await n({method:a.method,protocol:t,request:a,url:new URL(a.url)})!==!0)return d(t)}catch{return d(t)}return s.fetch(a)},protocol:t}},O=e=>new p({accessKeyId:e.accessKeyId,bucket:e.bucket,endpoint:e.endpoint??`https://${e.accountId}.r2.cloudflarestorage.com`,path:e.path??"/",region:"auto",secretAccessKey:e.secretAccessKey,...e.partSize===void 0?{}:{partSize:e.partSize}});export{E as DEFAULT_MAX_UPLOAD_BYTES,O as createR2UploadStorage,z as createUploadHandler};
|
package/dist/upload.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DEFAULT_MAX_UPLOAD_BYTES as r,createR2UploadStorage as o,createUploadHandler as t}from"./packem_shared/DEFAULT_MAX_UPLOAD_BYTES-
|
|
1
|
+
import{DEFAULT_MAX_UPLOAD_BYTES as r,createR2UploadStorage as o,createUploadHandler as t}from"./packem_shared/DEFAULT_MAX_UPLOAD_BYTES-DOQ-yvKa.mjs";export{r as DEFAULT_MAX_UPLOAD_BYTES,o as createR2UploadStorage,t as createUploadHandler};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as d}from"@lunora/errors";import{Rest as l,Multipart as m,Tus as h}from"@visulima/storage/handler/http/fetch";import{AwsLightStorage as f}from"@visulima/storage/provider/aws-light";const p=100*1024*1024,g="1.0.0",u=(e,t,r)=>{const o={"content-type":"application/json"};return e==="tus"&&(o["Tus-Resumable"]=g),Response.json({error:r},{headers:o,status:t})},s=e=>u(e,403,{code:"FORBIDDEN",message:"Upload denied by authorization policy",name:"ForbiddenError"}),S=e=>u(e,413,{code:"REQUEST_ENTITY_TOO_LARGE",message:"Upload exceeds the configured maxFileSize",name:"RequestEntityTooLargeError"}),R=(e,t)=>{if(t==="multipart")return;let r;for(const o of["Upload-Length","X-Total-Size","Content-Length"]){const i=e.headers.get(o);if(i===null)continue;const n=Number(i);Number.isFinite(n)&&(r===void 0||n>r)&&(r=n)}return r},b=(e,t)=>e==="chunked-rest"?new l(t):e==="multipart"?new m(t):new h(t),y=e=>{const t=e.protocol??"tus",r=e.maxFileSize??p;if(!Number.isFinite(r)||r<0)throw new d("VALIDATION_ERROR",`@lunora/storage: maxFileSize must be a finite, non-negative number (received ${String(r)})`);const o={maxFileSize:r,storage:e.storage},i=b(t,o),{authorize:n}=e;return n===void 0&&!e.silent&&!e.public&&console.warn("@lunora/storage: createUploadHandler() has no `authorize` — this mounts an unauthenticated, unbounded-write endpoint. Pass an RLS `authorize` gate, or set `public: true` (or `silent: true`) to confirm this bucket is intentionally open."),{fetch:async a=>{const c=R(a,t);if(c!==void 0&&c>r)return S(t);if(n!==void 0)try{if(await n({method:a.method,protocol:t,request:a,url:new URL(a.url)})!==!0)return s(t)}catch{return s(t)}return i.fetch(a)},protocol:t}},T=e=>new f({accessKeyId:e.accessKeyId,bucket:e.bucket,endpoint:e.endpoint??`https://${e.accountId}.r2.cloudflarestorage.com`,path:e.path??"/",region:"auto",secretAccessKey:e.secretAccessKey,...e.partSize===void 0?{}:{partSize:e.partSize}});export{p as DEFAULT_MAX_UPLOAD_BYTES,T as createR2UploadStorage,y as createUploadHandler};
|