@visulima/storage 1.0.0-alpha.17 → 1.0.0-alpha.19

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.
Files changed (185) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE.md +3 -0
  3. package/dist/adapter/nuxt/module.d.ts +3 -3
  4. package/dist/adapter/nuxt/module.js +1 -93
  5. package/dist/handler/http/fetch/index.d.ts +6 -6
  6. package/dist/handler/http/fetch/index.js +1 -4
  7. package/dist/handler/http/hono/index.d.ts +3 -3
  8. package/dist/handler/http/hono/index.js +1 -65
  9. package/dist/handler/http/nextjs/index.d.ts +4 -4
  10. package/dist/handler/http/nextjs/index.js +1 -37
  11. package/dist/handler/http/node/index.d.ts +6 -6
  12. package/dist/handler/http/node/index.js +1 -8
  13. package/dist/handler/http/solid-start/index.d.ts +4 -4
  14. package/dist/handler/http/solid-start/index.js +1 -44
  15. package/dist/index.js +1 -13
  16. package/dist/openapi/index.js +1 -5
  17. package/dist/packem_shared/AwsLightFile-BTLiRxXj.js +1 -0
  18. package/dist/packem_shared/AwsLightMetaStorage-DHz1nf_H.js +1 -0
  19. package/dist/packem_shared/AwsLightStorage-CA9cdfJ6.js +1 -0
  20. package/dist/packem_shared/AzureFile-BKHru1zB.js +1 -0
  21. package/dist/packem_shared/AzureSMetaStorage-BqA4jUDJ.js +1 -0
  22. package/dist/packem_shared/AzureStorage-BKUjCymW.js +1 -0
  23. package/dist/packem_shared/BaseTransformer-D68eLyz1.js +1 -0
  24. package/dist/packem_shared/DiskStorage-DNjpDMX9.js +1 -0
  25. package/dist/packem_shared/DiskStorageWithChecksum-Bb6JX_tC.js +1 -0
  26. package/dist/packem_shared/ERRORS-B9jkvKwx.js +1 -0
  27. package/dist/packem_shared/File-alcSNpLq.js +1 -0
  28. package/dist/packem_shared/GCSConfig-BQ0OpVhe.js +1 -0
  29. package/dist/packem_shared/GCSFile-CHjX_fJk.js +1 -0
  30. package/dist/packem_shared/GCSMetaStorage-CpxQ8wM9.js +1 -0
  31. package/dist/packem_shared/GCStorage-DAg1V55T.js +1 -0
  32. package/dist/packem_shared/LocalMetaStorage-BWuFvWn4.js +1 -0
  33. package/dist/packem_shared/MediaTransformer-2C8MJeAg.js +1 -0
  34. package/dist/packem_shared/MetaStorage-Y4m1dWgd.js +1 -0
  35. package/dist/packem_shared/Metadata-B6Ir0KO7.js +1 -0
  36. package/dist/packem_shared/Multipart-Bd9YFFn0.js +1 -0
  37. package/dist/packem_shared/Multipart-D5bcEvga.js +1 -0
  38. package/dist/packem_shared/NetlifyBlobFile-CpzkMKng.js +1 -0
  39. package/dist/packem_shared/NetlifyBlobMetaStorage-dD0oBLom.js +1 -0
  40. package/dist/packem_shared/NetlifyBlobStorage-ByTwCN-h.js +1 -0
  41. package/dist/packem_shared/NoOpMetrics-Dky06sf1.js +1 -0
  42. package/dist/packem_shared/OpenTelemetryMetrics-9uxQMSlg.js +1 -0
  43. package/dist/packem_shared/Rest-CYEBbtCD.js +1 -0
  44. package/dist/packem_shared/Rest-DoonVU7B.js +1 -0
  45. package/dist/packem_shared/S3File-Du6wP0Sz.js +1 -0
  46. package/dist/packem_shared/S3MetaStorage-vcriiosn.js +1 -0
  47. package/dist/packem_shared/S3Storage-Fx6-OSc-.js +1 -0
  48. package/dist/packem_shared/TUS_RESUMABLE-B7KtPVeC.js +1 -0
  49. package/dist/packem_shared/Tus-Bd_2Ki2G.js +1 -0
  50. package/dist/packem_shared/Tus-CUBCkuPE.js +1 -0
  51. package/dist/packem_shared/ValidationError-D8KKJiKA.js +1 -0
  52. package/dist/packem_shared/VercelBlobFile-CL9MjKcY.js +1 -0
  53. package/dist/packem_shared/VercelBlobMetaStorage-BsOTx-Su.js +1 -0
  54. package/dist/packem_shared/VercelBlobStorage-kNkk5Cn4.js +1 -0
  55. package/dist/packem_shared/_commonjsHelpers-D6W6KoPK.js +1 -0
  56. package/dist/packem_shared/aws-light-meta-storage-TPyQwLvk.js +4 -0
  57. package/dist/packem_shared/backblaze-DEflv87m.js +1 -0
  58. package/dist/packem_shared/base-handler-core-DaggCVsq.js +1 -0
  59. package/dist/packem_shared/base-handler-fetch-DnarP64X.js +1 -0
  60. package/dist/packem_shared/base-handler-node-BTes6sql.js +1 -0
  61. package/dist/packem_shared/cache-qV_5Umeq.js +1 -0
  62. package/dist/packem_shared/cloudflare-DLAeQvgD.js +1 -0
  63. package/dist/packem_shared/defaultCloudStorageFileNameValidation-yiM9GxHr.js +1 -0
  64. package/dist/packem_shared/digitalOcean-nhZUds87.js +1 -0
  65. package/dist/packem_shared/disk-storage-BvdK4bqF.js +5 -0
  66. package/dist/packem_shared/gcs-meta-storage-CvGkpzVE.js +1 -0
  67. package/dist/packem_shared/has-content-Bx2p8Okx.js +1 -0
  68. package/dist/packem_shared/headers-DC2MEOrK.js +27 -0
  69. package/dist/packem_shared/is-expired-1JuZjDtb.js +1 -0
  70. package/dist/packem_shared/isRetryableError-DQNSZiBc.js +1 -0
  71. package/dist/packem_shared/isValidMediaType-B-2UKjZx.js +1 -0
  72. package/dist/packem_shared/local-meta-storage-Bkwqi_gi.js +1 -0
  73. package/dist/packem_shared/{media-transformer.d-ChmjTvjc.d.ts → media-transformer.d-CY9CsEOe.d.ts} +1 -1
  74. package/dist/packem_shared/minio-BWwgGXeE.js +1 -0
  75. package/dist/packem_shared/multipart-base-C6OjBwMS.js +1 -0
  76. package/dist/packem_shared/part-match-DqD5U7An.js +1 -0
  77. package/dist/packem_shared/path-D7rMc9nq-B718mbm6.js +1 -0
  78. package/dist/packem_shared/response-builder-Wdo_fvcF.js +1 -0
  79. package/dist/packem_shared/rest-base-B2Dv7esY.js +1 -0
  80. package/dist/packem_shared/restOpenApiSpec-PaIVbESh.js +1 -0
  81. package/dist/packem_shared/s3-base-storage-xHZNtsGe.js +1 -0
  82. package/dist/packem_shared/sharedGet-Ce7WGAsc.js +1 -0
  83. package/dist/packem_shared/storage-m_Cxgiih.js +1 -0
  84. package/dist/packem_shared/tigris-DZoyrMNd.js +1 -0
  85. package/dist/packem_shared/transformOpenApiSpec-C0vEbDTO.js +1 -0
  86. package/dist/packem_shared/{tus-base.d-CpLzyd-S.d.ts → tus-base.d-DNZRXR9X.d.ts} +2 -2
  87. package/dist/packem_shared/tusOpenApiSpec-DF0-hlWV.js +1 -0
  88. package/dist/packem_shared/{types.d-DBjmJvIT.d.ts → types.d-BCN94sB_.d.ts} +1 -1
  89. package/dist/packem_shared/{types.d-DviSTLOg.d.ts → types.d-D4caL2Fp.d.ts} +1 -1
  90. package/dist/packem_shared/update-size-DANV7aa2.js +1 -0
  91. package/dist/packem_shared/validator-DK41xp8N.js +1 -0
  92. package/dist/packem_shared/waitForStorage-ChSBLhLc.js +1 -0
  93. package/dist/packem_shared/wasabi-Dmce4x9s.js +1 -0
  94. package/dist/packem_shared/xhrOpenApiSpec-nyoboz83.js +1 -0
  95. package/dist/storage/aws/clients/index.js +1 -6
  96. package/dist/storage/aws/index.js +1 -3
  97. package/dist/storage/aws-light/index.js +1 -3
  98. package/dist/storage/azure/index.js +1 -3
  99. package/dist/storage/gcs/index.js +1 -4
  100. package/dist/storage/local/index.js +1 -3
  101. package/dist/storage/netlify-blob/index.js +1 -3
  102. package/dist/storage/vercel-blob/index.js +1 -3
  103. package/dist/transformer/audio-transformer.d.ts +1 -1
  104. package/dist/transformer/audio-transformer.js +1 -278
  105. package/dist/transformer/image-transformer.d.ts +1 -1
  106. package/dist/transformer/image-transformer.js +1 -1100
  107. package/dist/transformer/index.d.ts +2 -2
  108. package/dist/transformer/index.js +1 -4
  109. package/dist/transformer/video-transformer.d.ts +1 -1
  110. package/dist/transformer/video-transformer.js +1 -310
  111. package/package.json +18 -18
  112. package/dist/packem_shared/AwsLightFile-C-Nd5rtl.js +0 -11
  113. package/dist/packem_shared/AwsLightMetaStorage-BIDb5EPg.js +0 -4
  114. package/dist/packem_shared/AwsLightStorage-CMuKw4bI.js +0 -133
  115. package/dist/packem_shared/AzureFile-C0kug4w4.js +0 -8
  116. package/dist/packem_shared/AzureSMetaStorage-BEbXX9Uk.js +0 -89
  117. package/dist/packem_shared/AzureStorage-98-LRZ1e.js +0 -359
  118. package/dist/packem_shared/BaseTransformer-9965D4pb.js +0 -83
  119. package/dist/packem_shared/DiskStorage-COMe_G42.js +0 -12
  120. package/dist/packem_shared/DiskStorageWithChecksum-BVaaZiyS.js +0 -249
  121. package/dist/packem_shared/ERRORS-D0apMqnc.js +0 -97
  122. package/dist/packem_shared/File-CPUhj3DI.js +0 -69
  123. package/dist/packem_shared/GCSConfig-vPP22kN6.js +0 -11
  124. package/dist/packem_shared/GCSFile-DaDiCKE2.js +0 -8
  125. package/dist/packem_shared/GCSMetaStorage-BygVH0Ee.js +0 -7
  126. package/dist/packem_shared/GCStorage-4hSx_bN1.js +0 -410
  127. package/dist/packem_shared/LocalMetaStorage-DvnZqf61.js +0 -7
  128. package/dist/packem_shared/MediaTransformer-BRRqYA0E.js +0 -1202
  129. package/dist/packem_shared/MetaStorage-pECeFOad.js +0 -46
  130. package/dist/packem_shared/Metadata-DRLXeJ0F.js +0 -89
  131. package/dist/packem_shared/Multipart-BzzvNxt4.js +0 -128
  132. package/dist/packem_shared/Multipart-DLtFLQ8s.js +0 -163
  133. package/dist/packem_shared/NetlifyBlobFile-CfyJtGWN.js +0 -14
  134. package/dist/packem_shared/NetlifyBlobMetaStorage-eJT6RFy9.js +0 -9
  135. package/dist/packem_shared/NetlifyBlobStorage-nPv7iIAG.js +0 -376
  136. package/dist/packem_shared/NoOpMetrics-DhAk5rXc.js +0 -10
  137. package/dist/packem_shared/OpenTelemetryMetrics-BnxhqIaH.js +0 -67
  138. package/dist/packem_shared/Rest-DEa7IA9R.js +0 -267
  139. package/dist/packem_shared/Rest-qhMbCn5a.js +0 -228
  140. package/dist/packem_shared/S3File-BXCuJaQZ.js +0 -11
  141. package/dist/packem_shared/S3MetaStorage-yT4CznlV.js +0 -77
  142. package/dist/packem_shared/S3Storage-wi5XT-yu.js +0 -317
  143. package/dist/packem_shared/TUS_RESUMABLE-Dtfsffnj.js +0 -434
  144. package/dist/packem_shared/Tus-Ck0Hdle5.js +0 -195
  145. package/dist/packem_shared/Tus-_0vCdHyB.js +0 -200
  146. package/dist/packem_shared/ValidationError-BfF1aE4h.js +0 -26
  147. package/dist/packem_shared/VercelBlobFile-DkFIIb9Q.js +0 -18
  148. package/dist/packem_shared/VercelBlobMetaStorage-DjFmi4vp.js +0 -9
  149. package/dist/packem_shared/VercelBlobStorage-CmMgiDgr.js +0 -261
  150. package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
  151. package/dist/packem_shared/aws-light-meta-storage-BGZEiY3y.js +0 -447
  152. package/dist/packem_shared/backblaze-BlMnIcBC.js +0 -20
  153. package/dist/packem_shared/base-handler-core-lVB-D59L.js +0 -306
  154. package/dist/packem_shared/base-handler-fetch-CitgN-Aw.js +0 -291
  155. package/dist/packem_shared/base-handler-node-BiO2DF87.js +0 -731
  156. package/dist/packem_shared/cache-B88MXQ_2.js +0 -18
  157. package/dist/packem_shared/cloudflare-Bi1q8wXE.js +0 -21
  158. package/dist/packem_shared/defaultCloudStorageFileNameValidation-Brw40ZEP.js +0 -11
  159. package/dist/packem_shared/digitalOcean-CWQRJM3L.js +0 -21
  160. package/dist/packem_shared/disk-storage-D9RfoKjW.js +0 -832
  161. package/dist/packem_shared/gcs-meta-storage-8FovEDbW.js +0 -159
  162. package/dist/packem_shared/has-content-CY66ehMK.js +0 -3
  163. package/dist/packem_shared/headers-YLRp1dLo.js +0 -1318
  164. package/dist/packem_shared/is-expired-CTThU1q5.js +0 -8
  165. package/dist/packem_shared/isRetryableError-Dycp7127.js +0 -82
  166. package/dist/packem_shared/isValidMediaType-BeDgiObq.js +0 -35
  167. package/dist/packem_shared/local-meta-storage-D-pPc3FI.js +0 -658
  168. package/dist/packem_shared/minio-C2YBZQOw.js +0 -22
  169. package/dist/packem_shared/multipart-base-C994naBi.js +0 -102
  170. package/dist/packem_shared/part-match-Dt738Ddb.js +0 -96
  171. package/dist/packem_shared/path-aV9lMdcn-DMU5H1-h.js +0 -162
  172. package/dist/packem_shared/response-builder-BtnRiBUI.js +0 -45
  173. package/dist/packem_shared/rest-base-k1ory8uB.js +0 -457
  174. package/dist/packem_shared/restOpenApiSpec-BBJ_SiPE.js +0 -800
  175. package/dist/packem_shared/s3-base-storage-zUO8u8Cp.js +0 -510
  176. package/dist/packem_shared/sharedGet-CkSLSnMd.js +0 -1022
  177. package/dist/packem_shared/storage-5XW1E7XU.js +0 -1188
  178. package/dist/packem_shared/tigris-Hac8TKnX.js +0 -21
  179. package/dist/packem_shared/transformOpenApiSpec-BodFhFls.js +0 -975
  180. package/dist/packem_shared/tusOpenApiSpec-DzppyJTW.js +0 -740
  181. package/dist/packem_shared/update-size-CCGm6i1J.js +0 -8
  182. package/dist/packem_shared/validator-DuO17wFF.js +0 -79
  183. package/dist/packem_shared/waitForStorage-Cscw85sx.js +0 -18
  184. package/dist/packem_shared/wasabi-DIyflHSd.js +0 -21
  185. package/dist/packem_shared/xhrOpenApiSpec-CXz7BC5J.js +0 -264
@@ -1,200 +0,0 @@
1
- import { c as createHttpError } from './headers-YLRp1dLo.js';
2
- import { B as BaseHandlerFetch } from './base-handler-fetch-CitgN-Aw.js';
3
- import { TusBase } from './TUS_RESUMABLE-Dtfsffnj.js';
4
- export { TUS_RESUMABLE, TUS_VERSION } from './TUS_RESUMABLE-Dtfsffnj.js';
5
-
6
- const getIdFromRequestUrl = (url) => {
7
- try {
8
- const urlObject = new URL(url);
9
- const pathParts = urlObject.pathname.split("/").filter(Boolean);
10
- return pathParts[pathParts.length - 1] || void 0;
11
- } catch {
12
- return void 0;
13
- }
14
- };
15
- class Tus extends BaseHandlerFetch {
16
- /**
17
- * Limiting enabled http method handler
18
- */
19
- static methods = ["delete", "download", "get", "head", "options", "patch", "post"];
20
- tusBase;
21
- constructor(options) {
22
- super(options);
23
- this.disableTerminationForFinishedUploads = options.disableTerminationForFinishedUploads ?? false;
24
- const tusInstance = this;
25
- this.tusBase = new class extends TusBase {
26
- // eslint-disable-next-line class-methods-use-this
27
- get storage() {
28
- return tusInstance.storage;
29
- }
30
- // eslint-disable-next-line class-methods-use-this
31
- get disableTerminationForFinishedUploads() {
32
- return tusInstance.disableTerminationForFinishedUploads ?? false;
33
- }
34
- // eslint-disable-next-line class-methods-use-this
35
- buildFileUrl(requestUrl, file) {
36
- return tusInstance.buildFileUrlForTus(requestUrl, file);
37
- }
38
- }();
39
- }
40
- /**
41
- * Handle OPTIONS requests with TUS protocol capabilities.
42
- * @returns Promise resolving to ResponseFile with TUS headers
43
- */
44
- async options() {
45
- return this.tusBase.handleOptions(Tus.methods);
46
- }
47
- /**
48
- * Creates a new TUS upload and optionally starts uploading data.
49
- * @param request Web API Request with TUS headers.
50
- * @returns Promise resolving to ResponseFile with upload location and offset.
51
- */
52
- async post(request) {
53
- const tusResumable = request.headers.get("tus-resumable");
54
- this.tusBase.validateTusResumableHeader(tusResumable || void 0);
55
- const uploadLength = request.headers.get("upload-length") || void 0;
56
- const uploadDeferLength = request.headers.get("upload-defer-length") || void 0;
57
- const uploadConcat = request.headers.get("upload-concat") || void 0;
58
- const metadataHeader = request.headers.get("upload-metadata") || void 0;
59
- const contentType = request.headers.get("content-type") || "";
60
- const contentLengthHeader = request.headers.get("content-length");
61
- const contentLength = contentLengthHeader ? Number.parseInt(contentLengthHeader, 10) : 0;
62
- const requestUrl = request.url;
63
- const bodyStream = request.body;
64
- return this.tusBase.handlePost(uploadLength, uploadDeferLength, uploadConcat, metadataHeader, requestUrl, bodyStream, contentLength, contentType);
65
- }
66
- /**
67
- * Write a chunk of data to an existing TUS upload.
68
- * @param request Web API Request with chunk data and TUS headers
69
- * @returns Promise resolving to ResponseFile with updated offset
70
- */
71
- async patch(request) {
72
- const tusResumable = request.headers.get("tus-resumable");
73
- this.tusBase.validateTusResumableHeader(tusResumable || void 0);
74
- const id = getIdFromRequestUrl(request.url);
75
- if (!id) {
76
- throw createHttpError(404, "File not found");
77
- }
78
- const uploadOffsetHeader = request.headers.get("upload-offset");
79
- if (!uploadOffsetHeader) {
80
- throw createHttpError(412, "Missing Upload-Offset header");
81
- }
82
- const contentType = request.headers.get("content-type");
83
- if (!contentType) {
84
- throw createHttpError(412, "Content-Type header required");
85
- }
86
- if (contentType !== "application/offset+octet-stream") {
87
- throw createHttpError(415, "Unsupported Media Type");
88
- }
89
- const uploadOffset = Number.parseInt(uploadOffsetHeader, 10);
90
- const uploadLength = request.headers.get("upload-length") || void 0;
91
- const metadataHeader = request.headers.get("upload-metadata") || void 0;
92
- const contentLengthHeader = request.headers.get("content-length");
93
- const contentLength = contentLengthHeader ? Number.parseInt(contentLengthHeader, 10) : 0;
94
- const checksumHeader = request.headers.get("upload-checksum") || void 0;
95
- const { checksum, checksumAlgorithm } = this.tusBase.extractChecksum(checksumHeader);
96
- const requestUrl = request.url;
97
- const bodyStream = request.body;
98
- try {
99
- return this.tusBase.handlePatch(id, uploadOffset, uploadLength, metadataHeader, checksum, checksumAlgorithm, requestUrl, bodyStream, contentLength);
100
- } catch (error) {
101
- const errorWithCode = error;
102
- if (errorWithCode.UploadErrorCode === "GONE" || errorWithCode.UploadErrorCode === "FILE_NOT_FOUND") {
103
- throw createHttpError(410, "Upload expired");
104
- }
105
- throw error;
106
- }
107
- }
108
- /**
109
- * Get current upload offset and metadata for TUS resumable uploads.
110
- * @param request Web API Request with upload ID
111
- * @returns Promise resolving to ResponseFile with upload-offset and metadata headers
112
- */
113
- async head(request) {
114
- const tusResumable = request.headers.get("tus-resumable");
115
- this.tusBase.validateTusResumableHeader(tusResumable || void 0);
116
- const id = getIdFromRequestUrl(request.url);
117
- if (!id) {
118
- throw createHttpError(404, "File not found");
119
- }
120
- try {
121
- return this.tusBase.handleHead(id);
122
- } catch (error) {
123
- const errorWithCode = error;
124
- if (errorWithCode.UploadErrorCode === "GONE" || errorWithCode.UploadErrorCode === "FILE_NOT_FOUND") {
125
- throw createHttpError(410, "Upload expired");
126
- }
127
- throw error;
128
- }
129
- }
130
- /**
131
- * Get TUS upload metadata and current status.
132
- * @param request Web API Request with upload ID
133
- * @returns Promise resolving to ResponseFile with file metadata as JSON
134
- */
135
- async get(request) {
136
- const tusResumable = request.headers.get("tus-resumable");
137
- this.tusBase.validateTusResumableHeader(tusResumable || void 0);
138
- const id = getIdFromRequestUrl(request.url);
139
- if (!id) {
140
- throw createHttpError(404, "File not found");
141
- }
142
- try {
143
- return this.tusBase.handleGet(id);
144
- } catch (error) {
145
- const errorWithCode = error;
146
- if (errorWithCode.UploadErrorCode === "GONE") {
147
- throw createHttpError(410, "Upload expired");
148
- }
149
- throw error;
150
- }
151
- }
152
- /**
153
- * Delete a TUS upload and its associated data.
154
- * @param request Web API Request with upload ID
155
- * @returns Promise resolving to ResponseFile with deletion confirmation
156
- */
157
- async delete(request) {
158
- const tusResumable = request.headers.get("tus-resumable");
159
- this.tusBase.validateTusResumableHeader(tusResumable || void 0);
160
- const id = getIdFromRequestUrl(request.url);
161
- if (!id) {
162
- throw createHttpError(404, "File not found");
163
- }
164
- try {
165
- return this.tusBase.handleDelete(id);
166
- } catch (error) {
167
- const errorWithCode = error;
168
- if (errorWithCode.code === "ENOENT") {
169
- throw createHttpError(404, "File not found");
170
- }
171
- throw error;
172
- }
173
- }
174
- /**
175
- * Compose and register HTTP method handlers.
176
- */
177
- compose() {
178
- this.registeredHandlers.set("POST", this.post.bind(this));
179
- this.registeredHandlers.set("PATCH", this.patch.bind(this));
180
- this.registeredHandlers.set("HEAD", this.head.bind(this));
181
- this.registeredHandlers.set("GET", this.get.bind(this));
182
- this.registeredHandlers.set("DELETE", this.delete.bind(this));
183
- this.registeredHandlers.set("OPTIONS", this.options.bind(this));
184
- this.logger?.debug("Registered handler: %s", [...this.registeredHandlers.keys()].join(", "));
185
- }
186
- /**
187
- * Build file URL for TUS uploads (without file extension).
188
- * @param requestUrl Request URL string
189
- * @param file File object containing ID
190
- * @returns Constructed file URL for TUS protocol
191
- */
192
- buildFileUrlForTus(requestUrl, file) {
193
- const url = new URL(requestUrl);
194
- const { pathname, search } = url;
195
- const relative = `${pathname}/${file.id}${search}`;
196
- return this.storage.config.useRelativeLocation ? relative : url.origin + relative;
197
- }
198
- }
199
-
200
- export { Tus };
@@ -1,26 +0,0 @@
1
- class ValidationError extends Error {
2
- code;
3
- details;
4
- /**
5
- * Creates a new ValidationError instance with detailed error information.
6
- * @param message Human-readable error message describing the validation failure
7
- * @param code Machine-readable error code for programmatic error handling
8
- * @param mediaType The media type where validation failed ('image', 'video', or 'audio')
9
- * @param invalidParameters Array of parameter names that were invalid
10
- * @param validParameters Array of valid parameter names or values
11
- * @param suggestions Optional array of suggested corrections or valid values
12
- */
13
- constructor(message, code, mediaType, invalidParameters, validParameters, suggestions) {
14
- super(message);
15
- this.name = "ValidationError";
16
- this.code = code;
17
- this.details = {
18
- invalidParams: invalidParameters,
19
- mediaType,
20
- suggestions,
21
- validParams: validParameters
22
- };
23
- }
24
- }
25
-
26
- export { ValidationError as default };
@@ -1,18 +0,0 @@
1
- import File from './File-CPUhj3DI.js';
2
-
3
- class VercelBlobFile extends File {
4
- /**
5
- * The blob's public URL
6
- */
7
- url;
8
- /**
9
- * The blob's download URL (may be different from url for private blobs)
10
- */
11
- downloadUrl;
12
- /**
13
- * The blob's pathname within the store
14
- */
15
- pathname;
16
- }
17
-
18
- export { VercelBlobFile as default };
@@ -1,9 +0,0 @@
1
- import { L as LocalMetaStorage } from './local-meta-storage-D-pPc3FI.js';
2
-
3
- class VercelBlobMetaStorage extends LocalMetaStorage {
4
- constructor(config) {
5
- super(config);
6
- }
7
- }
8
-
9
- export { VercelBlobMetaStorage as default };
@@ -1,261 +0,0 @@
1
- import { put, del, copy, list } from '@vercel/blob';
2
- import { g as getFileStatus, p as partMatch, a as detectFileTypeFromBuffer } from './part-match-Dt738Ddb.js';
3
- import { B as BaseStorage, t as toMilliseconds } from './storage-5XW1E7XU.js';
4
- import { L as LocalMetaStorage } from './local-meta-storage-D-pPc3FI.js';
5
- import VercelBlobFile from './VercelBlobFile-DkFIIb9Q.js';
6
- import { u as updateSize } from './update-size-CCGm6i1J.js';
7
- import { h as hasContent } from './has-content-CY66ehMK.js';
8
-
9
- class VercelBlobStorage extends BaseStorage {
10
- static name = "vercel-blob";
11
- checksumTypes = ["md5"];
12
- meta;
13
- token;
14
- multipart;
15
- constructor(config) {
16
- super(config);
17
- this.token = config.token || process.env.BLOB_READ_WRITE_TOKEN || process.env.VERCEL_BLOB_TOKEN || "";
18
- if (!this.token) {
19
- throw new Error("Vercel Blob token is required. Set BLOB_READ_WRITE_TOKEN or VERCEL_BLOB_TOKEN environment variable, or provide token in config.");
20
- }
21
- this.multipart = config.multipart ?? false;
22
- const { metaStorage, metaStorageConfig } = config;
23
- this.meta = metaStorage || new LocalMetaStorage(metaStorageConfig);
24
- this.isReady = true;
25
- }
26
- async create(config) {
27
- return this.instrumentOperation("create", async () => {
28
- const processedConfig = { ...config };
29
- if (config.ttl) {
30
- const ttlMs = typeof config.ttl === "string" ? toMilliseconds(config.ttl) : config.ttl;
31
- processedConfig.expiredAt = ttlMs === void 0 ? void 0 : Date.now() + ttlMs;
32
- }
33
- const file = new VercelBlobFile(processedConfig);
34
- file.name = this.namingFunction(file);
35
- await this.validate(file);
36
- try {
37
- const existing = await this.getMeta(file.id);
38
- if (existing.bytesWritten >= 0) {
39
- return existing;
40
- }
41
- } catch {
42
- }
43
- file.bytesWritten = 0;
44
- file.status = getFileStatus(file);
45
- await this.saveMeta(file);
46
- await this.onCreate(file);
47
- return file;
48
- });
49
- }
50
- async write(part) {
51
- return this.instrumentOperation("write", async () => {
52
- let file;
53
- if ("contentType" in part && "metadata" in part && !("body" in part) && !("start" in part)) {
54
- file = part;
55
- } else {
56
- file = await this.getMeta(part.id);
57
- await this.checkIfExpired(file);
58
- }
59
- if (file.status === "completed") {
60
- return file;
61
- }
62
- if (part.size !== void 0) {
63
- updateSize(file, part.size);
64
- }
65
- if (!partMatch(part, file)) {
66
- throw new Error("File part does not match");
67
- }
68
- await this.lock(part.id);
69
- try {
70
- if (hasContent(part)) {
71
- if (this.isUnsupportedChecksum(part.checksumAlgorithm)) {
72
- throw new Error("Unsupported checksum algorithm");
73
- }
74
- const chunks = [];
75
- const stream = part.body;
76
- for await (const chunk of stream) {
77
- chunks.push(Buffer.from(chunk));
78
- }
79
- const buffer = Buffer.concat(chunks);
80
- if ((file.bytesWritten === 0 || Number.isNaN(file.bytesWritten)) && (!file.contentType || file.contentType === "application/octet-stream")) {
81
- try {
82
- const fileType = await detectFileTypeFromBuffer(buffer);
83
- if (fileType?.mime) {
84
- file.contentType = fileType.mime;
85
- }
86
- } catch {
87
- }
88
- }
89
- const blob = new Blob([buffer], { type: file.contentType });
90
- const result = await put(file.name, blob, {
91
- access: "public",
92
- multipart: this.shouldUseMultipart(file)
93
- });
94
- file.url = result.url;
95
- file.pathname = result.pathname;
96
- file.downloadUrl = result.downloadUrl;
97
- file.bytesWritten = buffer.length;
98
- }
99
- file.status = getFileStatus(file);
100
- if (file.status === "completed") {
101
- await this.internalOnComplete(file);
102
- }
103
- await this.saveMeta(file);
104
- return file;
105
- } finally {
106
- await this.unlock(part.id);
107
- }
108
- });
109
- }
110
- /**
111
- * Deletes an upload and its metadata.
112
- * @param query File query containing the file ID to delete.
113
- * @param query.id File ID to delete.
114
- * @returns Promise resolving to the deleted file object with status: "deleted".
115
- * @throws {UploadError} If the file metadata cannot be found.
116
- */
117
- async delete({ id }) {
118
- return this.instrumentOperation("delete", async () => {
119
- const file = await this.getMeta(id);
120
- if (!file.url) {
121
- throw new Error(`File ${id} does not have a valid URL`);
122
- }
123
- file.status = "deleted";
124
- try {
125
- await del(file.url, { token: this.token });
126
- } catch (error) {
127
- this.logger?.error("Failed to delete blob from Vercel Blob:", error);
128
- const httpError = this.normalizeError(error instanceof Error ? error : new Error(String(error)));
129
- await this.onError(httpError);
130
- }
131
- await this.deleteMeta(file.id);
132
- const deletedFile = { ...file };
133
- await this.onDelete(deletedFile);
134
- return deletedFile;
135
- });
136
- }
137
- /**
138
- * Checks if a file exists by verifying both metadata and the actual Vercel Blob.
139
- * Returns true only if both the metadata and the blob exist.
140
- * @param query File query containing the file ID to check.
141
- * @returns Promise resolving to true if both metadata and blob exist, false otherwise.
142
- */
143
- async exists({ id }) {
144
- return this.instrumentOperation("exists", async () => {
145
- try {
146
- const file = await this.getMeta(id);
147
- if (!file.url || file.url.length === 0) {
148
- return false;
149
- }
150
- const response = await fetch(file.url, { method: "HEAD" });
151
- return response.ok;
152
- } catch {
153
- return false;
154
- }
155
- });
156
- }
157
- async get({ id }) {
158
- return this.instrumentOperation("get", async () => {
159
- const file = await this.checkIfExpired(await this.getMeta(id));
160
- if (!file.url || file.url.length === 0) {
161
- throw new Error("File URL not found");
162
- }
163
- const response = await fetch(file.url);
164
- const content = Buffer.from(await response.arrayBuffer());
165
- return {
166
- content,
167
- contentType: file.contentType,
168
- ETag: file.ETag,
169
- expiredAt: file.expiredAt,
170
- id,
171
- metadata: file.metadata,
172
- modifiedAt: file.modifiedAt,
173
- name: file.name,
174
- originalName: file.originalName,
175
- size: file.size || content.length
176
- };
177
- });
178
- }
179
- /**
180
- * Copies an upload file to a new location.
181
- * @param name Source file name/ID.
182
- * @param destination Destination file name/ID.
183
- * @returns Promise resolving to the copied file object.
184
- * @throws {UploadError} If the source file cannot be found.
185
- */
186
- async copy(name, destination) {
187
- return this.instrumentOperation("copy", async () => {
188
- const sourceFile = await this.getMeta(name);
189
- if (!sourceFile.url) {
190
- throw new Error("Source file URL not found");
191
- }
192
- const result = await copy(sourceFile.url, destination, {
193
- access: "public"
194
- });
195
- return {
196
- ...sourceFile,
197
- id: destination,
198
- name: destination,
199
- pathname: result.pathname,
200
- url: result.url
201
- };
202
- });
203
- }
204
- /**
205
- * Moves an upload file to a new location.
206
- * @param name Source file name/ID.
207
- * @param destination Destination file name/ID.
208
- * @returns Promise resolving to the moved file object.
209
- * @throws {UploadError} If the source file cannot be found.
210
- */
211
- async move(name, destination) {
212
- return this.instrumentOperation("move", async () => {
213
- const copiedFile = await this.copy(name, destination);
214
- await this.delete({ id: name });
215
- return copiedFile;
216
- });
217
- }
218
- async list(limit = 1e3) {
219
- return this.instrumentOperation(
220
- "list",
221
- async () => {
222
- const result = await list({ limit });
223
- return result.blobs.map((blob) => {
224
- const file = new VercelBlobFile({
225
- contentType: "application/octet-stream",
226
- // Default content type
227
- metadata: {},
228
- originalName: blob.pathname
229
- });
230
- file.createdAt = blob.uploadedAt?.toISOString();
231
- file.id = blob.pathname;
232
- file.modifiedAt = blob.uploadedAt?.toISOString();
233
- file.name = blob.pathname;
234
- file.pathname = blob.pathname;
235
- file.size = blob.size;
236
- file.url = blob.url;
237
- file.downloadUrl = blob.downloadUrl;
238
- return file;
239
- });
240
- },
241
- { limit }
242
- );
243
- }
244
- internalOnComplete = (file) => this.deleteMeta(file.id);
245
- /**
246
- * Determines if multipart upload should be used for the given file.
247
- * @param file File object to check.
248
- * @returns True if multipart upload should be used, false otherwise.
249
- */
250
- shouldUseMultipart(file) {
251
- if (typeof this.multipart === "boolean") {
252
- return this.multipart;
253
- }
254
- if (typeof this.multipart === "number" && file.size !== void 0) {
255
- return file.size >= this.multipart;
256
- }
257
- return false;
258
- }
259
- }
260
-
261
- export { VercelBlobStorage as default };
@@ -1,5 +0,0 @@
1
- function getDefaultExportFromCjs(x) {
2
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3
- }
4
-
5
- export { getDefaultExportFromCjs as g };