@kiyasov/platform-hono 1.1.5 → 1.1.7
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/cjs/src/adapters/hono-adapter.d.ts +11 -11
- package/dist/cjs/src/adapters/hono-adapter.js +24 -24
- package/dist/cjs/src/multer/interceptors/any-files-interceptor.d.ts +2 -2
- package/dist/cjs/src/multer/interceptors/any-files-interceptor.js +3 -0
- package/dist/cjs/src/multer/interceptors/any-files-interceptor.js.map +1 -1
- package/dist/cjs/src/multer/interceptors/file-fields-interceptor.d.ts +3 -3
- package/dist/cjs/src/multer/interceptors/file-fields-interceptor.js +3 -0
- package/dist/cjs/src/multer/interceptors/file-fields-interceptor.js.map +1 -1
- package/dist/cjs/src/multer/interceptors/file-interceptor.d.ts +2 -2
- package/dist/cjs/src/multer/interceptors/file-interceptor.js +3 -0
- package/dist/cjs/src/multer/interceptors/file-interceptor.js.map +1 -1
- package/dist/cjs/src/multer/interceptors/files-interceptor.d.ts +2 -2
- package/dist/cjs/src/multer/interceptors/files-interceptor.js +3 -0
- package/dist/cjs/src/multer/interceptors/files-interceptor.js.map +1 -1
- package/dist/cjs/src/multer/multipart/request.js +0 -3
- package/dist/cjs/src/multer/multipart/request.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.d.ts +11 -11
- package/dist/esm/src/adapters/hono-adapter.js +35 -35
- package/dist/esm/src/multer/interceptors/any-files-interceptor.d.ts +2 -2
- package/dist/esm/src/multer/interceptors/any-files-interceptor.js +8 -5
- package/dist/esm/src/multer/interceptors/any-files-interceptor.js.map +1 -1
- package/dist/esm/src/multer/interceptors/file-fields-interceptor.d.ts +3 -3
- package/dist/esm/src/multer/interceptors/file-fields-interceptor.js +8 -5
- package/dist/esm/src/multer/interceptors/file-fields-interceptor.js.map +1 -1
- package/dist/esm/src/multer/interceptors/file-interceptor.d.ts +2 -2
- package/dist/esm/src/multer/interceptors/file-interceptor.js +8 -5
- package/dist/esm/src/multer/interceptors/file-interceptor.js.map +1 -1
- package/dist/esm/src/multer/interceptors/files-interceptor.d.ts +2 -2
- package/dist/esm/src/multer/interceptors/files-interceptor.js +8 -5
- package/dist/esm/src/multer/interceptors/files-interceptor.js.map +1 -1
- package/dist/esm/src/multer/multipart/request.js +0 -3
- package/dist/esm/src/multer/multipart/request.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/multer/interceptors/any-files-interceptor.ts +12 -8
- package/src/multer/interceptors/file-fields-interceptor.ts +12 -8
- package/src/multer/interceptors/file-interceptor.ts +12 -8
- package/src/multer/interceptors/files-interceptor.ts +12 -8
- package/src/multer/multipart/request.ts +0 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Server } from
|
|
4
|
-
import { HttpBindings } from
|
|
5
|
-
import { RequestMethod } from
|
|
6
|
-
import { ErrorHandler, NestApplicationOptions, RequestHandler } from
|
|
7
|
-
import { ServeStaticOptions } from
|
|
8
|
-
import { AbstractHttpAdapter } from
|
|
9
|
-
import { Context, HonoRequest } from
|
|
10
|
-
import { Hono } from
|
|
11
|
-
import { RedirectStatusCode, StatusCode } from
|
|
12
|
-
import { Http2SecureServer, Http2Server } from
|
|
13
|
-
import { TypeBodyParser } from
|
|
3
|
+
import { Server } from "node:net";
|
|
4
|
+
import { HttpBindings } from "@hono/node-server";
|
|
5
|
+
import { RequestMethod } from "@nestjs/common";
|
|
6
|
+
import { ErrorHandler, NestApplicationOptions, RequestHandler } from "@nestjs/common/interfaces";
|
|
7
|
+
import { ServeStaticOptions } from "@hono/node-server/serve-static";
|
|
8
|
+
import { AbstractHttpAdapter } from "@nestjs/core/adapters/http-adapter";
|
|
9
|
+
import { Context, HonoRequest } from "hono";
|
|
10
|
+
import { Hono } from "hono";
|
|
11
|
+
import { RedirectStatusCode, StatusCode } from "hono/utils/http-status";
|
|
12
|
+
import { Http2SecureServer, Http2Server } from "http2";
|
|
13
|
+
import { TypeBodyParser } from "../interfaces";
|
|
14
14
|
type HonoHandler = RequestHandler<HonoRequest, Context>;
|
|
15
15
|
type ServerType = Server | Http2Server | Http2SecureServer;
|
|
16
16
|
export declare class HonoAdapter extends AbstractHttpAdapter<ServerType, HonoRequest, Context> {
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { createAdaptorServer } from
|
|
2
|
-
import { RESPONSE_ALREADY_SENT } from
|
|
3
|
-
import { RequestMethod } from
|
|
4
|
-
import { HttpStatus, Logger } from
|
|
5
|
-
import { bodyLimit } from
|
|
6
|
-
import { serveStatic, } from
|
|
7
|
-
import { AbstractHttpAdapter } from
|
|
8
|
-
import { Hono } from
|
|
9
|
-
import { cors } from
|
|
10
|
-
import * as http from
|
|
11
|
-
import * as https from
|
|
1
|
+
import { createAdaptorServer } from "@hono/node-server";
|
|
2
|
+
import { RESPONSE_ALREADY_SENT } from "@hono/node-server/utils/response";
|
|
3
|
+
import { RequestMethod } from "@nestjs/common";
|
|
4
|
+
import { HttpStatus, Logger } from "@nestjs/common";
|
|
5
|
+
import { bodyLimit } from "hono/body-limit";
|
|
6
|
+
import { serveStatic, } from "@hono/node-server/serve-static";
|
|
7
|
+
import { AbstractHttpAdapter } from "@nestjs/core/adapters/http-adapter";
|
|
8
|
+
import { Hono } from "hono";
|
|
9
|
+
import { cors } from "hono/cors";
|
|
10
|
+
import * as http from "http";
|
|
11
|
+
import * as https from "https";
|
|
12
12
|
export class HonoAdapter extends AbstractHttpAdapter {
|
|
13
13
|
constructor() {
|
|
14
14
|
super(new Hono());
|
|
15
15
|
}
|
|
16
16
|
getRouteAndHandler(pathOrHandler, handler) {
|
|
17
|
-
let path = typeof pathOrHandler ===
|
|
18
|
-
handler = typeof pathOrHandler ===
|
|
17
|
+
let path = typeof pathOrHandler === "function" ? "" : pathOrHandler;
|
|
18
|
+
handler = typeof pathOrHandler === "function" ? pathOrHandler : handler;
|
|
19
19
|
return [path, handler];
|
|
20
20
|
}
|
|
21
21
|
createRouteHandler(routeHandler) {
|
|
@@ -25,8 +25,8 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
send(ctx) {
|
|
28
|
-
const body = ctx.get(
|
|
29
|
-
return typeof body ===
|
|
28
|
+
const body = ctx.get("body");
|
|
29
|
+
return typeof body === "string" ? ctx.text(body) : ctx.json(body);
|
|
30
30
|
}
|
|
31
31
|
get(pathOrHandler, handler) {
|
|
32
32
|
const [routePath, routeHandler] = this.getRouteAndHandler(pathOrHandler, handler);
|
|
@@ -59,13 +59,13 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
59
59
|
async reply(ctx, body, statusCode) {
|
|
60
60
|
if (statusCode)
|
|
61
61
|
ctx.status(statusCode);
|
|
62
|
-
const responseContentType = this.getHeader(ctx,
|
|
63
|
-
if (!responseContentType?.startsWith(
|
|
62
|
+
const responseContentType = this.getHeader(ctx, "Content-Type");
|
|
63
|
+
if (!responseContentType?.startsWith("application/json") &&
|
|
64
64
|
body?.statusCode >= HttpStatus.BAD_REQUEST) {
|
|
65
65
|
Logger.warn("Content-Type doesn't match Reply body, you might need a custom ExceptionFilter for non-JSON responses");
|
|
66
|
-
this.setHeader(ctx,
|
|
66
|
+
this.setHeader(ctx, "Content-Type", "application/json");
|
|
67
67
|
}
|
|
68
|
-
ctx.set(
|
|
68
|
+
ctx.set("body", body);
|
|
69
69
|
}
|
|
70
70
|
status(ctx, statusCode) {
|
|
71
71
|
ctx.status(statusCode);
|
|
@@ -74,7 +74,7 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
74
74
|
return RESPONSE_ALREADY_SENT;
|
|
75
75
|
}
|
|
76
76
|
render(response, view, options) {
|
|
77
|
-
throw new Error(
|
|
77
|
+
throw new Error("Method not implemented.");
|
|
78
78
|
}
|
|
79
79
|
redirect(ctx, statusCode, url) {
|
|
80
80
|
ctx.redirect(url, statusCode);
|
|
@@ -92,11 +92,11 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
useStaticAssets(path, options) {
|
|
95
|
-
Logger.log(
|
|
95
|
+
Logger.log("Registering static assets middleware");
|
|
96
96
|
this.instance.use(path, serveStatic(options));
|
|
97
97
|
}
|
|
98
98
|
setViewEngine(options) {
|
|
99
|
-
throw new Error(
|
|
99
|
+
throw new Error("Method not implemented.");
|
|
100
100
|
}
|
|
101
101
|
isHeadersSent(ctx) {
|
|
102
102
|
return true;
|
|
@@ -123,16 +123,16 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
123
123
|
this.instance.use(cors(options));
|
|
124
124
|
}
|
|
125
125
|
useBodyParser(type, bodyLimit = 1e6) {
|
|
126
|
-
Logger.log(
|
|
126
|
+
Logger.log("Registering body parser middleware");
|
|
127
127
|
this.instance.use(this.bodyLimit(bodyLimit), async (ctx, next) => {
|
|
128
|
-
const contentType = ctx.req.header(
|
|
128
|
+
const contentType = ctx.req.header("content-type");
|
|
129
129
|
switch (type) {
|
|
130
|
-
case
|
|
131
|
-
if (contentType ===
|
|
130
|
+
case "application/json":
|
|
131
|
+
if (contentType === "application/json")
|
|
132
132
|
ctx.req.body = await ctx.req.json();
|
|
133
133
|
break;
|
|
134
|
-
case
|
|
135
|
-
if (contentType ===
|
|
134
|
+
case "text/plain":
|
|
135
|
+
if (contentType === "text/plain") {
|
|
136
136
|
ctx.req.rawBody = Buffer.from(await ctx.req.text());
|
|
137
137
|
ctx.req.body = await ctx.req.json();
|
|
138
138
|
}
|
|
@@ -159,13 +159,13 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
getType() {
|
|
162
|
-
return
|
|
162
|
+
return "hono";
|
|
163
163
|
}
|
|
164
164
|
registerParserMiddleware(prefix, rawBody) {
|
|
165
|
-
Logger.log(
|
|
166
|
-
this.useBodyParser(
|
|
167
|
-
this.useBodyParser(
|
|
168
|
-
this.useBodyParser(
|
|
165
|
+
Logger.log("Registering parser middleware");
|
|
166
|
+
this.useBodyParser("application/x-www-form-urlencoded");
|
|
167
|
+
this.useBodyParser("application/json");
|
|
168
|
+
this.useBodyParser("text/plain");
|
|
169
169
|
}
|
|
170
170
|
async createMiddlewareFactory(requestMethod) {
|
|
171
171
|
return (path, callback) => {
|
|
@@ -185,7 +185,7 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
applyVersionFilter() {
|
|
188
|
-
throw new Error(
|
|
188
|
+
throw new Error("Versioning not yet supported in Hono");
|
|
189
189
|
}
|
|
190
190
|
listen(port, ...args) {
|
|
191
191
|
return this.httpServer.listen(port, ...args);
|
|
@@ -194,7 +194,7 @@ export class HonoAdapter extends AbstractHttpAdapter {
|
|
|
194
194
|
return bodyLimit({
|
|
195
195
|
maxSize,
|
|
196
196
|
onError: () => {
|
|
197
|
-
throw new Error(
|
|
197
|
+
throw new Error("Body too large");
|
|
198
198
|
},
|
|
199
199
|
});
|
|
200
200
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NestInterceptor, Type } from
|
|
2
|
-
import { UploadOptions } from
|
|
1
|
+
import { NestInterceptor, Type } from "@nestjs/common";
|
|
2
|
+
import { UploadOptions } from "../multipart/options";
|
|
3
3
|
export declare function AnyFilesInterceptor(options?: UploadOptions): Type<NestInterceptor>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { tap } from
|
|
2
|
-
import { mixin, } from
|
|
3
|
-
import { getMultipartRequest } from
|
|
4
|
-
import { transformUploadOptions } from
|
|
5
|
-
import { handleMultipartAnyFiles } from
|
|
1
|
+
import { tap } from "rxjs";
|
|
2
|
+
import { mixin, } from "@nestjs/common";
|
|
3
|
+
import { getMultipartRequest } from "../multipart/request";
|
|
4
|
+
import { transformUploadOptions } from "../multipart/options";
|
|
5
|
+
import { handleMultipartAnyFiles } from "../multipart/handlers/any-files";
|
|
6
6
|
export function AnyFilesInterceptor(options) {
|
|
7
7
|
class MixinInterceptor {
|
|
8
8
|
constructor() {
|
|
@@ -11,6 +11,9 @@ export function AnyFilesInterceptor(options) {
|
|
|
11
11
|
async intercept(context, next) {
|
|
12
12
|
const ctx = context.switchToHttp();
|
|
13
13
|
const req = getMultipartRequest(ctx);
|
|
14
|
+
if (!req.header("content-type")?.startsWith("multipart/form-data")) {
|
|
15
|
+
return next.handle();
|
|
16
|
+
}
|
|
14
17
|
const { body, files, remove } = await handleMultipartAnyFiles(req, this.options);
|
|
15
18
|
req.body = body;
|
|
16
19
|
req.storageFiles = files;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"any-files-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/any-files-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,MAAM,UAAU,mBAAmB,CACjC,OAAuB;IAEvB,MAAM,gBAAgB;QAGpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,uBAAuB,CAC3D,GAAG,EACH,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC;YAEzB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
1
|
+
{"version":3,"file":"any-files-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/any-files-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,MAAM,UAAU,mBAAmB,CACjC,OAAuB;IAEvB,MAAM,gBAAgB;QAGpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,CAAC;YAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,uBAAuB,CAC3D,GAAG,EACH,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC;YAEzB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NestInterceptor, Type } from
|
|
2
|
-
import { UploadOptions } from
|
|
3
|
-
import { UploadField } from
|
|
1
|
+
import { NestInterceptor, Type } from "@nestjs/common";
|
|
2
|
+
import { UploadOptions } from "../multipart/options";
|
|
3
|
+
import { UploadField } from "../multipart/handlers/file-fields";
|
|
4
4
|
export declare function FileFieldsInterceptor(uploadFields: UploadField[], options?: UploadOptions): Type<NestInterceptor>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { tap } from
|
|
2
|
-
import { mixin, } from
|
|
3
|
-
import { getMultipartRequest } from
|
|
4
|
-
import { transformUploadOptions } from
|
|
5
|
-
import { handleMultipartFileFields, uploadFieldsToMap, } from
|
|
1
|
+
import { tap } from "rxjs";
|
|
2
|
+
import { mixin, } from "@nestjs/common";
|
|
3
|
+
import { getMultipartRequest } from "../multipart/request";
|
|
4
|
+
import { transformUploadOptions } from "../multipart/options";
|
|
5
|
+
import { handleMultipartFileFields, uploadFieldsToMap, } from "../multipart/handlers/file-fields";
|
|
6
6
|
export function FileFieldsInterceptor(uploadFields, options) {
|
|
7
7
|
class MixinInterceptor {
|
|
8
8
|
constructor() {
|
|
@@ -12,6 +12,9 @@ export function FileFieldsInterceptor(uploadFields, options) {
|
|
|
12
12
|
async intercept(context, next) {
|
|
13
13
|
const ctx = context.switchToHttp();
|
|
14
14
|
const req = getMultipartRequest(ctx);
|
|
15
|
+
if (!req.header("content-type")?.startsWith("multipart/form-data")) {
|
|
16
|
+
return next.handle();
|
|
17
|
+
}
|
|
15
18
|
const { body, files, remove } = await handleMultipartFileFields(req, this.fieldsMap, this.options);
|
|
16
19
|
req.body = body;
|
|
17
20
|
req.storageFiles = files;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-fields-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/file-fields-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,yBAAyB,EAGzB,iBAAiB,GAClB,MAAM,mCAAmC,CAAC;AAE3C,MAAM,UAAU,qBAAqB,CACnC,YAA2B,EAC3B,OAAuB;IAEvB,MAAM,gBAAgB;QAKpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;YAC/C,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;QACnD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,yBAAyB,CAC7D,GAAG,EACH,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC;YAEzB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
1
|
+
{"version":3,"file":"file-fields-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/file-fields-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,yBAAyB,EAGzB,iBAAiB,GAClB,MAAM,mCAAmC,CAAC;AAE3C,MAAM,UAAU,qBAAqB,CACnC,YAA2B,EAC3B,OAAuB;IAEvB,MAAM,gBAAgB;QAKpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;YAC/C,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;QACnD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,CAAC;YAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,yBAAyB,CAC7D,GAAG,EACH,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC;YAEzB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NestInterceptor, Type } from
|
|
2
|
-
import { UploadOptions } from
|
|
1
|
+
import { NestInterceptor, Type } from "@nestjs/common";
|
|
2
|
+
import { UploadOptions } from "../multipart/options";
|
|
3
3
|
export declare function FileInterceptor(fieldname: string, options?: UploadOptions): Type<NestInterceptor>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { tap } from
|
|
2
|
-
import { mixin, } from
|
|
3
|
-
import { getMultipartRequest } from
|
|
4
|
-
import { transformUploadOptions } from
|
|
5
|
-
import { handleMultipartSingleFile } from
|
|
1
|
+
import { tap } from "rxjs";
|
|
2
|
+
import { mixin, } from "@nestjs/common";
|
|
3
|
+
import { getMultipartRequest } from "../multipart/request";
|
|
4
|
+
import { transformUploadOptions } from "../multipart/options";
|
|
5
|
+
import { handleMultipartSingleFile } from "../multipart/handlers/single-file";
|
|
6
6
|
export function FileInterceptor(fieldname, options) {
|
|
7
7
|
class MixinInterceptor {
|
|
8
8
|
constructor() {
|
|
@@ -11,6 +11,9 @@ export function FileInterceptor(fieldname, options) {
|
|
|
11
11
|
async intercept(context, next) {
|
|
12
12
|
const ctx = context.switchToHttp();
|
|
13
13
|
const req = getMultipartRequest(ctx);
|
|
14
|
+
if (!req.header("content-type")?.startsWith("multipart/form-data")) {
|
|
15
|
+
return next.handle();
|
|
16
|
+
}
|
|
14
17
|
const { file, body, remove } = await handleMultipartSingleFile(req, fieldname, this.options);
|
|
15
18
|
req.body = body;
|
|
16
19
|
req.storageFile = file;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/file-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,MAAM,UAAU,eAAe,CAC7B,SAAiB,EACjB,OAAuB;IAEvB,MAAM,gBAAgB;QAGpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,yBAAyB,CAC5D,GAAG,EACH,SAAS,EACT,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;YAEvB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
1
|
+
{"version":3,"file":"file-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/file-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,MAAM,UAAU,eAAe,CAC7B,SAAiB,EACjB,OAAuB;IAEvB,MAAM,gBAAgB;QAGpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,CAAC;YAED,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,yBAAyB,CAC5D,GAAG,EACH,SAAS,EACT,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;YAEvB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NestInterceptor, Type } from
|
|
2
|
-
import { UploadOptions } from
|
|
1
|
+
import { NestInterceptor, Type } from "@nestjs/common";
|
|
2
|
+
import { UploadOptions } from "../multipart/options";
|
|
3
3
|
export declare function FilesInterceptor(fieldname: string, maxCount?: number, options?: UploadOptions): Type<NestInterceptor>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { tap } from
|
|
2
|
-
import { mixin, } from
|
|
3
|
-
import { getMultipartRequest } from
|
|
4
|
-
import { transformUploadOptions } from
|
|
5
|
-
import { handleMultipartMultipleFiles } from
|
|
1
|
+
import { tap } from "rxjs";
|
|
2
|
+
import { mixin, } from "@nestjs/common";
|
|
3
|
+
import { getMultipartRequest } from "../multipart/request";
|
|
4
|
+
import { transformUploadOptions } from "../multipart/options";
|
|
5
|
+
import { handleMultipartMultipleFiles } from "../multipart/handlers/multiple-files";
|
|
6
6
|
export function FilesInterceptor(fieldname, maxCount = 1, options) {
|
|
7
7
|
class MixinInterceptor {
|
|
8
8
|
constructor() {
|
|
@@ -11,6 +11,9 @@ export function FilesInterceptor(fieldname, maxCount = 1, options) {
|
|
|
11
11
|
async intercept(context, next) {
|
|
12
12
|
const ctx = context.switchToHttp();
|
|
13
13
|
const req = getMultipartRequest(ctx);
|
|
14
|
+
if (!req.header("content-type")?.startsWith("multipart/form-data")) {
|
|
15
|
+
return next.handle();
|
|
16
|
+
}
|
|
14
17
|
const { body, files, remove } = await handleMultipartMultipleFiles(req, fieldname, maxCount, this.options);
|
|
15
18
|
req.body = body;
|
|
16
19
|
req.storageFiles = files;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/files-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF,MAAM,UAAU,gBAAgB,CAC9B,SAAiB,EACjB,QAAQ,GAAG,CAAC,EACZ,OAAuB;IAEvB,MAAM,gBAAgB;QAGpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,4BAA4B,CAChE,GAAG,EACH,SAAS,EACT,QAAQ,EACR,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC;YAEzB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
1
|
+
{"version":3,"file":"files-interceptor.js","sourceRoot":"","sources":["../../../../../src/multer/interceptors/files-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,GAAG,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAGL,KAAK,GAGN,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAiB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF,MAAM,UAAU,gBAAgB,CAC9B,SAAiB,EACjB,QAAQ,GAAG,CAAC,EACZ,OAAuB;IAEvB,MAAM,gBAAgB;QAGpB;YACE,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,KAAK,CAAC,SAAS,CACb,OAAyB,EACzB,IAAiB;YAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,CAAC;YAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,4BAA4B,CAChE,GAAG,EACH,SAAS,EACT,QAAQ,EACR,IAAI,CAAC,OAAO,CACb,CAAC;YAEF,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC;YAEzB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,CAAC;KACF;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { BadRequestException } from "@nestjs/common";
|
|
2
2
|
export const getMultipartRequest = (ctx) => {
|
|
3
3
|
const req = ctx.getRequest();
|
|
4
|
-
if (!req.header("content-type")?.startsWith("multipart/form-data")) {
|
|
5
|
-
throw new BadRequestException("Not a multipart request");
|
|
6
|
-
}
|
|
7
4
|
return req;
|
|
8
5
|
};
|
|
9
6
|
export const getParts = async (req, options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../../src/multer/multipart/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAerD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAsB,EAAE,EAAE;IAC5D,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,EAAgB,CAAC;IAE3C,
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../../src/multer/multipart/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAerD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAsB,EAAE,EAAE;IAC5D,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,EAAgB,CAAC;IAE3C,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAiB,EAAE,OAAsB,EAAE,EAAE;IAC1E,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IAEjD,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,IACE,IAAI,YAAY,IAAI;YACpB,OAAO,EAAE,MAAM,EAAE,QAAQ;YACzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EACnC,CAAC;YACD,MAAM,IAAI,mBAAmB,CAC3B,QAAQ,GAAG,kCAAkC,OAAO,CAAC,MAAM,CAAC,QAAQ,QAAQ,CAC7E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|