@kiyasov/platform-hono 1.3.4 → 1.3.6
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/.yarn/install-state.gz +0 -0
- package/dist/cjs/src/adapters/hono-adapter.js +3 -1
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
- package/dist/cjs/src/drivers/graphQLUpload/processRequest.js +7 -1
- package/dist/cjs/src/drivers/graphQLUpload/processRequest.js.map +1 -1
- package/dist/cjs/src/multer/multipart/handlers/any-files.d.ts +3 -3
- package/dist/cjs/src/multer/multipart/handlers/any-files.js +1 -1
- package/dist/cjs/src/multer/multipart/handlers/any-files.js.map +1 -1
- package/dist/cjs/src/multer/multipart/handlers/file-fields.d.ts +4 -4
- package/dist/cjs/src/multer/multipart/handlers/file-fields.js +1 -1
- package/dist/cjs/src/multer/multipart/handlers/file-fields.js.map +1 -1
- package/dist/cjs/src/multer/multipart/handlers/multiple-files.d.ts +3 -3
- package/dist/cjs/src/multer/multipart/handlers/multiple-files.js +1 -1
- package/dist/cjs/src/multer/multipart/handlers/multiple-files.js.map +1 -1
- package/dist/cjs/src/multer/multipart/handlers/single-file.d.ts +3 -3
- package/dist/cjs/src/multer/multipart/handlers/single-file.js +1 -1
- package/dist/cjs/src/multer/multipart/handlers/single-file.js.map +1 -1
- package/dist/cjs/src/multer/multipart/request.d.ts +1 -3
- package/dist/cjs/src/multer/multipart/request.js +4 -4
- 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.js +3 -1
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
- package/dist/esm/src/drivers/graphQLUpload/processRequest.js +7 -1
- package/dist/esm/src/drivers/graphQLUpload/processRequest.js.map +1 -1
- package/dist/esm/src/multer/multipart/handlers/any-files.d.ts +3 -3
- package/dist/esm/src/multer/multipart/handlers/any-files.js +4 -4
- package/dist/esm/src/multer/multipart/handlers/any-files.js.map +1 -1
- package/dist/esm/src/multer/multipart/handlers/file-fields.d.ts +4 -4
- package/dist/esm/src/multer/multipart/handlers/file-fields.js +5 -5
- package/dist/esm/src/multer/multipart/handlers/file-fields.js.map +1 -1
- package/dist/esm/src/multer/multipart/handlers/multiple-files.d.ts +3 -3
- package/dist/esm/src/multer/multipart/handlers/multiple-files.js +5 -5
- package/dist/esm/src/multer/multipart/handlers/multiple-files.js.map +1 -1
- package/dist/esm/src/multer/multipart/handlers/single-file.d.ts +3 -3
- package/dist/esm/src/multer/multipart/handlers/single-file.js +4 -4
- package/dist/esm/src/multer/multipart/handlers/single-file.js.map +1 -1
- package/dist/esm/src/multer/multipart/request.d.ts +1 -3
- package/dist/esm/src/multer/multipart/request.js +4 -4
- 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/adapters/hono-adapter.ts +3 -1
- package/src/drivers/graphQLUpload/processRequest.ts +8 -1
- package/src/multer/multipart/handlers/any-files.ts +7 -7
- package/src/multer/multipart/handlers/file-fields.ts +12 -12
- package/src/multer/multipart/handlers/multiple-files.ts +10 -10
- package/src/multer/multipart/handlers/single-file.ts +9 -9
- package/src/multer/multipart/request.ts +4 -4
package/package.json
CHANGED
|
@@ -251,7 +251,9 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
251
251
|
contentType?.startsWith("multipart/form-data") ||
|
|
252
252
|
contentType?.startsWith("application/x-www-form-urlencoded")
|
|
253
253
|
) {
|
|
254
|
-
(ctx.req as any).body = await ctx.req.parseBody(
|
|
254
|
+
(ctx.req as any).body = await ctx.req.parseBody({
|
|
255
|
+
all: true,
|
|
256
|
+
});
|
|
255
257
|
} else if (
|
|
256
258
|
contentType?.startsWith("application/json") ||
|
|
257
259
|
contentType?.startsWith("text/plain")
|
|
@@ -25,12 +25,19 @@ export async function processRequest(
|
|
|
25
25
|
Readable.from(buffer).pipe(capacitor);
|
|
26
26
|
|
|
27
27
|
const upload = new Upload();
|
|
28
|
+
|
|
28
29
|
upload.file = {
|
|
29
30
|
filename: file.name,
|
|
30
31
|
mimetype: file.type,
|
|
31
32
|
fieldName,
|
|
32
33
|
encoding: "7bit",
|
|
33
|
-
createReadStream: (options) =>
|
|
34
|
+
createReadStream: (options) => {
|
|
35
|
+
const stream = capacitor.createReadStream(options);
|
|
36
|
+
stream.on("close", () => {
|
|
37
|
+
capacitor.release();
|
|
38
|
+
});
|
|
39
|
+
return stream;
|
|
40
|
+
},
|
|
34
41
|
capacitor,
|
|
35
42
|
};
|
|
36
43
|
upload.resolve(upload.file);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { UploadOptions } from
|
|
2
|
-
import { StorageFile } from
|
|
3
|
-
import { THonoRequest, getParts } from
|
|
4
|
-
import { removeStorageFiles } from
|
|
5
|
-
import { filterUpload } from
|
|
1
|
+
import { UploadOptions } from "../options";
|
|
2
|
+
import { StorageFile } from "../../storage";
|
|
3
|
+
import { THonoRequest, getParts } from "../request";
|
|
4
|
+
import { removeStorageFiles } from "../file";
|
|
5
|
+
import { filterUpload } from "../filter";
|
|
6
6
|
|
|
7
7
|
export const handleMultipartAnyFiles = async (
|
|
8
8
|
req: THonoRequest,
|
|
9
|
-
options: UploadOptions
|
|
9
|
+
options: UploadOptions
|
|
10
10
|
) => {
|
|
11
|
-
const parts =
|
|
11
|
+
const parts = getParts(req, options);
|
|
12
12
|
|
|
13
13
|
const body: Record<string, any> = {};
|
|
14
14
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BadRequestException } from
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
2
|
|
|
3
|
-
import { UploadOptions } from
|
|
4
|
-
import { StorageFile } from
|
|
5
|
-
import { THonoRequest, getParts } from
|
|
6
|
-
import { removeStorageFiles } from
|
|
7
|
-
import { filterUpload } from
|
|
8
|
-
import { HonoRequest } from
|
|
3
|
+
import { UploadOptions } from "../options";
|
|
4
|
+
import { StorageFile } from "../../storage/storage";
|
|
5
|
+
import { THonoRequest, getParts } from "../request";
|
|
6
|
+
import { removeStorageFiles } from "../file";
|
|
7
|
+
import { filterUpload } from "../filter";
|
|
8
|
+
import { HonoRequest } from "hono";
|
|
9
9
|
|
|
10
10
|
export interface UploadField {
|
|
11
11
|
/**
|
|
@@ -18,7 +18,7 @@ export interface UploadField {
|
|
|
18
18
|
maxCount?: number;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export type UploadFieldMapEntry = Required<Pick<UploadField,
|
|
21
|
+
export type UploadFieldMapEntry = Required<Pick<UploadField, "maxCount">>;
|
|
22
22
|
|
|
23
23
|
export const uploadFieldsToMap = (uploadFields: UploadField[]) => {
|
|
24
24
|
const map = new Map<string, UploadFieldMapEntry>();
|
|
@@ -33,9 +33,9 @@ export const uploadFieldsToMap = (uploadFields: UploadField[]) => {
|
|
|
33
33
|
export const handleMultipartFileFields = async (
|
|
34
34
|
req: THonoRequest,
|
|
35
35
|
fieldsMap: Map<string, UploadFieldMapEntry>,
|
|
36
|
-
options: UploadOptions
|
|
36
|
+
options: UploadOptions
|
|
37
37
|
) => {
|
|
38
|
-
const parts =
|
|
38
|
+
const parts = getParts(req, options);
|
|
39
39
|
const body: Record<string, any> = {};
|
|
40
40
|
|
|
41
41
|
const files: Record<string, StorageFile[]> = {};
|
|
@@ -56,7 +56,7 @@ export const handleMultipartFileFields = async (
|
|
|
56
56
|
|
|
57
57
|
if (fieldOptions == null) {
|
|
58
58
|
throw new BadRequestException(
|
|
59
|
-
`Field ${fieldName} doesn't accept files
|
|
59
|
+
`Field ${fieldName} doesn't accept files`
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -66,7 +66,7 @@ export const handleMultipartFileFields = async (
|
|
|
66
66
|
|
|
67
67
|
if (files[fieldName].length + 1 > fieldOptions.maxCount) {
|
|
68
68
|
throw new BadRequestException(
|
|
69
|
-
`Field ${fieldName} accepts max ${fieldOptions.maxCount} files
|
|
69
|
+
`Field ${fieldName} accepts max ${fieldOptions.maxCount} files`
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { BadRequestException } from
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
2
|
|
|
3
|
-
import { UploadOptions } from
|
|
4
|
-
import { StorageFile } from
|
|
5
|
-
import { removeStorageFiles } from
|
|
6
|
-
import { THonoRequest, getParts } from
|
|
7
|
-
import { filterUpload } from
|
|
3
|
+
import { UploadOptions } from "../options";
|
|
4
|
+
import { StorageFile } from "../../storage";
|
|
5
|
+
import { removeStorageFiles } from "../file";
|
|
6
|
+
import { THonoRequest, getParts } from "../request";
|
|
7
|
+
import { filterUpload } from "../filter";
|
|
8
8
|
|
|
9
9
|
export const handleMultipartMultipleFiles = async (
|
|
10
10
|
req: THonoRequest,
|
|
11
11
|
fieldname: string,
|
|
12
12
|
maxCount: number,
|
|
13
|
-
options: UploadOptions
|
|
13
|
+
options: UploadOptions
|
|
14
14
|
) => {
|
|
15
|
-
const parts =
|
|
15
|
+
const parts = getParts(req, options);
|
|
16
16
|
const body: Record<string, any> = {};
|
|
17
17
|
|
|
18
18
|
const files: StorageFile[] = [];
|
|
@@ -30,13 +30,13 @@ export const handleMultipartMultipleFiles = async (
|
|
|
30
30
|
|
|
31
31
|
if (partFieldName !== fieldname) {
|
|
32
32
|
throw new BadRequestException(
|
|
33
|
-
`Field ${partFieldName} doesn't accept files
|
|
33
|
+
`Field ${partFieldName} doesn't accept files`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (files.length + 1 > maxCount) {
|
|
38
38
|
throw new BadRequestException(
|
|
39
|
-
`Field ${partFieldName} accepts max ${maxCount} files
|
|
39
|
+
`Field ${partFieldName} accepts max ${maxCount} files`
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { BadRequestException } from
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
2
|
|
|
3
|
-
import { UploadOptions } from
|
|
4
|
-
import { StorageFile } from
|
|
5
|
-
import { THonoRequest, getParts } from
|
|
6
|
-
import { filterUpload } from
|
|
3
|
+
import { UploadOptions } from "../options";
|
|
4
|
+
import { StorageFile } from "../../storage";
|
|
5
|
+
import { THonoRequest, getParts } from "../request";
|
|
6
|
+
import { filterUpload } from "../filter";
|
|
7
7
|
|
|
8
8
|
export const handleMultipartSingleFile = async (
|
|
9
9
|
req: THonoRequest,
|
|
10
10
|
fieldname: string,
|
|
11
|
-
options: UploadOptions
|
|
11
|
+
options: UploadOptions
|
|
12
12
|
) => {
|
|
13
|
-
const parts =
|
|
13
|
+
const parts = getParts(req, options);
|
|
14
14
|
const body: Record<string, any> = {};
|
|
15
15
|
|
|
16
16
|
let file: StorageFile | undefined = undefined;
|
|
@@ -29,11 +29,11 @@ export const handleMultipartSingleFile = async (
|
|
|
29
29
|
|
|
30
30
|
if (partFieldName !== fieldname) {
|
|
31
31
|
throw new BadRequestException(
|
|
32
|
-
`Field ${partFieldName} doesn't accept file
|
|
32
|
+
`Field ${partFieldName} doesn't accept file`
|
|
33
33
|
);
|
|
34
34
|
} else if (file != null) {
|
|
35
35
|
throw new BadRequestException(
|
|
36
|
-
`Field ${fieldname} accepts only one file
|
|
36
|
+
`Field ${fieldname} accepts only one file`
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -19,10 +19,10 @@ export const getMultipartRequest = (ctx: HttpArgumentsHost) => {
|
|
|
19
19
|
return req;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export const getParts =
|
|
23
|
-
const
|
|
22
|
+
export const getParts = (req: THonoRequest, options: UploadOptions) => {
|
|
23
|
+
const parts = req.body;
|
|
24
24
|
|
|
25
|
-
for (const [key, file] of Object.entries(
|
|
25
|
+
for (const [key, file] of Object.entries(parts)) {
|
|
26
26
|
if (
|
|
27
27
|
file instanceof File &&
|
|
28
28
|
options?.limits?.fileSize &&
|
|
@@ -34,7 +34,7 @@ export const getParts = async (req: THonoRequest, options: UploadOptions) => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
return
|
|
37
|
+
return parts;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
export type MultipartsIterator = AsyncIterableIterator<MultipartFile>;
|