@kiyasov/platform-hono 1.5.6 → 1.5.8
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/.claude/settings.local.json +5 -2
- package/dist/cjs/src/adapters/hono-adapter.js +11 -11
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.js +11 -11
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +14 -13
- package/src/adapters/hono-adapter.ts +24 -29
- package/src/interfaces/nest-hono-application.interface.ts +3 -2
- package/dist/build.d.ts +0 -1
- package/dist/build.js +0 -28
- package/dist/build.js.map +0 -1
- package/dist/cjs/src/multer/crypto/index.d.ts +0 -1
- package/dist/cjs/src/multer/crypto/index.js +0 -7
- package/dist/cjs/src/multer/crypto/index.js.map +0 -1
- package/dist/cjs/src/multer/stream/index.d.ts +0 -2
- package/dist/cjs/src/multer/stream/index.js +0 -7
- package/dist/cjs/src/multer/stream/index.js.map +0 -1
- package/dist/esm/build.d.ts +0 -1
- package/dist/esm/build.js +0 -28
- package/dist/esm/build.js.map +0 -1
- package/dist/esm/src/multer/crypto/index.d.ts +0 -1
- package/dist/esm/src/multer/crypto/index.js +0 -4
- package/dist/esm/src/multer/crypto/index.js.map +0 -1
- package/dist/esm/src/multer/stream/index.d.ts +0 -2
- package/dist/esm/src/multer/stream/index.js +0 -4
- package/dist/esm/src/multer/stream/index.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
- package/dist/src/adapters/hono-adapter.d.ts +0 -66
- package/dist/src/adapters/hono-adapter.js +0 -270
- package/dist/src/adapters/hono-adapter.js.map +0 -1
- package/dist/src/adapters/index.d.ts +0 -1
- package/dist/src/adapters/index.js +0 -2
- package/dist/src/adapters/index.js.map +0 -1
- package/dist/src/drivers/constants/apollo.constants.d.ts +0 -1
- package/dist/src/drivers/constants/apollo.constants.js +0 -2
- package/dist/src/drivers/constants/apollo.constants.js.map +0 -1
- package/dist/src/drivers/constants/index.d.ts +0 -1
- package/dist/src/drivers/constants/index.js +0 -2
- package/dist/src/drivers/constants/index.js.map +0 -1
- package/dist/src/drivers/graphQLUpload/GraphQLUpload.d.ts +0 -3
- package/dist/src/drivers/graphQLUpload/GraphQLUpload.js +0 -18
- package/dist/src/drivers/graphQLUpload/GraphQLUpload.js.map +0 -1
- package/dist/src/drivers/graphQLUpload/Upload.d.ts +0 -16
- package/dist/src/drivers/graphQLUpload/Upload.js +0 -17
- package/dist/src/drivers/graphQLUpload/Upload.js.map +0 -1
- package/dist/src/drivers/graphQLUpload/fs-capacitor.d.ts +0 -42
- package/dist/src/drivers/graphQLUpload/fs-capacitor.js +0 -185
- package/dist/src/drivers/graphQLUpload/fs-capacitor.js.map +0 -1
- package/dist/src/drivers/graphQLUpload/index.d.ts +0 -4
- package/dist/src/drivers/graphQLUpload/index.js +0 -5
- package/dist/src/drivers/graphQLUpload/index.js.map +0 -1
- package/dist/src/drivers/graphQLUpload/processRequest.d.ts +0 -2
- package/dist/src/drivers/graphQLUpload/processRequest.js +0 -47
- package/dist/src/drivers/graphQLUpload/processRequest.js.map +0 -1
- package/dist/src/drivers/graphql.driver.d.ts +0 -20
- package/dist/src/drivers/graphql.driver.js +0 -125
- package/dist/src/drivers/graphql.driver.js.map +0 -1
- package/dist/src/drivers/index.d.ts +0 -2
- package/dist/src/drivers/index.js +0 -3
- package/dist/src/drivers/index.js.map +0 -1
- package/dist/src/drivers/services/plugins-explorer.service.d.ts +0 -9
- package/dist/src/drivers/services/plugins-explorer.service.js +0 -22
- package/dist/src/drivers/services/plugins-explorer.service.js.map +0 -1
- package/dist/src/interfaces/hono.interface.d.ts +0 -4
- package/dist/src/interfaces/hono.interface.js +0 -2
- package/dist/src/interfaces/hono.interface.js.map +0 -1
- package/dist/src/interfaces/index.d.ts +0 -2
- package/dist/src/interfaces/index.js +0 -3
- package/dist/src/interfaces/index.js.map +0 -1
- package/dist/src/interfaces/nest-hono-application.interface.d.ts +0 -18
- package/dist/src/interfaces/nest-hono-application.interface.js +0 -2
- package/dist/src/interfaces/nest-hono-application.interface.js.map +0 -1
- package/dist/src/multer/decorators/index.d.ts +0 -2
- package/dist/src/multer/decorators/index.js +0 -3
- package/dist/src/multer/decorators/index.js.map +0 -1
- package/dist/src/multer/decorators/uploaded-file-decorator.d.ts +0 -1
- package/dist/src/multer/decorators/uploaded-file-decorator.js +0 -7
- package/dist/src/multer/decorators/uploaded-file-decorator.js.map +0 -1
- package/dist/src/multer/decorators/uploaded-files-decorator.d.ts +0 -1
- package/dist/src/multer/decorators/uploaded-files-decorator.js +0 -7
- package/dist/src/multer/decorators/uploaded-files-decorator.js.map +0 -1
- package/dist/src/multer/fs/index.d.ts +0 -2
- package/dist/src/multer/fs/index.js +0 -18
- package/dist/src/multer/fs/index.js.map +0 -1
- package/dist/src/multer/index.d.ts +0 -4
- package/dist/src/multer/index.js +0 -5
- package/dist/src/multer/index.js.map +0 -1
- package/dist/src/multer/interceptors/any-files-interceptor.d.ts +0 -3
- package/dist/src/multer/interceptors/any-files-interceptor.js +0 -27
- package/dist/src/multer/interceptors/any-files-interceptor.js.map +0 -1
- package/dist/src/multer/interceptors/file-fields-interceptor.d.ts +0 -4
- package/dist/src/multer/interceptors/file-fields-interceptor.js +0 -29
- package/dist/src/multer/interceptors/file-fields-interceptor.js.map +0 -1
- package/dist/src/multer/interceptors/file-interceptor.d.ts +0 -3
- package/dist/src/multer/interceptors/file-interceptor.js +0 -27
- package/dist/src/multer/interceptors/file-interceptor.js.map +0 -1
- package/dist/src/multer/interceptors/files-interceptor.d.ts +0 -3
- package/dist/src/multer/interceptors/files-interceptor.js +0 -27
- package/dist/src/multer/interceptors/files-interceptor.js.map +0 -1
- package/dist/src/multer/interceptors/index.d.ts +0 -4
- package/dist/src/multer/interceptors/index.js +0 -5
- package/dist/src/multer/interceptors/index.js.map +0 -1
- package/dist/src/multer/multipart/exceptions.d.ts +0 -1
- package/dist/src/multer/multipart/exceptions.js +0 -18
- package/dist/src/multer/multipart/exceptions.js.map +0 -1
- package/dist/src/multer/multipart/file.d.ts +0 -9
- package/dist/src/multer/multipart/file.js +0 -6
- package/dist/src/multer/multipart/file.js.map +0 -1
- package/dist/src/multer/multipart/filter.d.ts +0 -6
- package/dist/src/multer/multipart/filter.js +0 -18
- package/dist/src/multer/multipart/filter.js.map +0 -1
- package/dist/src/multer/multipart/handlers/any-files.d.ts +0 -10
- package/dist/src/multer/multipart/handlers/any-files.js +0 -29
- package/dist/src/multer/multipart/handlers/any-files.js.map +0 -1
- package/dist/src/multer/multipart/handlers/file-fields.d.ts +0 -17
- package/dist/src/multer/multipart/handlers/file-fields.js +0 -40
- package/dist/src/multer/multipart/handlers/file-fields.js.map +0 -1
- package/dist/src/multer/multipart/handlers/index.d.ts +0 -1
- package/dist/src/multer/multipart/handlers/index.js +0 -2
- package/dist/src/multer/multipart/handlers/index.js.map +0 -1
- package/dist/src/multer/multipart/handlers/multiple-files.d.ts +0 -10
- package/dist/src/multer/multipart/handlers/multiple-files.js +0 -36
- package/dist/src/multer/multipart/handlers/multiple-files.js.map +0 -1
- package/dist/src/multer/multipart/handlers/single-file.d.ts +0 -10
- package/dist/src/multer/multipart/handlers/single-file.js +0 -41
- package/dist/src/multer/multipart/handlers/single-file.js.map +0 -1
- package/dist/src/multer/multipart/index.d.ts +0 -3
- package/dist/src/multer/multipart/index.js +0 -3
- package/dist/src/multer/multipart/index.js.map +0 -1
- package/dist/src/multer/multipart/options.d.ts +0 -21
- package/dist/src/multer/multipart/options.js +0 -19
- package/dist/src/multer/multipart/options.js.map +0 -1
- package/dist/src/multer/multipart/request.d.ts +0 -15
- package/dist/src/multer/multipart/request.js +0 -17
- package/dist/src/multer/multipart/request.js.map +0 -1
- package/dist/src/multer/storage/disk-storage.d.ts +0 -31
- package/dist/src/multer/storage/disk-storage.js +0 -59
- package/dist/src/multer/storage/disk-storage.js.map +0 -1
- package/dist/src/multer/storage/index.d.ts +0 -3
- package/dist/src/multer/storage/index.js +0 -4
- package/dist/src/multer/storage/index.js.map +0 -1
- package/dist/src/multer/storage/memory-storage.d.ts +0 -19
- package/dist/src/multer/storage/memory-storage.js +0 -23
- package/dist/src/multer/storage/memory-storage.js.map +0 -1
- package/dist/src/multer/storage/storage.d.ts +0 -13
- package/dist/src/multer/storage/storage.js +0 -2
- package/dist/src/multer/storage/storage.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { StorageFile } from '../../storage';
|
|
2
|
-
import { UploadOptions } from '../options';
|
|
3
|
-
import { THonoRequest } from '../request';
|
|
4
|
-
export declare const handleMultipartSingleFile: (req: THonoRequest, fieldname: string, options: UploadOptions) => Promise<{
|
|
5
|
-
body: {
|
|
6
|
-
[x: string]: string | File;
|
|
7
|
-
};
|
|
8
|
-
file: StorageFile;
|
|
9
|
-
remove: () => Promise<void>;
|
|
10
|
-
}>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { BadRequestException } from '@nestjs/common';
|
|
2
|
-
import { filterUpload } from '../filter';
|
|
3
|
-
import { getParts } from '../request';
|
|
4
|
-
export const handleMultipartSingleFile = async (req, fieldname, options) => {
|
|
5
|
-
const parts = getParts(req, options);
|
|
6
|
-
const body = {};
|
|
7
|
-
let file;
|
|
8
|
-
const removeFiles = async (error) => {
|
|
9
|
-
if (!file)
|
|
10
|
-
return;
|
|
11
|
-
await options.storage.removeFile(file, error);
|
|
12
|
-
};
|
|
13
|
-
try {
|
|
14
|
-
for await (const [partFieldName, part] of Object.entries(parts)) {
|
|
15
|
-
if (!(part instanceof File)) {
|
|
16
|
-
body[partFieldName] = part;
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
if (partFieldName !== fieldname) {
|
|
20
|
-
throw new BadRequestException(`Field "${partFieldName}" doesn't accept file.`);
|
|
21
|
-
}
|
|
22
|
-
if (file) {
|
|
23
|
-
throw new BadRequestException(`Field "${fieldname}" accepts only one file.`);
|
|
24
|
-
}
|
|
25
|
-
const _file = await options.storage.handleFile(part, req, partFieldName);
|
|
26
|
-
if (await filterUpload(options, req, _file)) {
|
|
27
|
-
file = _file;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
await removeFiles(true);
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
body,
|
|
37
|
-
file,
|
|
38
|
-
remove: () => removeFiles(),
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=single-file.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"single-file.js","sourceRoot":"","sources":["../../../../../src/multer/multipart/handlers/single-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAIrD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAgB,QAAQ,EAAE,MAAM,YAAY,CAAC;AASpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAC5C,GAAiB,EACjB,SAAiB,EACjB,OAAsB,EACtB,EAAE;IACF,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACrC,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,IAA6B,CAAC;IAMlC,MAAM,WAAW,GAAG,KAAK,EAAE,KAAe,EAAE,EAAE;QAC5C,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,MAAM,OAAO,CAAC,OAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,IAAI,KAAK,EAAE,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChE,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;gBAC5B,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;gBAC3B,SAAS;YACX,CAAC;YAED,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;gBAChC,MAAM,IAAI,mBAAmB,CAC3B,UAAU,aAAa,wBAAwB,CAChD,CAAC;YACJ,CAAC;YAED,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,IAAI,mBAAmB,CAC3B,UAAU,SAAS,0BAA0B,CAC9C,CAAC;YACJ,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,OAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;YAE1E,IAAI,MAAM,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;gBAC5C,IAAI,GAAG,KAAK,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE;KAC5B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/multer/multipart/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import busboy from 'busboy';
|
|
2
|
-
import { DiskStorage, Storage } from '../storage';
|
|
3
|
-
import { UploadFilterHandler } from './filter';
|
|
4
|
-
export type UploadOptions = busboy.BusboyConfig & {
|
|
5
|
-
dest?: string;
|
|
6
|
-
storage?: Storage;
|
|
7
|
-
filter?: UploadFilterHandler;
|
|
8
|
-
};
|
|
9
|
-
export declare const DEFAULT_UPLOAD_OPTIONS: Partial<UploadOptions>;
|
|
10
|
-
export declare const transformUploadOptions: (opts?: UploadOptions) => Partial<UploadOptions> | {
|
|
11
|
-
storage: DiskStorage;
|
|
12
|
-
headers?: import("http").IncomingHttpHeaders | undefined;
|
|
13
|
-
highWaterMark?: number | undefined;
|
|
14
|
-
fileHwm?: number | undefined;
|
|
15
|
-
defCharset?: string | undefined;
|
|
16
|
-
defParamCharset?: string | undefined;
|
|
17
|
-
preservePath?: boolean | undefined;
|
|
18
|
-
limits?: busboy.Limits | undefined;
|
|
19
|
-
dest?: string;
|
|
20
|
-
filter?: UploadFilterHandler;
|
|
21
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { DiskStorage, MemoryStorage } from '../storage';
|
|
2
|
-
export const DEFAULT_UPLOAD_OPTIONS = {
|
|
3
|
-
storage: new MemoryStorage(),
|
|
4
|
-
};
|
|
5
|
-
export const transformUploadOptions = (opts) => {
|
|
6
|
-
if (opts == null)
|
|
7
|
-
return DEFAULT_UPLOAD_OPTIONS;
|
|
8
|
-
if (opts.dest != null) {
|
|
9
|
-
return {
|
|
10
|
-
...opts,
|
|
11
|
-
storage: new DiskStorage({
|
|
12
|
-
dest: opts.dest,
|
|
13
|
-
...opts.storage?.options,
|
|
14
|
-
}),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return { ...DEFAULT_UPLOAD_OPTIONS, ...opts };
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../src/multer/multipart/options.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAW,MAAM,YAAY,CAAC;AASjE,MAAM,CAAC,MAAM,sBAAsB,GAA2B;IAC5D,OAAO,EAAE,IAAI,aAAa,EAAE;CAC7B,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAoB,EAAE,EAAE;IAC7D,IAAI,IAAI,IAAI,IAAI;QAAE,OAAO,sBAAsB,CAAC;IAEhD,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;QACtB,OAAO;YACL,GAAG,IAAI;YACP,OAAO,EAAE,IAAI,WAAW,CAAC;gBACvB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO;aACzB,CAAC;SACH,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,GAAG,sBAAsB,EAAE,GAAG,IAAI,EAAE,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { HttpArgumentsHost } from '@nestjs/common/interfaces';
|
|
2
|
-
import { HonoRequest } from 'hono';
|
|
3
|
-
import { BodyData } from 'hono/utils/body';
|
|
4
|
-
import { StorageFile } from '../storage';
|
|
5
|
-
import { MultipartFile } from './file';
|
|
6
|
-
import { UploadOptions } from './options';
|
|
7
|
-
export type THonoRequest = HonoRequest & {
|
|
8
|
-
files: Record<string, File[]>;
|
|
9
|
-
body: BodyData;
|
|
10
|
-
storageFile?: StorageFile;
|
|
11
|
-
storageFiles?: StorageFile[] | Record<string, StorageFile[]>;
|
|
12
|
-
};
|
|
13
|
-
export declare const getMultipartRequest: (ctx: HttpArgumentsHost) => THonoRequest;
|
|
14
|
-
export declare const getParts: (req: THonoRequest, options: UploadOptions) => BodyData;
|
|
15
|
-
export type MultipartsIterator = AsyncIterableIterator<MultipartFile>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { BadRequestException } from '@nestjs/common';
|
|
2
|
-
export const getMultipartRequest = (ctx) => {
|
|
3
|
-
return ctx.getRequest();
|
|
4
|
-
};
|
|
5
|
-
export const getParts = (req, options) => {
|
|
6
|
-
const parts = req.body;
|
|
7
|
-
for (const [key, file] of Object.entries(parts)) {
|
|
8
|
-
if (file instanceof File) {
|
|
9
|
-
const maxSize = options?.limits?.fileSize;
|
|
10
|
-
if (maxSize && file.size > maxSize) {
|
|
11
|
-
throw new BadRequestException(`File "${key}" is too large. Maximum size is ${maxSize} bytes.`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return parts;
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=request.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../src/multer/multipart/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAqBrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAsB,EAAgB,EAAE;IAC1E,OAAO,GAAG,CAAC,UAAU,EAAgB,CAAC;AACxC,CAAC,CAAC;AASF,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,GAAiB,EACjB,OAAsB,EACZ,EAAE;IACZ,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC;IAEvB,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;YACzB,MAAM,OAAO,GAAG,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;YAC1C,IAAI,OAAO,IAAI,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,CAAC;gBACnC,MAAM,IAAI,mBAAmB,CAC3B,SAAS,GAAG,mCAAmC,OAAO,SAAS,CAChE,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { HonoRequest } from 'hono';
|
|
2
|
-
import { StorageFile, Storage } from './storage';
|
|
3
|
-
export interface DiskStorageFile extends StorageFile {
|
|
4
|
-
dest: string;
|
|
5
|
-
filename: string;
|
|
6
|
-
path: string;
|
|
7
|
-
}
|
|
8
|
-
type DiskStorageOptionHandler = ((file: File, req: HonoRequest) => Promise<string> | string) | string;
|
|
9
|
-
export interface DiskStorageOptions {
|
|
10
|
-
dest?: DiskStorageOptionHandler;
|
|
11
|
-
filename?: DiskStorageOptionHandler;
|
|
12
|
-
removeAfter?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare class DiskStorage implements Storage<DiskStorageFile, DiskStorageOptions> {
|
|
15
|
-
readonly options?: DiskStorageOptions;
|
|
16
|
-
constructor(options?: DiskStorageOptions);
|
|
17
|
-
handleFile(file: File, req: HonoRequest, fieldName: string): Promise<{
|
|
18
|
-
size: number;
|
|
19
|
-
dest: string;
|
|
20
|
-
filename: string;
|
|
21
|
-
originalFilename: string;
|
|
22
|
-
path: string;
|
|
23
|
-
mimetype: string;
|
|
24
|
-
encoding: string;
|
|
25
|
-
fieldname: string;
|
|
26
|
-
}>;
|
|
27
|
-
removeFile(file: DiskStorageFile, force?: boolean): Promise<void>;
|
|
28
|
-
protected getFilename(file: File, req: HonoRequest, obj?: DiskStorageOptionHandler): Promise<string>;
|
|
29
|
-
protected getFileDestination(file: File, req: HonoRequest, obj?: DiskStorageOptionHandler): Promise<string>;
|
|
30
|
-
}
|
|
31
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createWriteStream } from 'fs';
|
|
2
|
-
import { mkdir, unlink } from 'fs/promises';
|
|
3
|
-
import { Readable } from 'node:stream';
|
|
4
|
-
import { pipeline } from 'node:stream/promises';
|
|
5
|
-
import { tmpdir } from 'os';
|
|
6
|
-
import { join } from 'path';
|
|
7
|
-
import { getUniqueFilename, pathExists } from '../fs';
|
|
8
|
-
const excecuteStorageHandler = (file, req, obj) => {
|
|
9
|
-
if (typeof obj === 'function') {
|
|
10
|
-
return obj(file, req);
|
|
11
|
-
}
|
|
12
|
-
if (obj != null)
|
|
13
|
-
return obj;
|
|
14
|
-
return null;
|
|
15
|
-
};
|
|
16
|
-
const ENV_TESTS_STORAGE_TMP_PATH = process.env.__TESTS_TMP_PATH__;
|
|
17
|
-
export class DiskStorage {
|
|
18
|
-
options;
|
|
19
|
-
constructor(options) {
|
|
20
|
-
this.options = options;
|
|
21
|
-
if (ENV_TESTS_STORAGE_TMP_PATH != null) {
|
|
22
|
-
this.options = { ...this.options, dest: ENV_TESTS_STORAGE_TMP_PATH };
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async handleFile(file, req, fieldName) {
|
|
26
|
-
const filename = await this.getFilename(file, req, this.options?.filename);
|
|
27
|
-
const dest = await this.getFileDestination(file, req, this.options?.dest);
|
|
28
|
-
if (!(await pathExists(dest))) {
|
|
29
|
-
await mkdir(dest, { recursive: true });
|
|
30
|
-
}
|
|
31
|
-
const path = join(dest, filename);
|
|
32
|
-
const stream = createWriteStream(path);
|
|
33
|
-
const buffer = await file.arrayBuffer();
|
|
34
|
-
const readableStream = Readable.from(Buffer.from(buffer));
|
|
35
|
-
await pipeline(readableStream, stream);
|
|
36
|
-
return {
|
|
37
|
-
size: stream.bytesWritten,
|
|
38
|
-
dest,
|
|
39
|
-
filename,
|
|
40
|
-
originalFilename: file.name,
|
|
41
|
-
path,
|
|
42
|
-
mimetype: file.type,
|
|
43
|
-
encoding: 'utf-8',
|
|
44
|
-
fieldname: fieldName,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async removeFile(file, force) {
|
|
48
|
-
if (!this.options?.removeAfter && !force)
|
|
49
|
-
return;
|
|
50
|
-
await unlink(file.path);
|
|
51
|
-
}
|
|
52
|
-
async getFilename(file, req, obj) {
|
|
53
|
-
return (excecuteStorageHandler(file, req, obj) ?? getUniqueFilename(file.name));
|
|
54
|
-
}
|
|
55
|
-
async getFileDestination(file, req, obj) {
|
|
56
|
-
return excecuteStorageHandler(file, req, obj) ?? tmpdir();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=disk-storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"disk-storage.js","sourceRoot":"","sources":["../../../../src/multer/storage/disk-storage.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/multer/storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HonoRequest } from 'hono';
|
|
2
|
-
import { StorageFile, Storage } from './storage';
|
|
3
|
-
export interface MemoryStorageFile extends StorageFile {
|
|
4
|
-
buffer: Buffer;
|
|
5
|
-
stream: () => ReadableStream<Uint8Array>;
|
|
6
|
-
}
|
|
7
|
-
export declare class MemoryStorage implements Storage<MemoryStorageFile> {
|
|
8
|
-
handleFile(file: File, _req: HonoRequest, fieldName: string): Promise<{
|
|
9
|
-
buffer: Buffer<ArrayBufferLike>;
|
|
10
|
-
size: number;
|
|
11
|
-
encoding: string;
|
|
12
|
-
mimetype: string;
|
|
13
|
-
fieldname: string;
|
|
14
|
-
originalFilename: string;
|
|
15
|
-
stream: () => ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
16
|
-
lastModified: number;
|
|
17
|
-
}>;
|
|
18
|
-
removeFile(file: MemoryStorageFile): Promise<void>;
|
|
19
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export class MemoryStorage {
|
|
2
|
-
async handleFile(file, _req, fieldName) {
|
|
3
|
-
const buffer = await file
|
|
4
|
-
.stream()
|
|
5
|
-
.pipeTo(new WritableStream())
|
|
6
|
-
.then(() => file.arrayBuffer())
|
|
7
|
-
.then((buffer) => Buffer.from(buffer));
|
|
8
|
-
return {
|
|
9
|
-
buffer,
|
|
10
|
-
size: buffer.length,
|
|
11
|
-
encoding: 'utf-8',
|
|
12
|
-
mimetype: file.type,
|
|
13
|
-
fieldname: fieldName,
|
|
14
|
-
originalFilename: file.name,
|
|
15
|
-
stream: () => file.stream(),
|
|
16
|
-
lastModified: file.lastModified,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
async removeFile(file) {
|
|
20
|
-
delete file.buffer;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=memory-storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-storage.js","sourceRoot":"","sources":["../../../../src/multer/storage/memory-storage.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,aAAa;IACjB,KAAK,CAAC,UAAU,CAAC,IAAU,EAAE,IAAiB,EAAE,SAAiB;QACtE,MAAM,MAAM,GAAG,MAAM,IAAI;aACtB,MAAM,EAAE;aACR,MAAM,CAAC,IAAI,cAAc,EAAE,CAAC;aAC5B,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;aAC9B,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAEzC,OAAO;YACL,MAAM;YACN,IAAI,EAAE,MAAM,CAAC,MAAM;YACnB,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,SAAS,EAAE,SAAS;YACpB,gBAAgB,EAAE,IAAI,CAAC,IAAI;YAC3B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAuB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { HonoRequest } from 'hono';
|
|
2
|
-
export interface StorageFile {
|
|
3
|
-
size: number;
|
|
4
|
-
fieldname: string;
|
|
5
|
-
encoding: string;
|
|
6
|
-
mimetype: string;
|
|
7
|
-
originalFilename: string;
|
|
8
|
-
}
|
|
9
|
-
export interface Storage<T extends StorageFile = StorageFile, K = any> {
|
|
10
|
-
handleFile: (file: File, req: HonoRequest, fieldName: string) => Promise<T>;
|
|
11
|
-
removeFile: (file: T, force?: boolean) => Promise<void> | void;
|
|
12
|
-
options?: K;
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../../src/multer/storage/storage.ts"],"names":[],"mappings":""}
|