@visulima/storage 1.0.0-alpha.1 → 1.0.0-alpha.11
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/CHANGELOG.md +170 -0
- package/LICENSE.md +6 -6
- package/README.md +33 -14
- package/dist/adapter/nuxt/module.d.ts +39 -0
- package/dist/adapter/nuxt/module.js +93 -0
- package/dist/adapter/nuxt/package.json +20 -0
- package/dist/handler/base/base-handler-core.d.ts +91 -0
- package/dist/handler/base/base-handler-fetch.d.ts +76 -0
- package/dist/handler/base/base-handler-node.d.ts +137 -0
- package/dist/handler/http/fetch/index.d.ts +4 -0
- package/dist/handler/http/fetch/index.js +4 -0
- package/dist/handler/http/hono/index.d.ts +67 -0
- package/dist/handler/http/hono/index.js +65 -0
- package/dist/handler/http/nextjs/index.d.ts +61 -0
- package/dist/handler/http/nextjs/index.js +37 -0
- package/dist/handler/http/node/index.d.ts +4 -0
- package/dist/handler/http/node/index.js +8 -0
- package/dist/handler/http/solid-start/index.d.ts +60 -0
- package/dist/handler/http/solid-start/index.js +44 -0
- package/dist/handler/multipart/multipart-base.d.ts +84 -0
- package/dist/handler/multipart/multipart-fetch.d.ts +64 -0
- package/dist/handler/multipart/multipart.d.ts +49 -0
- package/dist/handler/rest/rest-base.d.ts +106 -0
- package/dist/handler/rest/rest-fetch.d.ts +88 -0
- package/dist/handler/rest/rest.d.ts +93 -0
- package/dist/handler/tus/tus-base.d.ts +152 -0
- package/dist/handler/tus/tus-fetch.d.ts +72 -0
- package/dist/handler/tus/tus.d.ts +78 -0
- package/dist/handler/types.d.ts +53 -0
- package/dist/handler/utils/request-parser.d.ts +72 -0
- package/dist/handler/utils/response-builder.d.ts +83 -0
- package/dist/handler/utils/storage-utils.d.ts +10 -0
- package/dist/handler/utils/stream-utils.d.ts +29 -0
- package/dist/handler/utils/upload-handlers.d.ts +76 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +13 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/no-op-metrics.d.ts +15 -0
- package/dist/metrics/opentelemetry-metrics.d.ts +55 -0
- package/dist/openapi/index.d.ts +5 -0
- package/dist/openapi/index.js +5 -0
- package/dist/openapi/rest.d.ts +7 -0
- package/dist/openapi/shared.d.ts +13 -0
- package/dist/openapi/transform.d.ts +3 -0
- package/dist/openapi/tus.d.ts +7 -0
- package/dist/openapi/xhr.d.ts +7 -0
- package/dist/packem_shared/AwsLightFile-tTneXZgG.js +11 -0
- package/dist/packem_shared/AwsLightMetaStorage-D9qWQt6q.js +4 -0
- package/dist/packem_shared/AwsLightStorage-CEJTYBVv.js +133 -0
- package/dist/packem_shared/AzureFile-CesgFzps.js +8 -0
- package/dist/packem_shared/AzureSMetaStorage-BEbXX9Uk.js +89 -0
- package/dist/packem_shared/AzureStorage-CH6nvQx8.js +357 -0
- package/dist/packem_shared/BaseTransformer-9965D4pb.js +83 -0
- package/dist/packem_shared/DiskStorage-DziI2mwX.js +12 -0
- package/dist/packem_shared/DiskStorageWithChecksum-B_XY8_cO.js +240 -0
- package/dist/packem_shared/ERRORS-D0apMqnc.js +97 -0
- package/dist/packem_shared/File-Bb3P23dr.js +69 -0
- package/dist/packem_shared/GCSConfig-vPP22kN6.js +11 -0
- package/dist/packem_shared/GCSFile-BIEunhAN.js +8 -0
- package/dist/packem_shared/GCSMetaStorage-FypK8Tn1.js +7 -0
- package/dist/packem_shared/GCStorage-CasTo9rF.js +408 -0
- package/dist/packem_shared/LocalMetaStorage-BnllcjV9.js +7 -0
- package/dist/packem_shared/MediaTransformer-BErvw2vE.js +1196 -0
- package/dist/packem_shared/MetaStorage-pECeFOad.js +46 -0
- package/dist/packem_shared/Metadata-DRLXeJ0F.js +89 -0
- package/dist/packem_shared/Multipart-CDDlDOs7.js +163 -0
- package/dist/packem_shared/Multipart-vxBL2VXm.js +128 -0
- package/dist/packem_shared/NetlifyBlobFile-CXzyjqrD.js +14 -0
- package/dist/packem_shared/NetlifyBlobMetaStorage-DIkZ2umW.js +9 -0
- package/dist/packem_shared/NetlifyBlobStorage-DEpx_4q-.js +376 -0
- package/dist/packem_shared/NoOpMetrics-DhAk5rXc.js +10 -0
- package/dist/packem_shared/OpenTelemetryMetrics-BnxhqIaH.js +67 -0
- package/dist/packem_shared/Rest-CEj3EhMj.js +228 -0
- package/dist/packem_shared/Rest-D14vM7aJ.js +267 -0
- package/dist/packem_shared/S3File-DZiyk9Qt.js +11 -0
- package/dist/packem_shared/S3MetaStorage-yT4CznlV.js +77 -0
- package/dist/packem_shared/S3Storage-B0scgwPa.js +317 -0
- package/dist/packem_shared/TUS_RESUMABLE-Dtfsffnj.js +434 -0
- package/dist/packem_shared/Tus-Cjz87bpz.js +200 -0
- package/dist/packem_shared/Tus-WOVg-YnB.js +195 -0
- package/dist/packem_shared/ValidationError-BfF1aE4h.js +26 -0
- package/dist/packem_shared/VercelBlobFile-BCg4aTEq.js +18 -0
- package/dist/packem_shared/VercelBlobMetaStorage-c0M-TvAR.js +9 -0
- package/dist/packem_shared/VercelBlobStorage-wOYxv8F7.js +261 -0
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +5 -0
- package/dist/packem_shared/aws-light-meta-storage-Ba2b_h-o.js +447 -0
- package/dist/packem_shared/backblaze-BlMnIcBC.js +20 -0
- package/dist/packem_shared/base-handler-core-BoAqTyz7.js +303 -0
- package/dist/packem_shared/base-handler-fetch-CinvR65S.js +291 -0
- package/dist/packem_shared/base-handler-node-c02H0AxN.js +731 -0
- package/dist/packem_shared/cache-B88MXQ_2.js +18 -0
- package/dist/packem_shared/cloudflare-Bi1q8wXE.js +21 -0
- package/dist/packem_shared/defaultCloudStorageFileNameValidation-CGoYrGB2.js +11 -0
- package/dist/packem_shared/digitalOcean-CWQRJM3L.js +21 -0
- package/dist/packem_shared/disk-storage-DeivH-J5.js +816 -0
- package/dist/packem_shared/gcs-meta-storage-B0Baj0Xr.js +159 -0
- package/dist/packem_shared/has-content-CY66ehMK.js +3 -0
- package/dist/packem_shared/headers-YLRp1dLo.js +1318 -0
- package/dist/packem_shared/is-expired-CTThU1q5.js +8 -0
- package/dist/packem_shared/isRetryableError-Dycp7127.js +82 -0
- package/dist/packem_shared/isValidMediaType-BeDgiObq.js +35 -0
- package/dist/packem_shared/local-meta-storage-BlOk6m7F.js +647 -0
- package/dist/packem_shared/minio-C2YBZQOw.js +22 -0
- package/dist/packem_shared/multipart-base-C994naBi.js +102 -0
- package/dist/packem_shared/part-match-BMNqHDYD.js +96 -0
- package/dist/packem_shared/path-aV9lMdcn-DMU5H1-h.js +162 -0
- package/dist/packem_shared/response-builder-BtnRiBUI.js +45 -0
- package/dist/packem_shared/rest-base-D9URIFkc.js +457 -0
- package/dist/packem_shared/restOpenApiSpec-D1zbmid7.js +800 -0
- package/dist/packem_shared/s3-base-storage-CG21uusd.js +513 -0
- package/dist/packem_shared/sharedGet-DAyJfjhl.js +1018 -0
- package/dist/packem_shared/storage-CpJpqLdn.js +1184 -0
- package/dist/packem_shared/tigris-Hac8TKnX.js +21 -0
- package/dist/packem_shared/transformOpenApiSpec-BC0r6PzI.js +975 -0
- package/dist/packem_shared/tusOpenApiSpec-BLIjKf0s.js +740 -0
- package/dist/packem_shared/update-size-CCGm6i1J.js +8 -0
- package/dist/packem_shared/validator-DuO17wFF.js +79 -0
- package/dist/packem_shared/waitForStorage-Cscw85sx.js +18 -0
- package/dist/packem_shared/wasabi-DIyflHSd.js +21 -0
- package/dist/packem_shared/xhrOpenApiSpec-kItrSAsc.js +264 -0
- package/dist/storage/aws/clients/backblaze.d.ts +12 -0
- package/dist/storage/aws/clients/cloudflare.d.ts +13 -0
- package/dist/storage/aws/clients/digital-ocean.d.ts +12 -0
- package/dist/storage/aws/clients/index.d.ts +6 -0
- package/dist/storage/aws/clients/index.js +6 -0
- package/dist/storage/aws/clients/minio.d.ts +13 -0
- package/dist/storage/aws/clients/tigris.d.ts +12 -0
- package/dist/storage/aws/clients/types.d.ts +95 -0
- package/dist/storage/aws/clients/wasabi.d.ts +12 -0
- package/dist/storage/aws/index.d.ts +4 -0
- package/dist/storage/aws/index.js +3 -0
- package/dist/storage/aws/s3-base-storage.d.ts +248 -0
- package/dist/storage/aws/s3-client-adapter.d.ts +110 -0
- package/dist/storage/aws/s3-file.d.ts +10 -0
- package/dist/storage/aws/s3-meta-storage.d.ts +15 -0
- package/dist/storage/aws/s3-storage.d.ts +70 -0
- package/dist/storage/aws/types.d.ts +119 -0
- package/dist/storage/aws-light/aws-light-api-adapter.d.ts +130 -0
- package/dist/storage/aws-light/aws-light-file.d.ts +10 -0
- package/dist/storage/aws-light/aws-light-meta-storage.d.ts +19 -0
- package/dist/storage/aws-light/aws-light-storage.d.ts +65 -0
- package/dist/storage/aws-light/index.d.ts +4 -0
- package/dist/storage/aws-light/index.js +3 -0
- package/dist/storage/aws-light/types.d.ts +37 -0
- package/dist/storage/azure/azure-file.d.ts +6 -0
- package/dist/storage/azure/azure-meta-storage.d.ts +15 -0
- package/dist/storage/azure/azure-storage.d.ts +69 -0
- package/dist/storage/azure/index.d.ts +4 -0
- package/dist/storage/azure/index.js +3 -0
- package/dist/storage/azure/types.d.ts +62 -0
- package/dist/storage/gcs/fetch-error.d.ts +11 -0
- package/dist/storage/gcs/gcs-config.d.ts +2 -0
- package/dist/storage/gcs/gcs-file.d.ts +6 -0
- package/dist/storage/gcs/gcs-meta-storage.d.ts +27 -0
- package/dist/storage/gcs/gcs-storage.d.ts +91 -0
- package/dist/storage/gcs/index.d.ts +5 -0
- package/dist/storage/gcs/index.js +4 -0
- package/dist/storage/gcs/types.d.ts +55 -0
- package/dist/storage/gcs/utils.d.ts +7 -0
- package/dist/storage/local/disk-storage-with-checksum.d.ts +15 -0
- package/dist/storage/local/disk-storage.d.ts +135 -0
- package/dist/storage/local/index.d.ts +4 -0
- package/dist/storage/local/index.js +3 -0
- package/dist/storage/local/local-meta-storage.d.ts +32 -0
- package/dist/storage/meta-storage.d.ts +30 -0
- package/dist/storage/netlify-blob/index.d.ts +4 -0
- package/dist/storage/netlify-blob/index.js +3 -0
- package/dist/storage/netlify-blob/netlify-blob-file.d.ts +12 -0
- package/dist/storage/netlify-blob/netlify-blob-meta-storage.d.ts +7 -0
- package/dist/storage/netlify-blob/netlify-blob-storage.d.ts +93 -0
- package/dist/storage/netlify-blob/types.d.ts +30 -0
- package/dist/storage/storage.d.ts +353 -0
- package/dist/storage/types.d.ts +221 -0
- package/dist/storage/utils/file/file.d.ts +25 -0
- package/dist/storage/utils/file/get-file-status.d.ts +9 -0
- package/dist/storage/utils/file/has-content.d.ts +9 -0
- package/dist/storage/utils/file/index.d.ts +10 -0
- package/dist/storage/utils/file/is-expired.d.ts +8 -0
- package/dist/storage/utils/file/metadata.d.ts +18 -0
- package/dist/storage/utils/file/part-match.d.ts +11 -0
- package/dist/storage/utils/file/types.d.ts +37 -0
- package/dist/storage/utils/file/update-metadata.d.ts +10 -0
- package/dist/storage/utils/file/update-size.d.ts +10 -0
- package/dist/storage/vercel-blob/index.d.ts +4 -0
- package/dist/storage/vercel-blob/index.js +3 -0
- package/dist/storage/vercel-blob/types.d.ts +32 -0
- package/dist/storage/vercel-blob/vercel-blob-file.d.ts +16 -0
- package/dist/storage/vercel-blob/vercel-blob-meta-storage.d.ts +7 -0
- package/dist/storage/vercel-blob/vercel-blob-storage.d.ts +76 -0
- package/dist/transformer/audio-transformer.d.ts +128 -0
- package/dist/transformer/audio-transformer.js +278 -0
- package/dist/transformer/base-transformer.d.ts +63 -0
- package/dist/transformer/image-transformer.d.ts +571 -0
- package/dist/transformer/image-transformer.js +1100 -0
- package/dist/transformer/index.d.ts +5 -0
- package/dist/transformer/index.js +4 -0
- package/dist/transformer/media-transformer.d.ts +332 -0
- package/dist/transformer/types.d.ts +652 -0
- package/dist/transformer/utils.d.ts +33 -0
- package/dist/transformer/validation-error.d.ts +23 -0
- package/dist/transformer/video-transformer.d.ts +145 -0
- package/dist/transformer/video-transformer.js +310 -0
- package/dist/utils/cache.d.ts +32 -0
- package/dist/utils/chunked-upload.d.ts +65 -0
- package/dist/utils/detect-file-type.d.ts +28 -0
- package/dist/utils/errors.d.ts +74 -0
- package/dist/utils/file-path-url-matcher.d.ts +18 -0
- package/dist/utils/headers.d.ts +111 -0
- package/dist/utils/http.d.ts +92 -0
- package/dist/utils/locker.d.ts +26 -0
- package/dist/utils/pipes/stream-checksum.d.ts +47 -0
- package/dist/utils/pipes/stream-length.d.ts +22 -0
- package/dist/utils/primitives/get-last-one.d.ts +3 -0
- package/dist/utils/primitives/is-record.d.ts +2 -0
- package/dist/utils/primitives/map-values.d.ts +9 -0
- package/dist/utils/primitives/pick.d.ts +2 -0
- package/dist/utils/primitives/to-milliseconds.d.ts +12 -0
- package/dist/utils/primitives/to-seconds.d.ts +12 -0
- package/dist/utils/range-checksum.d.ts +33 -0
- package/dist/utils/range-hasher.d.ts +46 -0
- package/dist/utils/retry.d.ts +64 -0
- package/dist/utils/types.d.ts +108 -0
- package/dist/utils/validation-error.d.ts +22 -0
- package/dist/utils/validator.d.ts +36 -0
- package/package.json +9 -9
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { Readable } from "node:stream";
|
|
3
|
+
import type { UploadFile } from "../../storage/utils/index.d.ts";
|
|
4
|
+
import type { UploadResponse } from "../../utils/types.d.ts";
|
|
5
|
+
import type { AsyncHandler, Handlers, MethodHandler, ResponseFile, ResponseList, UploadOptions } from "../types.d.ts";
|
|
6
|
+
import BaseHandlerCore from "./base-handler-core.d.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Base handler for Node.js platform (IncomingMessage/ServerResponse).
|
|
9
|
+
* Extends BaseHandlerCore with Node.js-specific request/response handling.
|
|
10
|
+
* @template TFile The file type used by this handler.
|
|
11
|
+
* @template NodeRequest The Node.js request type.
|
|
12
|
+
* @template NodeResponse The Node.js response type.
|
|
13
|
+
*/
|
|
14
|
+
declare abstract class BaseHandlerNode<TFile extends UploadFile, NodeRequest extends IncomingMessage = IncomingMessage, NodeResponse extends ServerResponse = ServerResponse> extends BaseHandlerCore<TFile> implements MethodHandler<NodeRequest, NodeResponse> {
|
|
15
|
+
/**
|
|
16
|
+
* Limiting enabled HTTP method handler.
|
|
17
|
+
*/
|
|
18
|
+
static readonly methods: Handlers[];
|
|
19
|
+
/**
|
|
20
|
+
* Map of registered HTTP method handlers.
|
|
21
|
+
*/
|
|
22
|
+
protected registeredHandlers: Map<string, AsyncHandler<NodeRequest, NodeResponse>>;
|
|
23
|
+
constructor(options: UploadOptions<TFile>);
|
|
24
|
+
/**
|
|
25
|
+
* Gets the registered handlers map.
|
|
26
|
+
* @returns Map of registered handlers.
|
|
27
|
+
*/
|
|
28
|
+
get handlers(): Map<string, AsyncHandler<NodeRequest, NodeResponse>>;
|
|
29
|
+
/**
|
|
30
|
+
* Handles HTTP request (alias for upload method).
|
|
31
|
+
* @param request Node.js IncomingMessage.
|
|
32
|
+
* @param response Node.js ServerResponse.
|
|
33
|
+
*/
|
|
34
|
+
handle: (request: NodeRequest, response: NodeResponse) => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Main upload handler that processes HTTP requests and routes them to appropriate method handlers.
|
|
37
|
+
* @param request Node.js IncomingMessage.
|
|
38
|
+
* @param response Node.js ServerResponse.
|
|
39
|
+
* @param next Optional Express-style next function for middleware compatibility.
|
|
40
|
+
* @throws {UploadError} When storage is not ready or method is not allowed.
|
|
41
|
+
*/
|
|
42
|
+
upload: (request: NodeRequest, response: NodeResponse, next?: () => void) => Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Compose and register HTTP method handlers.
|
|
45
|
+
* Subclasses should override this to register their specific handlers.
|
|
46
|
+
*/
|
|
47
|
+
protected abstract compose(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Sends an HTTP response with the provided body, headers, and status code.
|
|
50
|
+
* @param response Node.js ServerResponse to send data to.
|
|
51
|
+
* @param body Response body, headers, and status code.
|
|
52
|
+
*/
|
|
53
|
+
send(response: NodeResponse, { body, headers, statusCode }: UploadResponse): void;
|
|
54
|
+
/**
|
|
55
|
+
* Sends an error response to the client with appropriate status code and message.
|
|
56
|
+
* @param response Node.js ServerResponse to send error to.
|
|
57
|
+
* @param error Error object to convert to HTTP error response.
|
|
58
|
+
*/
|
|
59
|
+
sendError(response: NodeResponse, error: Error): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Sends streaming response to client with proper backpressure handling and range request support.
|
|
62
|
+
* @param response Node.js ServerResponse to stream data to.
|
|
63
|
+
* @param stream Readable stream containing the file data.
|
|
64
|
+
* @param options Streaming options including headers, range, size, and status code.
|
|
65
|
+
*/
|
|
66
|
+
sendStream(response: NodeResponse, stream: Readable, { headers, range, size, statusCode, }: {
|
|
67
|
+
headers?: Record<string, string | number>;
|
|
68
|
+
range?: {
|
|
69
|
+
end: number;
|
|
70
|
+
start: number;
|
|
71
|
+
};
|
|
72
|
+
size?: number;
|
|
73
|
+
statusCode?: number;
|
|
74
|
+
}): void;
|
|
75
|
+
/**
|
|
76
|
+
* Finish upload by sending final response to client with completed file data.
|
|
77
|
+
* @param _request HTTP request (unused parameter)
|
|
78
|
+
* @param response HTTP response object to send final response to
|
|
79
|
+
* @param uploadResponse Final upload response data containing body, headers, and status code
|
|
80
|
+
*/
|
|
81
|
+
protected finish(_request: NodeRequest, response: NodeResponse, uploadResponse: UploadResponse | ResponseFile<TFile>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Build file URL from request and file data.
|
|
84
|
+
* @param request HTTP request with optional originalUrl property
|
|
85
|
+
* @param file File object containing ID and content type
|
|
86
|
+
* @returns Constructed file URL with extension based on content type
|
|
87
|
+
*/
|
|
88
|
+
protected buildFileUrl(request: NodeRequest & {
|
|
89
|
+
originalUrl?: string;
|
|
90
|
+
}, file: TFile): string;
|
|
91
|
+
/**
|
|
92
|
+
* Negotiates content type based on Accept header and supported formats.
|
|
93
|
+
* @param request HTTP request object containing Accept header.
|
|
94
|
+
* @param supportedTypes Array of supported MIME types to match against.
|
|
95
|
+
* @returns Best matching content type or undefined if no match found.
|
|
96
|
+
*/
|
|
97
|
+
negotiateContentType(request: NodeRequest, supportedTypes: string[]): string | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Default OPTIONS handler.
|
|
100
|
+
* @param _request HTTP request (unused)
|
|
101
|
+
* @param _response HTTP response (unused)
|
|
102
|
+
* @returns Promise resolving to ResponseFile with CORS headers
|
|
103
|
+
*/
|
|
104
|
+
options(_request: NodeRequest, _response: NodeResponse): Promise<ResponseFile<TFile>>;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves a file or list of files based on the request path.
|
|
107
|
+
* @param request Node.js IncomingMessage with optional originalUrl.
|
|
108
|
+
* @param response Node.js ServerResponse.
|
|
109
|
+
* @returns Promise resolving to a single file, paginated list, or array of files.
|
|
110
|
+
* @throws {UploadError} When file is not found or storage error occurs.
|
|
111
|
+
*/
|
|
112
|
+
get(request: NodeRequest & {
|
|
113
|
+
originalUrl?: string;
|
|
114
|
+
}, _response: NodeResponse): Promise<ResponseFile<TFile> | ResponseList<TFile>>;
|
|
115
|
+
/**
|
|
116
|
+
* Returns a list of uploaded files with optional pagination support.
|
|
117
|
+
* @param request Node.js IncomingMessage containing query parameters for pagination.
|
|
118
|
+
* @param _response Node.js ServerResponse (unused).
|
|
119
|
+
* @returns Promise resolving to a paginated or complete list of uploaded files.
|
|
120
|
+
*/
|
|
121
|
+
list(request: NodeRequest, _response: NodeResponse): Promise<ResponseList<TFile>>;
|
|
122
|
+
/**
|
|
123
|
+
* Streams download of a file with resumable support using HTTP range requests.
|
|
124
|
+
* @param request Node.js IncomingMessage with optional originalUrl and range header.
|
|
125
|
+
* @param response Node.js ServerResponse to stream the file to.
|
|
126
|
+
* @throws {HttpError} When file is not found or streaming is not supported.
|
|
127
|
+
*/
|
|
128
|
+
download(request: NodeRequest & {
|
|
129
|
+
originalUrl?: string;
|
|
130
|
+
}, response: NodeResponse): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Check if error is related to undefined ID or path and throw appropriate HTTP error.
|
|
133
|
+
* @param error Error object to check
|
|
134
|
+
*/
|
|
135
|
+
protected checkForUndefinedIdOrPath(error: unknown): void;
|
|
136
|
+
}
|
|
137
|
+
export default BaseHandlerNode;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Multipart } from "../../multipart/multipart-fetch.d.ts";
|
|
2
|
+
export { default as Rest } from "../../rest/rest-fetch.d.ts";
|
|
3
|
+
export { Tus, TUS_RESUMABLE, TUS_VERSION } from "../../tus/tus-fetch.d.ts";
|
|
4
|
+
export type { AsyncHandler, BaseHandler, Handlers, MethodHandler, RequestEvent, UploadErrorEvent, UploadEvent, UploadOptions } from "../../types.d.ts";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Multipart } from '../../../packem_shared/Multipart-CDDlDOs7.js';
|
|
2
|
+
export { default as Rest } from '../../../packem_shared/Rest-D14vM7aJ.js';
|
|
3
|
+
export { Tus } from '../../../packem_shared/Tus-Cjz87bpz.js';
|
|
4
|
+
export { TUS_RESUMABLE, TUS_VERSION } from '../../../packem_shared/TUS_RESUMABLE-Dtfsffnj.js';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import type { UploadFile } from "../../../storage/utils/index.d.ts";
|
|
3
|
+
import type { UploadOptions } from "../../types.d.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Registers upload handler routes on a Hono app instance.
|
|
6
|
+
* Automatically registers all required HTTP methods for the specified handler type.
|
|
7
|
+
* @param app Hono app instance to register routes on
|
|
8
|
+
* @param config Handler configuration including storage, type, and path
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { Hono } from "hono";
|
|
12
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
13
|
+
* import { createHonoHandler } from "@visulima/storage/handler/http/hono";
|
|
14
|
+
*
|
|
15
|
+
* const app = new Hono();
|
|
16
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
17
|
+
*
|
|
18
|
+
* // Multipart handler - automatically registers POST, GET, DELETE, OPTIONS
|
|
19
|
+
* createHonoHandler(app, {
|
|
20
|
+
* path: "/files",
|
|
21
|
+
* storage,
|
|
22
|
+
* type: "multipart"
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { Hono } from "hono";
|
|
28
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
29
|
+
* import { createHonoHandler } from "@visulima/storage/handler/http/hono";
|
|
30
|
+
*
|
|
31
|
+
* const app = new Hono();
|
|
32
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
33
|
+
*
|
|
34
|
+
* // REST handler - automatically registers POST, PUT, PATCH, GET, HEAD, DELETE, OPTIONS
|
|
35
|
+
* createHonoHandler(app, {
|
|
36
|
+
* path: "/files-rest",
|
|
37
|
+
* storage,
|
|
38
|
+
* type: "rest"
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { Hono } from "hono";
|
|
44
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
45
|
+
* import { createHonoHandler } from "@visulima/storage/handler/http/hono";
|
|
46
|
+
*
|
|
47
|
+
* const app = new Hono();
|
|
48
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
49
|
+
*
|
|
50
|
+
* // TUS handler - automatically registers POST, PATCH, HEAD, GET, DELETE, OPTIONS
|
|
51
|
+
* createHonoHandler(app, {
|
|
52
|
+
* path: "/files-tus",
|
|
53
|
+
* storage,
|
|
54
|
+
* type: "tus"
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const createStorageHandler: <TFile extends UploadFile>(app: Hono, config: HonoHandlerConfig<TFile>) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Configuration for Hono handler.
|
|
61
|
+
*/
|
|
62
|
+
export interface HonoHandlerConfig<TFile extends UploadFile> extends UploadOptions<TFile> {
|
|
63
|
+
/** Base path for the routes (e.g., "/files" or "/api/upload") */
|
|
64
|
+
path: string;
|
|
65
|
+
/** Handler type to use */
|
|
66
|
+
type: "multipart" | "rest" | "tus";
|
|
67
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Multipart from '../../../packem_shared/Multipart-CDDlDOs7.js';
|
|
2
|
+
import RestFetch from '../../../packem_shared/Rest-D14vM7aJ.js';
|
|
3
|
+
import { Tus } from '../../../packem_shared/Tus-Cjz87bpz.js';
|
|
4
|
+
|
|
5
|
+
const createHandlerFunction = (handler) => async (c) => {
|
|
6
|
+
try {
|
|
7
|
+
const request = c.req.raw;
|
|
8
|
+
return await handler.fetch(request);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
const errorObject = error;
|
|
11
|
+
const statusCode = errorObject.statusCode || (errorObject.status ? Number.parseInt(errorObject.status, 10) : void 0) || 500;
|
|
12
|
+
return Response.json({ error: errorObject.message || "Request failed" }, { status: statusCode });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const createStorageHandler = (app, config) => {
|
|
16
|
+
const { path, type, ...handlerConfig } = config;
|
|
17
|
+
let handler;
|
|
18
|
+
switch (type) {
|
|
19
|
+
case "multipart": {
|
|
20
|
+
handler = new Multipart(handlerConfig);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case "rest": {
|
|
24
|
+
handler = new RestFetch(handlerConfig);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case "tus": {
|
|
28
|
+
handler = new Tus(handlerConfig);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
default: {
|
|
32
|
+
throw new Error(`Unknown handler type: ${String(type ?? "unknown")}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const handlerFunction = createHandlerFunction(handler);
|
|
36
|
+
switch (type) {
|
|
37
|
+
case "multipart": {
|
|
38
|
+
app.post(path, handlerFunction);
|
|
39
|
+
app.get(`${path}/:id?/:metadata?`, handlerFunction);
|
|
40
|
+
app.delete(`${path}/:id`, handlerFunction);
|
|
41
|
+
app.on("OPTIONS", path, handlerFunction);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "rest": {
|
|
45
|
+
app.post(path, handlerFunction);
|
|
46
|
+
app.put(`${path}/:id`, handlerFunction);
|
|
47
|
+
app.patch(`${path}/:id`, handlerFunction);
|
|
48
|
+
app.get(`${path}/:id?`, handlerFunction);
|
|
49
|
+
app.on("HEAD", `${path}/:id`, handlerFunction);
|
|
50
|
+
app.delete(`${path}/:id?`, handlerFunction);
|
|
51
|
+
app.on("OPTIONS", path, handlerFunction);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "tus": {
|
|
55
|
+
app.all(path, handlerFunction);
|
|
56
|
+
app.all(`${path}/:id`, handlerFunction);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
throw new Error(`Unknown handler type: ${String(type)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { createStorageHandler };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server.d.ts";
|
|
2
|
+
import { NextResponse } from "next/server.d.ts";
|
|
3
|
+
import type { UploadFile } from "../../../storage/utils/index.d.ts";
|
|
4
|
+
import type { UploadOptions } from "../../types.d.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for Next.js handler.
|
|
7
|
+
*/
|
|
8
|
+
export interface NextjsHandlerConfig<TFile extends UploadFile> extends UploadOptions<TFile> {
|
|
9
|
+
/** Handler type to use */
|
|
10
|
+
type: "multipart" | "rest" | "tus";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Next.js route handler that automatically exports the correct HTTP methods for each handler type.
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // app/api/upload/multipart/route.ts
|
|
17
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
18
|
+
* import { createHandler } from "@visulima/storage/handler/http/nextjs";
|
|
19
|
+
*
|
|
20
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
21
|
+
* const handler = createHandler({ storage, type: "multipart" });
|
|
22
|
+
*
|
|
23
|
+
* export const POST = handler;
|
|
24
|
+
* export const DELETE = handler;
|
|
25
|
+
* export const GET = handler;
|
|
26
|
+
* export const OPTIONS = handler;
|
|
27
|
+
* ```
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // app/api/upload/rest/route.ts
|
|
31
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
32
|
+
* import { createHandler } from "@visulima/storage/handler/http/nextjs";
|
|
33
|
+
*
|
|
34
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
35
|
+
* const handler = createHandler({ storage, type: "rest" });
|
|
36
|
+
*
|
|
37
|
+
* export const POST = handler;
|
|
38
|
+
* export const PUT = handler;
|
|
39
|
+
* export const PATCH = handler;
|
|
40
|
+
* export const GET = handler;
|
|
41
|
+
* export const HEAD = handler;
|
|
42
|
+
* export const DELETE = handler;
|
|
43
|
+
* export const OPTIONS = handler;
|
|
44
|
+
* ```
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // app/api/upload/tus/route.ts
|
|
48
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
49
|
+
* import { createHandler } from "@visulima/storage/handler/http/nextjs";
|
|
50
|
+
*
|
|
51
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
52
|
+
* const handler = createHandler({ storage, type: "tus" });
|
|
53
|
+
*
|
|
54
|
+
* export const POST = handler;
|
|
55
|
+
* export const PATCH = handler;
|
|
56
|
+
* export const HEAD = handler;
|
|
57
|
+
* export const DELETE = handler;
|
|
58
|
+
* export const OPTIONS = handler;
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const createHandler: <TFile extends UploadFile>(config: NextjsHandlerConfig<TFile>) => ((request: NextRequest) => Promise<NextResponse>);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server.js';
|
|
2
|
+
import Multipart from '../../../packem_shared/Multipart-CDDlDOs7.js';
|
|
3
|
+
import RestFetch from '../../../packem_shared/Rest-D14vM7aJ.js';
|
|
4
|
+
import { Tus } from '../../../packem_shared/Tus-Cjz87bpz.js';
|
|
5
|
+
|
|
6
|
+
const createHandler = (config) => {
|
|
7
|
+
let handler;
|
|
8
|
+
switch (config.type) {
|
|
9
|
+
case "multipart": {
|
|
10
|
+
handler = new Multipart(config);
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case "rest": {
|
|
14
|
+
handler = new RestFetch(config);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case "tus": {
|
|
18
|
+
handler = new Tus(config);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
default: {
|
|
22
|
+
throw new Error(`Unknown handler type: ${String(config.type ?? "unknown")}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const nextjsHandler = async (request) => {
|
|
26
|
+
try {
|
|
27
|
+
return await handler.fetch(request);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
const errorObject = error;
|
|
30
|
+
const statusCode = errorObject.statusCode || (errorObject.status ? Number.parseInt(errorObject.status, 10) : void 0) || 500;
|
|
31
|
+
return NextResponse.json({ error: errorObject.message || "Request failed" }, { status: statusCode });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return nextjsHandler;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { createHandler };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Multipart } from "../../multipart/multipart.d.ts";
|
|
2
|
+
export { default as Rest } from "../../rest/rest.d.ts";
|
|
3
|
+
export { Tus, TUS_RESUMABLE, TUS_VERSION } from "../../tus/tus.d.ts";
|
|
4
|
+
export type { AsyncHandler, BaseHandler, Handlers, MethodHandler, RequestEvent, UploadErrorEvent, UploadEvent, UploadOptions } from "../../types.d.ts";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Multipart from '../../../packem_shared/Multipart-vxBL2VXm.js';
|
|
2
|
+
import Rest from '../../../packem_shared/Rest-CEj3EhMj.js';
|
|
3
|
+
import { Tus } from '../../../packem_shared/Tus-WOVg-YnB.js';
|
|
4
|
+
export { TUS_RESUMABLE, TUS_VERSION } from '../../../packem_shared/TUS_RESUMABLE-Dtfsffnj.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export { Multipart, Rest, Tus };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { APIEvent } from "@solidjs/start/server";
|
|
2
|
+
import type { UploadFile } from "../../../storage/utils/index.d.ts";
|
|
3
|
+
import type { UploadOptions } from "../../types.d.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for SolidStart handler.
|
|
6
|
+
*/
|
|
7
|
+
export interface SolidStartHandlerConfig<TFile extends UploadFile> extends UploadOptions<TFile> {
|
|
8
|
+
/** Handler type to use */
|
|
9
|
+
type: "multipart" | "rest" | "tus";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SolidStart API route handler that automatically handles the correct HTTP methods for each handler type.
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // app/routes/api/upload/multipart.ts
|
|
16
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
17
|
+
* import { createSolidStartHandler } from "@visulima/storage/handler/http/solid-start";
|
|
18
|
+
*
|
|
19
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
20
|
+
* const handler = createSolidStartHandler({ storage, type: "multipart" });
|
|
21
|
+
*
|
|
22
|
+
* export const POST = handler;
|
|
23
|
+
* export const DELETE = handler;
|
|
24
|
+
* export const GET = handler;
|
|
25
|
+
* export const OPTIONS = handler;
|
|
26
|
+
* ```
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // app/routes/api/upload/rest.ts
|
|
30
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
31
|
+
* import { createSolidStartHandler } from "@visulima/storage/handler/http/solid-start";
|
|
32
|
+
*
|
|
33
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
34
|
+
* const handler = createSolidStartHandler({ storage, type: "rest" });
|
|
35
|
+
*
|
|
36
|
+
* export const POST = handler;
|
|
37
|
+
* export const PUT = handler;
|
|
38
|
+
* export const PATCH = handler;
|
|
39
|
+
* export const GET = handler;
|
|
40
|
+
* export const HEAD = handler;
|
|
41
|
+
* export const DELETE = handler;
|
|
42
|
+
* export const OPTIONS = handler;
|
|
43
|
+
* ```
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // app/routes/api/upload/tus.ts
|
|
47
|
+
* import { DiskStorage } from "@visulima/storage";
|
|
48
|
+
* import { createSolidStartHandler } from "@visulima/storage/handler/http/solid-start";
|
|
49
|
+
*
|
|
50
|
+
* const storage = new DiskStorage({ directory: "./uploads" });
|
|
51
|
+
* const handler = createSolidStartHandler({ storage, type: "tus" });
|
|
52
|
+
*
|
|
53
|
+
* export const POST = handler;
|
|
54
|
+
* export const PATCH = handler;
|
|
55
|
+
* export const HEAD = handler;
|
|
56
|
+
* export const DELETE = handler;
|
|
57
|
+
* export const OPTIONS = handler;
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const createSolidStartHandler: <TFile extends UploadFile>(config: SolidStartHandlerConfig<TFile>) => ((event: APIEvent) => Promise<Response>);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Multipart from '../../../packem_shared/Multipart-CDDlDOs7.js';
|
|
2
|
+
import RestFetch from '../../../packem_shared/Rest-D14vM7aJ.js';
|
|
3
|
+
import { Tus } from '../../../packem_shared/Tus-Cjz87bpz.js';
|
|
4
|
+
|
|
5
|
+
const createSolidStartHandler = (config) => {
|
|
6
|
+
let handler;
|
|
7
|
+
switch (config.type) {
|
|
8
|
+
case "multipart": {
|
|
9
|
+
handler = new Multipart(config);
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
case "rest": {
|
|
13
|
+
handler = new RestFetch(config);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
case "tus": {
|
|
17
|
+
handler = new Tus(config);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
default: {
|
|
21
|
+
throw new Error(`Unknown handler type: ${String(config.type ?? "unknown")}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const solidStartHandler = async (event) => {
|
|
25
|
+
try {
|
|
26
|
+
return await handler.fetch(event.request);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const errorObject = error;
|
|
29
|
+
const statusCode = errorObject.statusCode || (errorObject.status ? Number.parseInt(errorObject.status, 10) : void 0) || 500;
|
|
30
|
+
return Response.json(
|
|
31
|
+
{ error: errorObject.message || "Request failed" },
|
|
32
|
+
{
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
},
|
|
36
|
+
status: statusCode
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return solidStartHandler;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { createSolidStartHandler };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { FileInit, UploadFile } from "../../storage/utils/index.d.ts";
|
|
2
|
+
import type { ResponseFile } from "../types.d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Base class containing shared Multipart business logic.
|
|
5
|
+
* Platform-agnostic - contains no Node.js or Web API specific code.
|
|
6
|
+
* @template TFile The file type used by this handler.
|
|
7
|
+
*/
|
|
8
|
+
declare abstract class MultipartBase<TFile extends UploadFile> {
|
|
9
|
+
/**
|
|
10
|
+
* Handle multipart POST (upload file).
|
|
11
|
+
* @param filePart File part from multipart parser
|
|
12
|
+
* @param filePart.bytes File bytes data
|
|
13
|
+
* @param filePart.filename Original filename
|
|
14
|
+
* @param filePart.mediaType Content type
|
|
15
|
+
* @param filePart.size File size in bytes
|
|
16
|
+
* @param metadataParts All parts from multipart parser (for extracting metadata)
|
|
17
|
+
* @param requestUrl Request URL for Location header
|
|
18
|
+
* @returns Promise resolving to ResponseFile with upload result
|
|
19
|
+
*/
|
|
20
|
+
handlePost(filePart: {
|
|
21
|
+
bytes: unknown;
|
|
22
|
+
filename?: string;
|
|
23
|
+
mediaType?: string;
|
|
24
|
+
size: number;
|
|
25
|
+
}, metadataParts: {
|
|
26
|
+
isFile: boolean;
|
|
27
|
+
name?: string;
|
|
28
|
+
text?: string;
|
|
29
|
+
}[], requestUrl: string): Promise<ResponseFile<TFile>>;
|
|
30
|
+
/**
|
|
31
|
+
* Handle DELETE (delete file).
|
|
32
|
+
* @param id File ID from URL
|
|
33
|
+
* @returns Promise resolving to ResponseFile with deletion result
|
|
34
|
+
*/
|
|
35
|
+
handleDelete(id: string): Promise<ResponseFile<TFile>>;
|
|
36
|
+
/**
|
|
37
|
+
* Storage instance for file operations.
|
|
38
|
+
*/
|
|
39
|
+
protected get storage(): {
|
|
40
|
+
create: (config: FileInit) => Promise<TFile>;
|
|
41
|
+
delete: (options: {
|
|
42
|
+
id: string;
|
|
43
|
+
}) => Promise<TFile>;
|
|
44
|
+
maxUploadSize: number;
|
|
45
|
+
update: (options: {
|
|
46
|
+
id: string;
|
|
47
|
+
}, updates: {
|
|
48
|
+
metadata?: Record<string, unknown>;
|
|
49
|
+
}) => Promise<TFile>;
|
|
50
|
+
write: (options: {
|
|
51
|
+
body: unknown;
|
|
52
|
+
contentLength: number;
|
|
53
|
+
id: string;
|
|
54
|
+
start: number;
|
|
55
|
+
}) => Promise<TFile>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Maximum file size allowed for multipart uploads
|
|
59
|
+
*/
|
|
60
|
+
protected abstract get maxFileSize(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Maximum header size allowed for multipart parser
|
|
63
|
+
*/
|
|
64
|
+
protected abstract get maxHeaderSize(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Build file URL from request URL and file data.
|
|
67
|
+
* @param _requestUrl Request URL string
|
|
68
|
+
* @param _file File object containing ID and content type
|
|
69
|
+
* @returns Constructed file URL with extension based on content type
|
|
70
|
+
*/
|
|
71
|
+
protected buildFileUrl(_requestUrl: string, _file: TFile): string;
|
|
72
|
+
/**
|
|
73
|
+
* Create a stream from bytes data.
|
|
74
|
+
* @param bytes Bytes data (Uint8Array, Buffer, or other)
|
|
75
|
+
* @returns Stream object
|
|
76
|
+
*/
|
|
77
|
+
protected abstract createStreamFromBytes(bytes: unknown): unknown;
|
|
78
|
+
/**
|
|
79
|
+
* Create an empty stream for signaling completion.
|
|
80
|
+
* @returns Empty stream object
|
|
81
|
+
*/
|
|
82
|
+
protected abstract createEmptyStream(): unknown;
|
|
83
|
+
}
|
|
84
|
+
export default MultipartBase;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { UploadFile } from "../../storage/utils/index.d.ts";
|
|
2
|
+
import BaseHandlerFetch from "../base/base-handler-fetch.d.ts";
|
|
3
|
+
import type { Handlers, ResponseFile, UploadOptions } from "../types.d.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Multipart/form-data upload handler (Web API Fetch version).
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const multipart = new MultipartFetch({
|
|
9
|
+
* storage,
|
|
10
|
+
* maxFileSize: 100 * 1024 * 1024, // 100MB
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* // Use with Hono, Cloudflare Workers, etc.
|
|
14
|
+
* app.all('/files/*', async (c) => {
|
|
15
|
+
* return multipart.fetch(c.req.raw);
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare class Multipart<TFile extends UploadFile> extends BaseHandlerFetch<TFile> {
|
|
20
|
+
/**
|
|
21
|
+
* Limiting enabled http method handler
|
|
22
|
+
*/
|
|
23
|
+
static readonly methods: Handlers[];
|
|
24
|
+
private readonly multipartBase;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum file size allowed for multipart uploads
|
|
27
|
+
*/
|
|
28
|
+
private maxFileSize;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum header size allowed for multipart parser
|
|
31
|
+
*/
|
|
32
|
+
private maxHeaderSize;
|
|
33
|
+
constructor(options: UploadOptions<TFile>);
|
|
34
|
+
/**
|
|
35
|
+
* Handles multipart/form-data POST requests for file uploads.
|
|
36
|
+
* @param request Web API Request containing multipart data.
|
|
37
|
+
* @returns Promise resolving to ResponseFile with upload result.
|
|
38
|
+
*/
|
|
39
|
+
post(request: Request): Promise<ResponseFile<TFile>>;
|
|
40
|
+
/**
|
|
41
|
+
* Delete an uploaded file.
|
|
42
|
+
* @param request Web API Request with file ID
|
|
43
|
+
* @returns Promise resolving to ResponseFile with deletion result
|
|
44
|
+
*/
|
|
45
|
+
delete(request: Request): Promise<ResponseFile<TFile>>;
|
|
46
|
+
/**
|
|
47
|
+
* Handle OPTIONS requests with CORS headers.
|
|
48
|
+
* @param _request Web API Request (unused)
|
|
49
|
+
* @returns Promise resolving to ResponseFile with CORS headers
|
|
50
|
+
*/
|
|
51
|
+
options(_request: Request): Promise<ResponseFile<TFile>>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves a file or list of files based on the request path.
|
|
54
|
+
* Delegates to BaseHandlerFetch.fetch() method.
|
|
55
|
+
* @param _request Web API Request
|
|
56
|
+
* @returns Promise resolving to Web API Response
|
|
57
|
+
*/
|
|
58
|
+
get(_request: Request): Promise<ResponseFile<TFile>>;
|
|
59
|
+
/**
|
|
60
|
+
* Compose and register HTTP method handlers.
|
|
61
|
+
*/
|
|
62
|
+
protected compose(): void;
|
|
63
|
+
}
|
|
64
|
+
export default Multipart;
|