@venizia/ignis-helpers 0.4.8-5 → 0.4.8-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/esm/core.d.ts +1 -0
- package/dist/esm/core.js +1 -0
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/storage/base.d.ts +3 -2
- package/dist/esm/modules/storage/base.js +45 -24
- package/dist/esm/modules/storage/base.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.js +7 -4
- package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/esm/modules/storage/disk/helper.js +29 -14
- package/dist/esm/modules/storage/disk/helper.js.map +1 -1
- package/dist/esm/utilities/echo.utility.d.ts +35 -0
- package/dist/esm/utilities/echo.utility.js +54 -0
- package/dist/esm/utilities/echo.utility.js.map +1 -0
- package/dist/esm/utilities/index.d.ts +1 -0
- package/dist/esm/utilities/index.js +1 -0
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/record.utility.d.ts +10 -1
- package/dist/esm/utilities/record.utility.js +22 -1
- package/dist/esm/utilities/record.utility.js.map +1 -1
- package/package.json +3 -3
package/dist/esm/core.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export type { IBuildOptions, IHeightWhereOptions, ILeavesOptions, INodeWithPath,
|
|
|
26
26
|
export { TreeWalker } from './modules/tree/walk.js';
|
|
27
27
|
export { BuildInfoRegistry } from './utilities/build-info.utility.js';
|
|
28
28
|
export type { IBuildInfo, TBuildInfoRecord } from './utilities/build-info.utility.js';
|
|
29
|
+
export { EchoUtility } from './utilities/echo.utility.js';
|
|
29
30
|
export { ParseUtility } from './utilities/parse.utility.js';
|
|
30
31
|
export { PerformanceUtility } from './utilities/performance.utility.js';
|
|
31
32
|
export { PromiseUtility } from './utilities/promise.utility.js';
|
package/dist/esm/core.js
CHANGED
|
@@ -33,6 +33,7 @@ export { TreeWalker } from './modules/tree/walk.js';
|
|
|
33
33
|
// cannot itself become a subpath. Named one at a time here instead of widening the barrel: every
|
|
34
34
|
// symbol below is verified free of node builtins/globals.
|
|
35
35
|
export { BuildInfoRegistry } from './utilities/build-info.utility.js';
|
|
36
|
+
export { EchoUtility } from './utilities/echo.utility.js';
|
|
36
37
|
export { ParseUtility } from './utilities/parse.utility.js';
|
|
37
38
|
export { PerformanceUtility } from './utilities/performance.utility.js';
|
|
38
39
|
export { PromiseUtility } from './utilities/promise.utility.js';
|
package/dist/esm/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,6FAA6F;AAC7F,8DAA8D;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,6HAA6H;AAC7H,iHAAiH;AACjH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,cAAc,qDAAqD,CAAC;AACpE,qGAAqG;AACrG,4FAA4F;AAC5F,oBAAoB;AACpB,cAAc,qDAAqD,CAAC;AACpE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,iGAAiG;AACjG,yFAAyF;AACzF,cAAc,yDAAyD,CAAC;AAExE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAcrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,gGAAgG;AAChG,6FAA6F;AAC7F,iGAAiG;AACjG,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,uHAAuH;AACvH,gGAAgG;AAChG,0EAA0E;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAOlE,+FAA+F;AAC/F,6GAA6G;AAC7G,wCAAwC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC","sourcesContent":["export { BaseHelper } from './modules/base';\n// By name, never `export *` from `./modules/env`: that barrel also carries `Environment` and\n// `applicationEnvironment`, both of which read `process.env`.\nexport { EnvironmentNames } from './modules/env/names';\nexport * from './modules/error';\nexport { LogLevels } from './modules/logger/common/types';\nexport type { ILogger, ILoggerProvider, TLogLevel } from './modules/logger/common/types';\n// The one way to get a logger, the same in the browser and on the server: `LoggerFactory` imports nothing from node, and its\n// default provider is the console. An application chooses another with `LoggerFactory.use({ provider, level })`.\nexport { ConsoleLogger } from './modules/logger/base/console';\nexport { LoggerFactory } from './modules/logger/factory';\nexport * from './modules/network/http-request/fetcher/base-fetcher';\n// The node fetcher carries no node builtin - its one `querystring.stringify` is written out - so the\n// framework HTTP layer is reachable from a browser bundle, and a connector on HTTP need not\n// re-implement one.\nexport * from './modules/network/http-request/fetcher/node-fetcher';\nexport * from './modules/network/http-request/base-network-request.helper';\nexport * from './modules/pool';\nexport * from './modules/queue/internal/hf';\nexport * from './modules/temporal';\nexport * from './modules/uid';\n// The url guard, pure half only: `UrlPolicy` decides a url and a literal address with string and\n// number work. Its sibling `UrlIngest` reaches `node:dns` and stays out of this subpath.\nexport * from './modules/network/utilities/url-safety/common/constants';\nexport type { IUrlSafetyPolicy } from './modules/network/utilities/url-safety/common/types';\nexport * from './modules/network/utilities/url-safety/policy';\nexport * from './modules/network/utilities/query-string';\nexport { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants';\nexport type { TRetryBackoffStrategy, TRetryJitterMode } from './modules/retry/common/constants';\nexport type { IRetryBackoffOptions, IRetryContext } from './modules/retry/common/types';\nexport { RetryHelper } from './modules/retry/helper';\nexport { SlugHelper } from './modules/slug/helper';\nexport { TreeBuilder } from './modules/tree/builder';\nexport type {\n IBuildOptions,\n IHeightWhereOptions,\n ILeavesOptions,\n INodeWithPath,\n IPrintOptions,\n ITreeNode,\n IWalkAsyncOptions,\n IWalkOptions,\n TNodePredicate,\n TOnVisit,\n TOnVisitAsync,\n} from './modules/tree/common/types';\nexport { TreeWalker } from './modules/tree/walk';\n\n// Pure value/type utilities that already live under the root barrel's `./utilities` re-export -\n// that barrel also carries node-only siblings (module.utility.ts, request.utility.ts), so it\n// cannot itself become a subpath. Named one at a time here instead of widening the barrel: every\n// symbol below is verified free of node builtins/globals.\nexport { BuildInfoRegistry } from './utilities/build-info.utility';\nexport type { IBuildInfo, TBuildInfoRecord } from './utilities/build-info.utility';\nexport { ParseUtility } from './utilities/parse.utility';\nexport { PerformanceUtility } from './utilities/performance.utility';\nexport { PromiseUtility } from './utilities/promise.utility';\nexport { RecordUtility } from './utilities/record.utility';\nexport { FormBodyUtility, RequestBodyErrors } from './utilities/form-body.utility';\nexport { ProjectRootRegistry } from './utilities/project-root.utility';\n\n// `ECDH` is the one crypto algorithm that is browser-pure: it runs over `crypto.subtle`, `btoa` and `atob`. It and its\n// base class come by leaf path, never the algorithms barrel, which also carries `AES` and `RSA`\n// (server code: they use `Buffer`, and `AES` reads files with `node:fs`).\nexport { AbstractCryptoAlgorithm } from './modules/crypto/algorithms/abstract.algorithm';\nexport { ECDH } from './modules/crypto/algorithms/ecdh.algorithm';\nexport type {\n ECDHAlgorithmType,\n IECDHEncryptedPayload,\n IECDHExtraOptions,\n} from './modules/crypto/algorithms/ecdh.algorithm';\n\n// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even\n// though the concrete classes they describe (the other crypto algorithms, the ioredis-backed helper) are not\n// themselves part of this pure surface.\nexport { AESAlgorithms } from './modules/crypto/algorithms/aes.constants';\nexport type { AESAlgorithmType } from './modules/crypto/algorithms/aes.constants';\nexport type { IRedisHelper } from './modules/redis/common/interfaces';\n"]}
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,6FAA6F;AAC7F,8DAA8D;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,6HAA6H;AAC7H,iHAAiH;AACjH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,cAAc,qDAAqD,CAAC;AACpE,qGAAqG;AACrG,4FAA4F;AAC5F,oBAAoB;AACpB,cAAc,qDAAqD,CAAC;AACpE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,iGAAiG;AACjG,yFAAyF;AACzF,cAAc,yDAAyD,CAAC;AAExE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAcrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,gGAAgG;AAChG,6FAA6F;AAC7F,iGAAiG;AACjG,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,uHAAuH;AACvH,gGAAgG;AAChG,0EAA0E;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAOlE,+FAA+F;AAC/F,6GAA6G;AAC7G,wCAAwC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC","sourcesContent":["export { BaseHelper } from './modules/base';\n// By name, never `export *` from `./modules/env`: that barrel also carries `Environment` and\n// `applicationEnvironment`, both of which read `process.env`.\nexport { EnvironmentNames } from './modules/env/names';\nexport * from './modules/error';\nexport { LogLevels } from './modules/logger/common/types';\nexport type { ILogger, ILoggerProvider, TLogLevel } from './modules/logger/common/types';\n// The one way to get a logger, the same in the browser and on the server: `LoggerFactory` imports nothing from node, and its\n// default provider is the console. An application chooses another with `LoggerFactory.use({ provider, level })`.\nexport { ConsoleLogger } from './modules/logger/base/console';\nexport { LoggerFactory } from './modules/logger/factory';\nexport * from './modules/network/http-request/fetcher/base-fetcher';\n// The node fetcher carries no node builtin - its one `querystring.stringify` is written out - so the\n// framework HTTP layer is reachable from a browser bundle, and a connector on HTTP need not\n// re-implement one.\nexport * from './modules/network/http-request/fetcher/node-fetcher';\nexport * from './modules/network/http-request/base-network-request.helper';\nexport * from './modules/pool';\nexport * from './modules/queue/internal/hf';\nexport * from './modules/temporal';\nexport * from './modules/uid';\n// The url guard, pure half only: `UrlPolicy` decides a url and a literal address with string and\n// number work. Its sibling `UrlIngest` reaches `node:dns` and stays out of this subpath.\nexport * from './modules/network/utilities/url-safety/common/constants';\nexport type { IUrlSafetyPolicy } from './modules/network/utilities/url-safety/common/types';\nexport * from './modules/network/utilities/url-safety/policy';\nexport * from './modules/network/utilities/query-string';\nexport { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants';\nexport type { TRetryBackoffStrategy, TRetryJitterMode } from './modules/retry/common/constants';\nexport type { IRetryBackoffOptions, IRetryContext } from './modules/retry/common/types';\nexport { RetryHelper } from './modules/retry/helper';\nexport { SlugHelper } from './modules/slug/helper';\nexport { TreeBuilder } from './modules/tree/builder';\nexport type {\n IBuildOptions,\n IHeightWhereOptions,\n ILeavesOptions,\n INodeWithPath,\n IPrintOptions,\n ITreeNode,\n IWalkAsyncOptions,\n IWalkOptions,\n TNodePredicate,\n TOnVisit,\n TOnVisitAsync,\n} from './modules/tree/common/types';\nexport { TreeWalker } from './modules/tree/walk';\n\n// Pure value/type utilities that already live under the root barrel's `./utilities` re-export -\n// that barrel also carries node-only siblings (module.utility.ts, request.utility.ts), so it\n// cannot itself become a subpath. Named one at a time here instead of widening the barrel: every\n// symbol below is verified free of node builtins/globals.\nexport { BuildInfoRegistry } from './utilities/build-info.utility';\nexport type { IBuildInfo, TBuildInfoRecord } from './utilities/build-info.utility';\nexport { EchoUtility } from './utilities/echo.utility';\nexport { ParseUtility } from './utilities/parse.utility';\nexport { PerformanceUtility } from './utilities/performance.utility';\nexport { PromiseUtility } from './utilities/promise.utility';\nexport { RecordUtility } from './utilities/record.utility';\nexport { FormBodyUtility, RequestBodyErrors } from './utilities/form-body.utility';\nexport { ProjectRootRegistry } from './utilities/project-root.utility';\n\n// `ECDH` is the one crypto algorithm that is browser-pure: it runs over `crypto.subtle`, `btoa` and `atob`. It and its\n// base class come by leaf path, never the algorithms barrel, which also carries `AES` and `RSA`\n// (server code: they use `Buffer`, and `AES` reads files with `node:fs`).\nexport { AbstractCryptoAlgorithm } from './modules/crypto/algorithms/abstract.algorithm';\nexport { ECDH } from './modules/crypto/algorithms/ecdh.algorithm';\nexport type {\n ECDHAlgorithmType,\n IECDHEncryptedPayload,\n IECDHExtraOptions,\n} from './modules/crypto/algorithms/ecdh.algorithm';\n\n// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even\n// though the concrete classes they describe (the other crypto algorithms, the ioredis-backed helper) are not\n// themselves part of this pure surface.\nexport { AESAlgorithms } from './modules/crypto/algorithms/aes.constants';\nexport type { AESAlgorithmType } from './modules/crypto/algorithms/aes.constants';\nexport type { IRedisHelper } from './modules/redis/common/interfaces';\n"]}
|
|
@@ -11,18 +11,19 @@ export declare abstract class BaseStorageHelper extends BaseHelper implements IS
|
|
|
11
11
|
getMimeType(opts: {
|
|
12
12
|
filename: string;
|
|
13
13
|
}): string;
|
|
14
|
-
/** One path segment or file name: no separator, no traversal, no control or shell character. */
|
|
14
|
+
/** One path segment or file name: at most 255 UTF-8 bytes, no separator, no traversal, no control or shell character. */
|
|
15
15
|
isValidSegment(opts: {
|
|
16
16
|
segment: string;
|
|
17
17
|
}): boolean;
|
|
18
18
|
static readonly DEFAULT_MAX_FOLDER_DEPTH = 2;
|
|
19
|
+
private static readonly UTF8;
|
|
19
20
|
/** Control characters, lone surrogates, the line and paragraph separators (U+2028, U+2029) and the bidirectional marks and overrides: never part of a file name or a key (the overrides make `gpj.exe` display as `exe.jpg`), and a control character or a surrogate cannot be encoded into a header. */
|
|
20
21
|
private static readonly UNSAFE_NAME_CHARACTERS;
|
|
21
22
|
/** A bucket name is one segment; a separator in it would silently address a different bucket. */
|
|
22
23
|
isValidBucketName(opts: {
|
|
23
24
|
bucket: IBucketRef;
|
|
24
25
|
}): boolean;
|
|
25
|
-
/** A whole object key: every segment valid, and no deeper than `maxDepth` folders. */
|
|
26
|
+
/** A whole object key: every segment valid, no trailing `/`, and no deeper than `maxDepth` folders. */
|
|
26
27
|
isValidObjectKey(opts: {
|
|
27
28
|
object: IObjectRef;
|
|
28
29
|
maxDepth?: number;
|
|
@@ -2,6 +2,7 @@ import { ObjectUtility } from '@venizia/ignis-inversion';
|
|
|
2
2
|
import { ContentTypeTable, MimeTypes } from '../../common/index.js';
|
|
3
3
|
import { BaseHelper } from '../base.js';
|
|
4
4
|
import { getError } from '../error/index.js';
|
|
5
|
+
import { EchoUtility } from '../../utilities/echo.utility.js';
|
|
5
6
|
import { PromiseUtility } from '../../utilities/promise.utility.js';
|
|
6
7
|
import { Readable } from 'node:stream';
|
|
7
8
|
import { StorageUtility, StorageConcurrency, StorageErrors } from './common/index.js';
|
|
@@ -13,11 +14,13 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
13
14
|
getMimeType(opts) {
|
|
14
15
|
return ContentTypeTable.resolve(opts);
|
|
15
16
|
}
|
|
16
|
-
/** One path segment or file name: no separator, no traversal, no control or shell character. */
|
|
17
|
+
/** One path segment or file name: at most 255 UTF-8 bytes, no separator, no traversal, no control or shell character. */
|
|
17
18
|
isValidSegment(opts) {
|
|
18
19
|
const name = opts.segment;
|
|
19
20
|
if (typeof name !== 'string') {
|
|
20
|
-
this.logger
|
|
21
|
+
this.logger
|
|
22
|
+
.for(this.isValidSegment.name)
|
|
23
|
+
.error('Invalid name provided: %s', EchoUtility.toSafeEcho({ value: name }));
|
|
21
24
|
return false;
|
|
22
25
|
}
|
|
23
26
|
if (!name || ObjectUtility.isEmpty({ value: name })) {
|
|
@@ -27,18 +30,20 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
27
30
|
if (name.includes('..') || name.includes('/') || name.includes('\\')) {
|
|
28
31
|
this.logger
|
|
29
32
|
.for(this.isValidSegment.name)
|
|
30
|
-
.error('Name contains invalid path characters: %s', name);
|
|
33
|
+
.error('Name contains invalid path characters: %s', EchoUtility.toSafeEcho({ value: name }));
|
|
31
34
|
return false;
|
|
32
35
|
}
|
|
33
36
|
if (name.startsWith('.')) {
|
|
34
|
-
this.logger
|
|
37
|
+
this.logger
|
|
38
|
+
.for(this.isValidSegment.name)
|
|
39
|
+
.error('Name cannot start with a dot: %s', EchoUtility.toSafeEcho({ value: name }));
|
|
35
40
|
return false;
|
|
36
41
|
}
|
|
37
42
|
const dangerousChars = /[;|&$`<>{}[\]!#]/;
|
|
38
43
|
if (dangerousChars.test(name)) {
|
|
39
44
|
this.logger
|
|
40
45
|
.for(this.isValidSegment.name)
|
|
41
|
-
.error('Name contains dangerous characters: %s', name);
|
|
46
|
+
.error('Name contains dangerous characters: %s', EchoUtility.toSafeEcho({ value: name }));
|
|
42
47
|
return false;
|
|
43
48
|
}
|
|
44
49
|
if (BaseStorageHelper.UNSAFE_NAME_CHARACTERS.test(name)) {
|
|
@@ -48,30 +53,39 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
48
53
|
.error('Name contains a control or bidirectional character | length: %d', name.length);
|
|
49
54
|
return false;
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
const byteLength = BaseStorageHelper.UTF8.encode(name).byteLength;
|
|
57
|
+
if (byteLength > 255) {
|
|
52
58
|
this.logger
|
|
53
59
|
.for(this.isValidSegment.name)
|
|
54
|
-
.error('Name is too long (%d
|
|
60
|
+
.error('Name is too long (%d bytes): %s', byteLength, EchoUtility.toSafeEcho({ value: name }));
|
|
55
61
|
return false;
|
|
56
62
|
}
|
|
57
63
|
if (name.trim().length === 0) {
|
|
58
64
|
this.logger
|
|
59
65
|
.for(this.isValidSegment.name)
|
|
60
|
-
.error('Name cannot be empty or whitespace only:
|
|
66
|
+
.error('Name cannot be empty or whitespace only: %s', EchoUtility.toSafeEcho({ value: name }));
|
|
61
67
|
return false;
|
|
62
68
|
}
|
|
63
69
|
return true;
|
|
64
70
|
}
|
|
65
71
|
static { this.DEFAULT_MAX_FOLDER_DEPTH = 2; }
|
|
72
|
+
static { this.UTF8 = new TextEncoder(); }
|
|
66
73
|
/** Control characters, lone surrogates, the line and paragraph separators (U+2028, U+2029) and the bidirectional marks and overrides: never part of a file name or a key (the overrides make `gpj.exe` display as `exe.jpg`), and a control character or a surrogate cannot be encoded into a header. */
|
|
67
74
|
static { this.UNSAFE_NAME_CHARACTERS = /[\p{Cc}\p{Cs}\u061C\u200E\u200F\u2028\u2029\u202A-\u202E\u2066-\u2069]/u; }
|
|
68
75
|
/** A bucket name is one segment; a separator in it would silently address a different bucket. */
|
|
69
76
|
isValidBucketName(opts) {
|
|
70
77
|
return this.isValidSegment({ segment: opts.bucket.name });
|
|
71
78
|
}
|
|
72
|
-
/** A whole object key: every segment valid, and no deeper than `maxDepth` folders. */
|
|
79
|
+
/** A whole object key: every segment valid, no trailing `/`, and no deeper than `maxDepth` folders. */
|
|
73
80
|
isValidObjectKey(opts) {
|
|
74
|
-
|
|
81
|
+
const { key } = opts.object;
|
|
82
|
+
if (typeof key === 'string' && key.endsWith('/')) {
|
|
83
|
+
this.logger
|
|
84
|
+
.for(this.isValidObjectKey.name)
|
|
85
|
+
.error('Object key ends with a slash: %s', EchoUtility.toSafeEcho({ value: key }));
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return this.isValidKeyPath({ path: key, maxDepth: opts.maxDepth });
|
|
75
89
|
}
|
|
76
90
|
/** The shared rule behind `isValidObjectKey` and the folder check inside `upload`. */
|
|
77
91
|
isValidKeyPath(opts) {
|
|
@@ -92,7 +106,7 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
92
106
|
if (segments.some((s) => s.length === 0)) {
|
|
93
107
|
this.logger
|
|
94
108
|
.for(this.isValidKeyPath.name)
|
|
95
|
-
.error('Path contains empty segments (double slashes): %s', pathStr);
|
|
109
|
+
.error('Path contains empty segments (double slashes): %s', EchoUtility.toSafeEcho({ value: pathStr }));
|
|
96
110
|
return false;
|
|
97
111
|
}
|
|
98
112
|
// segments include the filename, so depth is one less.
|
|
@@ -100,21 +114,22 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
100
114
|
if (folderDepth > maxDepth) {
|
|
101
115
|
this.logger
|
|
102
116
|
.for(this.isValidKeyPath.name)
|
|
103
|
-
.error('Path exceeds max folder depth (%d): %s (depth: %d)', maxDepth, pathStr, folderDepth);
|
|
117
|
+
.error('Path exceeds max folder depth (%d): %s (depth: %d)', maxDepth, EchoUtility.toSafeEcho({ value: pathStr }), folderDepth);
|
|
104
118
|
return false;
|
|
105
119
|
}
|
|
106
120
|
for (const segment of segments) {
|
|
107
121
|
if (!this.isValidSegment({ segment })) {
|
|
108
122
|
this.logger
|
|
109
123
|
.for(this.isValidKeyPath.name)
|
|
110
|
-
.error('Path segment failed validation: %s (in path: %s)', segment, pathStr);
|
|
124
|
+
.error('Path segment failed validation: %s (in path: %s)', EchoUtility.toSafeEcho({ value: segment }), EchoUtility.toSafeEcho({ value: pathStr }));
|
|
111
125
|
return false;
|
|
112
126
|
}
|
|
113
127
|
}
|
|
114
|
-
|
|
128
|
+
const byteLength = BaseStorageHelper.UTF8.encode(normalized).byteLength;
|
|
129
|
+
if (byteLength > 1024) {
|
|
115
130
|
this.logger
|
|
116
131
|
.for(this.isValidKeyPath.name)
|
|
117
|
-
.error('Path is too long (%d
|
|
132
|
+
.error('Path is too long (%d bytes): %s', byteLength, EchoUtility.toSafeEcho({ value: pathStr }));
|
|
118
133
|
return false;
|
|
119
134
|
}
|
|
120
135
|
return true;
|
|
@@ -152,13 +167,15 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
152
167
|
isValidOriginalName(opts) {
|
|
153
168
|
const { name } = opts;
|
|
154
169
|
if (typeof name !== 'string' || name.trim().length === 0 || name.length > 255) {
|
|
155
|
-
this.logger
|
|
170
|
+
this.logger
|
|
171
|
+
.for(this.isValidOriginalName.name)
|
|
172
|
+
.error('Invalid original name: %s', EchoUtility.toSafeEcho({ value: name }));
|
|
156
173
|
return false;
|
|
157
174
|
}
|
|
158
175
|
if (BaseStorageHelper.UNSAFE_NAME_CHARACTERS.test(name)) {
|
|
159
176
|
this.logger
|
|
160
177
|
.for(this.isValidOriginalName.name)
|
|
161
|
-
.error('Original name contains a control character or a lone surrogate: %
|
|
178
|
+
.error('Original name contains a control character or a lone surrogate: %s', EchoUtility.toSafeEcho({ value: name }));
|
|
162
179
|
return false;
|
|
163
180
|
}
|
|
164
181
|
return true;
|
|
@@ -206,7 +223,7 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
206
223
|
const isExists = await this.hasBucket({ bucket });
|
|
207
224
|
if (!isExists) {
|
|
208
225
|
throw getError({
|
|
209
|
-
message: `[upload] Bucket does not exist | name: ${bucket.name}`,
|
|
226
|
+
message: `[upload] Bucket does not exist | name: ${EchoUtility.toSafeText({ value: bucket.name })}`,
|
|
210
227
|
});
|
|
211
228
|
}
|
|
212
229
|
this.validateUploadFiles({
|
|
@@ -225,7 +242,7 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
225
242
|
: this.normalizeObjectName({ file: naming });
|
|
226
243
|
if (!this.isValidObjectKey({ object: { key }, maxDepth: maxFolderDepth })) {
|
|
227
244
|
throw getError({
|
|
228
|
-
message: `[upload] Invalid normalized object name | name: ${key}`,
|
|
245
|
+
message: `[upload] Invalid normalized object name | name: ${EchoUtility.toSafeText({ value: key })}`,
|
|
229
246
|
});
|
|
230
247
|
}
|
|
231
248
|
return key;
|
|
@@ -243,7 +260,7 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
243
260
|
await this.writeObject({ bucket, object, file });
|
|
244
261
|
this.logger
|
|
245
262
|
.for(this.upload.name)
|
|
246
|
-
.info('Uploaded: %
|
|
263
|
+
.info('Uploaded: %s | Took: %s (ms)', EchoUtility.toSafeEcho({ value: { key, link, mimeType, encoding, size } }), performance.now() - t);
|
|
247
264
|
return {
|
|
248
265
|
bucket: { name: bucket.name },
|
|
249
266
|
object: { key, size, contentType: mimeType },
|
|
@@ -305,16 +322,20 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
305
322
|
const { bucket, object, source, contentType } = opts;
|
|
306
323
|
// The same depth rule `upload` applies, as `BunS3Helper.writeStream` does: one object, two doors, one answer.
|
|
307
324
|
if (!this.isValidObjectKey({ object, maxDepth: opts.maxFolderDepth })) {
|
|
308
|
-
throw getError({
|
|
325
|
+
throw getError({
|
|
326
|
+
message: `[writeStream] Invalid object name | key: ${EchoUtility.toSafeText({ value: object.key })}`,
|
|
327
|
+
});
|
|
309
328
|
}
|
|
310
329
|
if (!this.isValidBucketName({ bucket })) {
|
|
311
|
-
throw getError({
|
|
330
|
+
throw getError({
|
|
331
|
+
message: `[storage] Invalid bucket name | bucket: ${EchoUtility.toSafeText({ value: bucket.name })}`,
|
|
332
|
+
});
|
|
312
333
|
}
|
|
313
334
|
// As `upload` does: a write never creates the bucket.
|
|
314
335
|
const result2 = await this.hasBucket({ bucket });
|
|
315
336
|
if (!result2) {
|
|
316
337
|
throw getError({
|
|
317
|
-
message: `[writeStream] Bucket does not exist | name: ${bucket.name}`,
|
|
338
|
+
message: `[writeStream] Bucket does not exist | name: ${EchoUtility.toSafeText({ value: bucket.name })}`,
|
|
318
339
|
});
|
|
319
340
|
}
|
|
320
341
|
const body = source instanceof Response || source instanceof Request ? source : new Response(source);
|
|
@@ -350,7 +371,7 @@ export class BaseStorageHelper extends BaseHelper {
|
|
|
350
371
|
}
|
|
351
372
|
return getError({
|
|
352
373
|
error: StorageErrors.OBJECT_NOT_FOUND,
|
|
353
|
-
message: `[${operation}] Object not found | bucket: ${bucket.name} | key: ${object.key}`,
|
|
374
|
+
message: `[${operation}] Object not found | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | key: ${EchoUtility.toSafeText({ value: object.key })}`,
|
|
354
375
|
});
|
|
355
376
|
}
|
|
356
377
|
// No transport for these: throwing beats returning undefined, which reads as a valid empty result.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/modules/storage/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAkB,SAAS,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAevC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE7E,+IAA+I;AAC/I,MAAM,OAAgB,iBAAkB,SAAQ,UAAU;IACxD,YAAY,IAA2C;QACrD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED,WAAW,CAAC,IAA0B;QACpC,OAAO,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,gGAAgG;IAChG,cAAc,CAAC,IAAyB;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QAE1B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC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U,CACd,KAKC;QAED,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,kEAAkE;SACrG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CACd,KAAgF;QAEhF,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,kEAAkE;SACrG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAAsB;QACxC,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,gEAAgE;SACnG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,KAAyD;QAEzD,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,oEAAoE;SACvG,CAAC,CAAC;IACL,CAAC","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-inversion';\nimport { ContentTypeTable, type IDuration, MimeTypes } from '@/common';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { Readable } from 'node:stream';\nimport {\n type IBucketInfo,\n type IBucketRef,\n type IFileStat,\n type IListObjectsOptions,\n type IObjectInfo,\n type IObjectLocation,\n type IPostPolicy,\n type IObjectRef,\n type IStorageHelper,\n type IUploadFile,\n type IUploadResult,\n type TUploadNaming,\n} from './common';\nimport { StorageUtility, StorageConcurrency, StorageErrors } from './common';\n\n/** Shared base for storage helpers: MIME lookup, name and path validation, and upload naming. Concrete helpers implement the backend calls. */\nexport abstract class BaseStorageHelper extends BaseHelper implements IStorageHelper {\n constructor(opts: { scope: string; identifier: string }) {\n super(opts);\n }\n\n getMimeType(opts: { filename: string }): string {\n return ContentTypeTable.resolve(opts);\n }\n\n /** One path segment or file name: no separator, no traversal, no control or shell character. */\n isValidSegment(opts: { segment: string }): boolean {\n const name = opts.segment;\n\n if (typeof name !== 'string') {\n this.logger.for(this.isValidSegment.name).error('Invalid name provided: %j', name);\n\n return false;\n }\n\n if (!name || ObjectUtility.isEmpty({ value: name })) {\n this.logger.for(this.isValidSegment.name).error('Empty name provided');\n\n return false;\n }\n\n if (name.includes('..') || name.includes('/') || name.includes('\\\\')) {\n this.logger\n .for(this.isValidSegment.name)\n .error('Name contains invalid path characters: %s', name);\n\n return false;\n }\n\n if (name.startsWith('.')) {\n this.logger.for(this.isValidSegment.name).error('Name cannot start with a dot: %s', name);\n\n return false;\n }\n\n const dangerousChars = /[;|&$`<>{}[\\]!#]/;\n\n if (dangerousChars.test(name)) {\n this.logger\n .for(this.isValidSegment.name)\n .error('Name contains dangerous characters: %s', name);\n\n return false;\n }\n\n if (BaseStorageHelper.UNSAFE_NAME_CHARACTERS.test(name)) {\n // The length, not the name: a control character in a log line is the line's own to forge.\n this.logger\n .for(this.isValidSegment.name)\n .error('Name contains a control or bidirectional character | length: %d', name.length);\n\n return false;\n }\n\n if (name.length > 255) {\n this.logger\n .for(this.isValidSegment.name)\n .error('Name is too long (%d characters): %s', name.length, name);\n\n return false;\n }\n\n if (name.trim().length === 0) {\n this.logger\n .for(this.isValidSegment.name)\n .error('Name cannot be empty or whitespace only: \"%s\"', name);\n\n return false;\n }\n\n return true;\n }\n\n static readonly DEFAULT_MAX_FOLDER_DEPTH = 2;\n\n /** Control characters, lone surrogates, the line and paragraph separators (U+2028, U+2029) and the bidirectional marks and overrides: never part of a file name or a key (the overrides make `gpj.exe` display as `exe.jpg`), and a control character or a surrogate cannot be encoded into a header. */\n private static readonly UNSAFE_NAME_CHARACTERS =\n /[\\p{Cc}\\p{Cs}\\u061C\\u200E\\u200F\\u2028\\u2029\\u202A-\\u202E\\u2066-\\u2069]/u;\n\n /** A bucket name is one segment; a separator in it would silently address a different bucket. */\n isValidBucketName(opts: { bucket: IBucketRef }): boolean {\n return this.isValidSegment({ segment: opts.bucket.name });\n }\n\n /** A whole object key: every segment valid, and no deeper than `maxDepth` folders. */\n isValidObjectKey(opts: { object: IObjectRef; maxDepth?: number }): boolean {\n return this.isValidKeyPath({ path: opts.object.key, maxDepth: opts.maxDepth });\n }\n\n /** The shared rule behind `isValidObjectKey` and the folder check inside `upload`. */\n protected isValidKeyPath(opts: { path: string; maxDepth?: number }): boolean {\n const { path: pathStr } = opts;\n const maxDepth = opts.maxDepth ?? BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH;\n\n if (typeof pathStr !== 'string' || !pathStr || ObjectUtility.isEmpty({ value: pathStr })) {\n this.logger.for(this.isValidKeyPath.name).error('Empty or invalid path provided');\n\n return false;\n }\n\n const normalized = pathStr.replace(/^\\/+|\\/+$/g, '');\n\n if (!normalized) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error('Path resolved to empty after trimming slashes');\n\n return false;\n }\n\n const segments = normalized.split('/');\n\n if (segments.some((s) => s.length === 0)) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error('Path contains empty segments (double slashes): %s', pathStr);\n\n return false;\n }\n\n // segments include the filename, so depth is one less.\n const folderDepth = segments.length - 1;\n\n if (folderDepth > maxDepth) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error(\n 'Path exceeds max folder depth (%d): %s (depth: %d)',\n maxDepth,\n pathStr,\n folderDepth,\n );\n\n return false;\n }\n\n for (const segment of segments) {\n if (!this.isValidSegment({ segment })) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error('Path segment failed validation: %s (in path: %s)', segment, pathStr);\n\n return false;\n }\n }\n\n if (normalized.length > 1024) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error('Path is too long (%d characters): %s', normalized.length, pathStr);\n\n return false;\n }\n\n return true;\n }\n\n getMediaType(opts: { mimeType: string }): string {\n const { mimeType } = opts;\n\n if (mimeType?.toLowerCase()?.startsWith(MimeTypes.IMAGE)) {\n return MimeTypes.IMAGE;\n }\n\n if (mimeType?.toLowerCase()?.startsWith(MimeTypes.VIDEO)) {\n return MimeTypes.VIDEO;\n }\n\n if (mimeType?.toLowerCase()?.startsWith(MimeTypes.TEXT)) {\n return MimeTypes.TEXT;\n }\n\n return MimeTypes.UNKNOWN;\n }\n\n /** Public URL prefix; keeps its trailing slash. */\n protected abstract get defaultLinkPrefix(): string;\n\n /** Backend write step; owns its metadata and error handling. */\n protected abstract writeObject(opts: IObjectLocation & { file: IUploadFile }): Promise<void>;\n\n protected normalizeObjectName(opts: { file: TUploadNaming }): string {\n const { originalName, folderPath } = opts.file;\n const normalizedFileName = originalName.toLowerCase().replace(/ /g, '_');\n\n if (!folderPath) {\n return normalizedFileName;\n }\n\n return `${folderPath.toLowerCase().replace(/ /g, '_')}/${normalizedFileName}`;\n }\n\n protected normalizeObjectLink(opts: IObjectLocation): string {\n const bucketName = opts.bucket.name;\n const encodedName = opts.object.key\n .split('/')\n .map((segment) => encodeURIComponent(segment))\n .join('/');\n\n return `${this.defaultLinkPrefix}${bucketName}/${encodedName}`;\n }\n\n /** An original name that is only metadata - the key is resolved elsewhere and validated on its own. */\n protected isValidOriginalName(opts: { name: string }): boolean {\n const { name } = opts;\n\n if (typeof name !== 'string' || name.trim().length === 0 || name.length > 255) {\n this.logger.for(this.isValidOriginalName.name).error('Invalid original name: %j', name);\n\n return false;\n }\n\n if (BaseStorageHelper.UNSAFE_NAME_CHARACTERS.test(name)) {\n this.logger\n .for(this.isValidOriginalName.name)\n .error('Original name contains a control character or a lone surrogate: %j', name);\n\n return false;\n }\n\n return true;\n }\n\n /** `isKeyResolvedByCaller`: a `normalizeNameFn` decides the key, so the original name is metadata and meets the metadata rule, not the key rule. */\n protected validateUploadFiles(opts: {\n files: IUploadFile[];\n maxFolderDepth?: number;\n isKeyResolvedByCaller?: boolean;\n }): void {\n const { files, maxFolderDepth, isKeyResolvedByCaller = false } = opts;\n\n for (const file of files) {\n this.validateUploadFile({ file, maxFolderDepth, isKeyResolvedByCaller });\n }\n }\n\n private validateUploadFile(opts: {\n file: IUploadFile;\n maxFolderDepth?: number;\n isKeyResolvedByCaller: boolean;\n }): void {\n const { file, maxFolderDepth, isKeyResolvedByCaller } = opts;\n const { originalName, size, folderPath } = file;\n\n const isNameValid = isKeyResolvedByCaller\n ? this.isValidOriginalName({ name: originalName })\n : this.isValidSegment({ segment: originalName });\n\n if (!isNameValid) {\n throw getError({ message: '[upload] Invalid original file name' });\n }\n\n // Checked against the CALLER's depth, before the body is spooled. `isValidKeyPath` measures an\n // object path (one folder deeper than a bare folderPath), so the depth is checked directly.\n if (folderPath) {\n const depthLimit = maxFolderDepth ?? BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH;\n const folderSegments = folderPath.replace(/^\\/+|\\/+$/g, '').split('/');\n\n if (folderSegments.length > depthLimit) {\n throw getError({\n message: `[upload] Invalid folder path | depth: ${folderSegments.length} | max: ${depthLimit}`,\n });\n }\n\n if (!this.isValidKeyPath({ path: folderPath, maxDepth: depthLimit })) {\n throw getError({ message: '[upload] Invalid folder path' });\n }\n }\n\n // Missing or negative is invalid; zero is a legitimate empty file.\n if (size === undefined || size === null || size < 0) {\n throw getError({ message: `[upload] Invalid file size | size: ${size}` });\n }\n }\n\n async upload(opts: {\n bucket: IBucketRef;\n files: IUploadFile[];\n normalizeNameFn?: (opts: { file: TUploadNaming }) => string;\n normalizeLinkFn?: (opts: IObjectLocation) => string;\n /**\n * Folder nesting allowed.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n }): Promise<IUploadResult[]> {\n const { bucket, files, normalizeNameFn, normalizeLinkFn, maxFolderDepth } = opts;\n\n if (!files || files.length === 0) {\n return [];\n }\n\n const isExists = await this.hasBucket({ bucket });\n\n if (!isExists) {\n throw getError({\n message: `[upload] Bucket does not exist | name: ${bucket.name}`,\n });\n }\n\n this.validateUploadFiles({\n files,\n maxFolderDepth,\n isKeyResolvedByCaller: normalizeNameFn !== undefined,\n });\n\n // Every key is resolved and validated before the first write, so one bad key stores nothing.\n const keys = files.map((file) => {\n const naming: TUploadNaming = {\n originalName: file.originalName,\n folderPath: file.folderPath,\n };\n const key = normalizeNameFn\n ? normalizeNameFn({ file: naming })\n : this.normalizeObjectName({ file: naming });\n\n if (!this.isValidObjectKey({ object: { key }, maxDepth: maxFolderDepth })) {\n throw getError({\n message: `[upload] Invalid normalized object name | name: ${key}`,\n });\n }\n\n return key;\n });\n\n return this.mapWithConcurrency({\n items: files,\n task: async ({ item: file, index }) => {\n const { mimetype: mimeType, size, encoding } = file;\n const t = performance.now();\n const key = keys[index];\n\n const object: IObjectRef = { key };\n const link = normalizeLinkFn\n ? normalizeLinkFn({ bucket, object })\n : this.normalizeObjectLink({ bucket, object });\n\n await this.writeObject({ bucket, object, file });\n\n this.logger\n .for(this.upload.name)\n .info(\n 'Uploaded: %j | Took: %s (ms)',\n { key, link, mimeType, encoding, size },\n performance.now() - t,\n );\n\n return {\n bucket: { name: bucket.name },\n object: { key, size, contentType: mimeType },\n link,\n };\n },\n });\n }\n\n /** Correct anywhere; overridden by a backend whose transport is already a web stream. */\n async getObjectStream(\n opts: IObjectLocation & { range?: { start: number; end?: number } },\n ): Promise<ReadableStream<Uint8Array>> {\n const { bucket, object, range } = opts;\n const source = await this.getObject({ bucket, object });\n\n if (!range) {\n return Readable.toWeb(source) as ReadableStream<Uint8Array>;\n }\n\n // No native range here: take the window off the front of the full stream. `pull` rather than\n // `start`, so one chunk is read per demand instead of the whole range landing in memory.\n const { start, end } = range;\n const chunks = source[Symbol.asyncIterator]();\n let offset = 0;\n\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n while (true) {\n const next = await chunks.next();\n\n if (next.done) {\n controller.close();\n\n return;\n }\n\n const bytes = next.value as Uint8Array;\n const chunkEnd = offset + bytes.byteLength;\n const from = Math.max(start - offset, 0);\n const to =\n end === undefined ? bytes.byteLength : Math.min(end + 1 - offset, bytes.byteLength);\n const isWanted = chunkEnd > start && from < to;\n\n if (isWanted) {\n controller.enqueue(bytes.subarray(from, to));\n }\n\n offset = chunkEnd;\n\n if (end !== undefined && offset > end) {\n source.destroy();\n controller.close();\n\n return;\n }\n\n if (isWanted) {\n return;\n }\n }\n },\n\n // Without this a client that aborts leaves the backend stream draining to nowhere.\n cancel() {\n source.destroy();\n },\n });\n }\n\n /**\n * Correct anywhere, and the wrong path to stay on: it buffers, so a backend whose transport takes\n * a stream overrides it. `BunS3Helper` does.\n */\n async writeStream(\n opts: IObjectLocation & {\n source: ReadableStream<Uint8Array> | Blob | Response | Request;\n contentType?: string;\n maxFolderDepth?: number;\n },\n ): Promise<void> {\n const { bucket, object, source, contentType } = opts;\n\n // The same depth rule `upload` applies, as `BunS3Helper.writeStream` does: one object, two doors, one answer.\n if (!this.isValidObjectKey({ object, maxDepth: opts.maxFolderDepth })) {\n throw getError({ message: `[writeStream] Invalid object name | key: ${object.key}` });\n }\n\n if (!this.isValidBucketName({ bucket })) {\n throw getError({ message: `[storage] Invalid bucket name | bucket: ${bucket.name}` });\n }\n\n // As `upload` does: a write never creates the bucket.\n const result2 = await this.hasBucket({ bucket });\n\n if (!result2) {\n throw getError({\n message: `[writeStream] Bucket does not exist | name: ${bucket.name}`,\n });\n }\n\n const body =\n source instanceof Response || source instanceof Request ? source : new Response(source);\n const result = await body.arrayBuffer();\n const buffer = Buffer.from(result);\n\n await this.writeObject({\n bucket,\n object,\n file: {\n originalName: object.key,\n mimetype: contentType ?? this.getMimeType({ filename: object.key }),\n buffer,\n size: buffer.length,\n },\n });\n }\n\n /** Bounded fan-out on the shared limiter; unbounded exhausts sockets and gets rate limited. */\n protected async mapWithConcurrency<Item, Result>(opts: {\n items: Item[];\n limit?: number;\n task: (taskOptions: { item: Item; index: number }) => Promise<Result>;\n }): Promise<Result[]> {\n const { items, task } = opts;\n\n if (items.length === 0) {\n return [];\n }\n\n return PromiseUtility.executeWithLimit({\n limit: Math.max(1, opts.limit ?? StorageConcurrency.DEFAULT_LIMIT),\n tasks: items.map((item, index) => () => task({ item, index })),\n });\n }\n\n /** A \"not there\" failure becomes a catalogued 404; every other failure passes through unchanged. */\n protected asStorageError(opts: IObjectLocation & { error: unknown; operation: string }): unknown {\n const { error, operation, bucket, object } = opts;\n\n if (!StorageUtility.isNotFoundError({ error })) {\n return error;\n }\n\n return getError({\n error: StorageErrors.OBJECT_NOT_FOUND,\n message: `[${operation}] Object not found | bucket: ${bucket.name} | key: ${object.key}`,\n });\n }\n\n // No transport for these: throwing beats returning undefined, which reads as a valid empty result.\n async copyObject(_opts: {\n bucket: IBucketRef;\n source: IObjectRef;\n destination: IObjectRef;\n }): Promise<void> {\n throw getError({\n message: `[${this.constructor.name}.copyObject] Server-side copy is not supported by this helper`,\n });\n }\n\n async presignPost(_opts: {\n bucket: IBucketRef;\n keyPrefix: string;\n maxBytes: number;\n contentType?: string;\n expiresIn?: IDuration;\n }): Promise<IPostPolicy> {\n throw getError({\n message: `[${this.constructor.name}.presignPost] Signed POST policies are not supported by this helper`,\n });\n }\n\n async presignPut(\n _opts: IObjectLocation & {\n expiresIn?: IDuration;\n tagging?: Record<string, string>;\n contentLength?: number;\n contentType?: string;\n },\n ): Promise<string> {\n throw getError({\n message: `[${this.constructor.name}.presignPut] Presigned PUT URLs are not supported by this helper`,\n });\n }\n\n async presignGet(\n _opts: IObjectLocation & { expiresIn?: IDuration; responseContentType?: string },\n ): Promise<string> {\n throw getError({\n message: `[${this.constructor.name}.presignGet] Presigned GET URLs are not supported by this helper`,\n });\n }\n\n async getObjectTags(_opts: IObjectLocation): Promise<Record<string, string>> {\n throw getError({\n message: `[${this.constructor.name}.getObjectTags] Object tagging is not supported by this helper`,\n });\n }\n\n async replaceObjectTags(\n _opts: IObjectLocation & { tags: Record<string, string> },\n ): Promise<void> {\n throw getError({\n message: `[${this.constructor.name}.replaceObjectTags] Object tagging is not supported by this helper`,\n });\n }\n\n abstract hasBucket(opts: { bucket: IBucketRef }): Promise<boolean>;\n abstract getBuckets(): Promise<IBucketInfo[]>;\n abstract getBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null>;\n abstract createBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null>;\n abstract removeBucket(opts: { bucket: IBucketRef }): Promise<boolean>;\n\n abstract getObject(opts: IObjectLocation & { options?: any }): Promise<Readable>;\n abstract getStat(opts: IObjectLocation): Promise<IFileStat>;\n abstract removeObject(opts: IObjectLocation): Promise<void>;\n abstract removeObjects(opts: { bucket: IBucketRef; objects: IObjectRef[] }): Promise<void>;\n abstract listObjects(opts: IListObjectsOptions): Promise<IObjectInfo[]>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/modules/storage/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAkB,SAAS,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAevC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE7E,+IAA+I;AAC/I,MAAM,OAAgB,iBAAkB,SAAQ,UAAU;IACxD,YAAY,IAA2C;QACrD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED,WAAW,CAAC,IAA0B;QACpC,OAAO,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,yHAAyH;IACzH,cAAc,CAAC,IAAyB;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QAE1B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM;iBACR,GA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C,IAAI,EAAE,CAAC,WAAW,WAAW,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE;SAC/J,CAAC,CAAC;IACL,CAAC;IAED,mGAAmG;IACnG,KAAK,CAAC,UAAU,CAAC,KAIhB;QACC,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,+DAA+D;SAClG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAMjB;QACC,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,qEAAqE;SACxG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CACd,KAKC;QAED,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,kEAAkE;SACrG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CACd,KAAgF;QAEhF,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,kEAAkE;SACrG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAAsB;QACxC,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,gEAAgE;SACnG,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,KAAyD;QAEzD,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,oEAAoE;SACvG,CAAC,CAAC;IACL,CAAC","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-inversion';\nimport { ContentTypeTable, type IDuration, MimeTypes } from '@/common';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { EchoUtility } from '@/utilities/echo.utility';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport { Readable } from 'node:stream';\nimport {\n type IBucketInfo,\n type IBucketRef,\n type IFileStat,\n type IListObjectsOptions,\n type IObjectInfo,\n type IObjectLocation,\n type IPostPolicy,\n type IObjectRef,\n type IStorageHelper,\n type IUploadFile,\n type IUploadResult,\n type TUploadNaming,\n} from './common';\nimport { StorageUtility, StorageConcurrency, StorageErrors } from './common';\n\n/** Shared base for storage helpers: MIME lookup, name and path validation, and upload naming. Concrete helpers implement the backend calls. */\nexport abstract class BaseStorageHelper extends BaseHelper implements IStorageHelper {\n constructor(opts: { scope: string; identifier: string }) {\n super(opts);\n }\n\n getMimeType(opts: { filename: string }): string {\n return ContentTypeTable.resolve(opts);\n }\n\n /** One path segment or file name: at most 255 UTF-8 bytes, no separator, no traversal, no control or shell character. */\n isValidSegment(opts: { segment: string }): boolean {\n const name = opts.segment;\n\n if (typeof name !== 'string') {\n this.logger\n .for(this.isValidSegment.name)\n .error('Invalid name provided: %s', EchoUtility.toSafeEcho({ value: name }));\n\n return false;\n }\n\n if (!name || ObjectUtility.isEmpty({ value: name })) {\n this.logger.for(this.isValidSegment.name).error('Empty name provided');\n\n return false;\n }\n\n if (name.includes('..') || name.includes('/') || name.includes('\\\\')) {\n this.logger\n .for(this.isValidSegment.name)\n .error(\n 'Name contains invalid path characters: %s',\n EchoUtility.toSafeEcho({ value: name }),\n );\n\n return false;\n }\n\n if (name.startsWith('.')) {\n this.logger\n .for(this.isValidSegment.name)\n .error('Name cannot start with a dot: %s', EchoUtility.toSafeEcho({ value: name }));\n\n return false;\n }\n\n const dangerousChars = /[;|&$`<>{}[\\]!#]/;\n\n if (dangerousChars.test(name)) {\n this.logger\n .for(this.isValidSegment.name)\n .error('Name contains dangerous characters: %s', EchoUtility.toSafeEcho({ value: name }));\n\n return false;\n }\n\n if (BaseStorageHelper.UNSAFE_NAME_CHARACTERS.test(name)) {\n // The length, not the name: a control character in a log line is the line's own to forge.\n this.logger\n .for(this.isValidSegment.name)\n .error('Name contains a control or bidirectional character | length: %d', name.length);\n\n return false;\n }\n\n const byteLength = BaseStorageHelper.UTF8.encode(name).byteLength;\n\n if (byteLength > 255) {\n this.logger\n .for(this.isValidSegment.name)\n .error(\n 'Name is too long (%d bytes): %s',\n byteLength,\n EchoUtility.toSafeEcho({ value: name }),\n );\n\n return false;\n }\n\n if (name.trim().length === 0) {\n this.logger\n .for(this.isValidSegment.name)\n .error(\n 'Name cannot be empty or whitespace only: %s',\n EchoUtility.toSafeEcho({ value: name }),\n );\n\n return false;\n }\n\n return true;\n }\n\n static readonly DEFAULT_MAX_FOLDER_DEPTH = 2;\n\n private static readonly UTF8 = new TextEncoder();\n\n /** Control characters, lone surrogates, the line and paragraph separators (U+2028, U+2029) and the bidirectional marks and overrides: never part of a file name or a key (the overrides make `gpj.exe` display as `exe.jpg`), and a control character or a surrogate cannot be encoded into a header. */\n private static readonly UNSAFE_NAME_CHARACTERS =\n /[\\p{Cc}\\p{Cs}\\u061C\\u200E\\u200F\\u2028\\u2029\\u202A-\\u202E\\u2066-\\u2069]/u;\n\n /** A bucket name is one segment; a separator in it would silently address a different bucket. */\n isValidBucketName(opts: { bucket: IBucketRef }): boolean {\n return this.isValidSegment({ segment: opts.bucket.name });\n }\n\n /** A whole object key: every segment valid, no trailing `/`, and no deeper than `maxDepth` folders. */\n isValidObjectKey(opts: { object: IObjectRef; maxDepth?: number }): boolean {\n const { key } = opts.object;\n\n if (typeof key === 'string' && key.endsWith('/')) {\n this.logger\n .for(this.isValidObjectKey.name)\n .error('Object key ends with a slash: %s', EchoUtility.toSafeEcho({ value: key }));\n\n return false;\n }\n\n return this.isValidKeyPath({ path: key, maxDepth: opts.maxDepth });\n }\n\n /** The shared rule behind `isValidObjectKey` and the folder check inside `upload`. */\n protected isValidKeyPath(opts: { path: string; maxDepth?: number }): boolean {\n const { path: pathStr } = opts;\n const maxDepth = opts.maxDepth ?? BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH;\n\n if (typeof pathStr !== 'string' || !pathStr || ObjectUtility.isEmpty({ value: pathStr })) {\n this.logger.for(this.isValidKeyPath.name).error('Empty or invalid path provided');\n\n return false;\n }\n\n const normalized = pathStr.replace(/^\\/+|\\/+$/g, '');\n\n if (!normalized) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error('Path resolved to empty after trimming slashes');\n\n return false;\n }\n\n const segments = normalized.split('/');\n\n if (segments.some((s) => s.length === 0)) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error(\n 'Path contains empty segments (double slashes): %s',\n EchoUtility.toSafeEcho({ value: pathStr }),\n );\n\n return false;\n }\n\n // segments include the filename, so depth is one less.\n const folderDepth = segments.length - 1;\n\n if (folderDepth > maxDepth) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error(\n 'Path exceeds max folder depth (%d): %s (depth: %d)',\n maxDepth,\n EchoUtility.toSafeEcho({ value: pathStr }),\n folderDepth,\n );\n\n return false;\n }\n\n for (const segment of segments) {\n if (!this.isValidSegment({ segment })) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error(\n 'Path segment failed validation: %s (in path: %s)',\n EchoUtility.toSafeEcho({ value: segment }),\n EchoUtility.toSafeEcho({ value: pathStr }),\n );\n\n return false;\n }\n }\n\n const byteLength = BaseStorageHelper.UTF8.encode(normalized).byteLength;\n\n if (byteLength > 1024) {\n this.logger\n .for(this.isValidKeyPath.name)\n .error(\n 'Path is too long (%d bytes): %s',\n byteLength,\n EchoUtility.toSafeEcho({ value: pathStr }),\n );\n\n return false;\n }\n\n return true;\n }\n\n getMediaType(opts: { mimeType: string }): string {\n const { mimeType } = opts;\n\n if (mimeType?.toLowerCase()?.startsWith(MimeTypes.IMAGE)) {\n return MimeTypes.IMAGE;\n }\n\n if (mimeType?.toLowerCase()?.startsWith(MimeTypes.VIDEO)) {\n return MimeTypes.VIDEO;\n }\n\n if (mimeType?.toLowerCase()?.startsWith(MimeTypes.TEXT)) {\n return MimeTypes.TEXT;\n }\n\n return MimeTypes.UNKNOWN;\n }\n\n /** Public URL prefix; keeps its trailing slash. */\n protected abstract get defaultLinkPrefix(): string;\n\n /** Backend write step; owns its metadata and error handling. */\n protected abstract writeObject(opts: IObjectLocation & { file: IUploadFile }): Promise<void>;\n\n protected normalizeObjectName(opts: { file: TUploadNaming }): string {\n const { originalName, folderPath } = opts.file;\n const normalizedFileName = originalName.toLowerCase().replace(/ /g, '_');\n\n if (!folderPath) {\n return normalizedFileName;\n }\n\n return `${folderPath.toLowerCase().replace(/ /g, '_')}/${normalizedFileName}`;\n }\n\n protected normalizeObjectLink(opts: IObjectLocation): string {\n const bucketName = opts.bucket.name;\n const encodedName = opts.object.key\n .split('/')\n .map((segment) => encodeURIComponent(segment))\n .join('/');\n\n return `${this.defaultLinkPrefix}${bucketName}/${encodedName}`;\n }\n\n /** An original name that is only metadata - the key is resolved elsewhere and validated on its own. */\n protected isValidOriginalName(opts: { name: string }): boolean {\n const { name } = opts;\n\n if (typeof name !== 'string' || name.trim().length === 0 || name.length > 255) {\n this.logger\n .for(this.isValidOriginalName.name)\n .error('Invalid original name: %s', EchoUtility.toSafeEcho({ value: name }));\n\n return false;\n }\n\n if (BaseStorageHelper.UNSAFE_NAME_CHARACTERS.test(name)) {\n this.logger\n .for(this.isValidOriginalName.name)\n .error(\n 'Original name contains a control character or a lone surrogate: %s',\n EchoUtility.toSafeEcho({ value: name }),\n );\n\n return false;\n }\n\n return true;\n }\n\n /** `isKeyResolvedByCaller`: a `normalizeNameFn` decides the key, so the original name is metadata and meets the metadata rule, not the key rule. */\n protected validateUploadFiles(opts: {\n files: IUploadFile[];\n maxFolderDepth?: number;\n isKeyResolvedByCaller?: boolean;\n }): void {\n const { files, maxFolderDepth, isKeyResolvedByCaller = false } = opts;\n\n for (const file of files) {\n this.validateUploadFile({ file, maxFolderDepth, isKeyResolvedByCaller });\n }\n }\n\n private validateUploadFile(opts: {\n file: IUploadFile;\n maxFolderDepth?: number;\n isKeyResolvedByCaller: boolean;\n }): void {\n const { file, maxFolderDepth, isKeyResolvedByCaller } = opts;\n const { originalName, size, folderPath } = file;\n\n const isNameValid = isKeyResolvedByCaller\n ? this.isValidOriginalName({ name: originalName })\n : this.isValidSegment({ segment: originalName });\n\n if (!isNameValid) {\n throw getError({ message: '[upload] Invalid original file name' });\n }\n\n // Checked against the CALLER's depth, before the body is spooled. `isValidKeyPath` measures an\n // object path (one folder deeper than a bare folderPath), so the depth is checked directly.\n if (folderPath) {\n const depthLimit = maxFolderDepth ?? BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH;\n const folderSegments = folderPath.replace(/^\\/+|\\/+$/g, '').split('/');\n\n if (folderSegments.length > depthLimit) {\n throw getError({\n message: `[upload] Invalid folder path | depth: ${folderSegments.length} | max: ${depthLimit}`,\n });\n }\n\n if (!this.isValidKeyPath({ path: folderPath, maxDepth: depthLimit })) {\n throw getError({ message: '[upload] Invalid folder path' });\n }\n }\n\n // Missing or negative is invalid; zero is a legitimate empty file.\n if (size === undefined || size === null || size < 0) {\n throw getError({ message: `[upload] Invalid file size | size: ${size}` });\n }\n }\n\n async upload(opts: {\n bucket: IBucketRef;\n files: IUploadFile[];\n normalizeNameFn?: (opts: { file: TUploadNaming }) => string;\n normalizeLinkFn?: (opts: IObjectLocation) => string;\n /**\n * Folder nesting allowed.\n *\n * @default BaseStorageHelper.DEFAULT_MAX_FOLDER_DEPTH\n */\n maxFolderDepth?: number;\n }): Promise<IUploadResult[]> {\n const { bucket, files, normalizeNameFn, normalizeLinkFn, maxFolderDepth } = opts;\n\n if (!files || files.length === 0) {\n return [];\n }\n\n const isExists = await this.hasBucket({ bucket });\n\n if (!isExists) {\n throw getError({\n message: `[upload] Bucket does not exist | name: ${EchoUtility.toSafeText({ value: bucket.name })}`,\n });\n }\n\n this.validateUploadFiles({\n files,\n maxFolderDepth,\n isKeyResolvedByCaller: normalizeNameFn !== undefined,\n });\n\n // Every key is resolved and validated before the first write, so one bad key stores nothing.\n const keys = files.map((file) => {\n const naming: TUploadNaming = {\n originalName: file.originalName,\n folderPath: file.folderPath,\n };\n const key = normalizeNameFn\n ? normalizeNameFn({ file: naming })\n : this.normalizeObjectName({ file: naming });\n\n if (!this.isValidObjectKey({ object: { key }, maxDepth: maxFolderDepth })) {\n throw getError({\n message: `[upload] Invalid normalized object name | name: ${EchoUtility.toSafeText({ value: key })}`,\n });\n }\n\n return key;\n });\n\n return this.mapWithConcurrency({\n items: files,\n task: async ({ item: file, index }) => {\n const { mimetype: mimeType, size, encoding } = file;\n const t = performance.now();\n const key = keys[index];\n\n const object: IObjectRef = { key };\n const link = normalizeLinkFn\n ? normalizeLinkFn({ bucket, object })\n : this.normalizeObjectLink({ bucket, object });\n\n await this.writeObject({ bucket, object, file });\n\n this.logger\n .for(this.upload.name)\n .info(\n 'Uploaded: %s | Took: %s (ms)',\n EchoUtility.toSafeEcho({ value: { key, link, mimeType, encoding, size } }),\n performance.now() - t,\n );\n\n return {\n bucket: { name: bucket.name },\n object: { key, size, contentType: mimeType },\n link,\n };\n },\n });\n }\n\n /** Correct anywhere; overridden by a backend whose transport is already a web stream. */\n async getObjectStream(\n opts: IObjectLocation & { range?: { start: number; end?: number } },\n ): Promise<ReadableStream<Uint8Array>> {\n const { bucket, object, range } = opts;\n const source = await this.getObject({ bucket, object });\n\n if (!range) {\n return Readable.toWeb(source) as ReadableStream<Uint8Array>;\n }\n\n // No native range here: take the window off the front of the full stream. `pull` rather than\n // `start`, so one chunk is read per demand instead of the whole range landing in memory.\n const { start, end } = range;\n const chunks = source[Symbol.asyncIterator]();\n let offset = 0;\n\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n while (true) {\n const next = await chunks.next();\n\n if (next.done) {\n controller.close();\n\n return;\n }\n\n const bytes = next.value as Uint8Array;\n const chunkEnd = offset + bytes.byteLength;\n const from = Math.max(start - offset, 0);\n const to =\n end === undefined ? bytes.byteLength : Math.min(end + 1 - offset, bytes.byteLength);\n const isWanted = chunkEnd > start && from < to;\n\n if (isWanted) {\n controller.enqueue(bytes.subarray(from, to));\n }\n\n offset = chunkEnd;\n\n if (end !== undefined && offset > end) {\n source.destroy();\n controller.close();\n\n return;\n }\n\n if (isWanted) {\n return;\n }\n }\n },\n\n // Without this a client that aborts leaves the backend stream draining to nowhere.\n cancel() {\n source.destroy();\n },\n });\n }\n\n /**\n * Correct anywhere, and the wrong path to stay on: it buffers, so a backend whose transport takes\n * a stream overrides it. `BunS3Helper` does.\n */\n async writeStream(\n opts: IObjectLocation & {\n source: ReadableStream<Uint8Array> | Blob | Response | Request;\n contentType?: string;\n maxFolderDepth?: number;\n },\n ): Promise<void> {\n const { bucket, object, source, contentType } = opts;\n\n // The same depth rule `upload` applies, as `BunS3Helper.writeStream` does: one object, two doors, one answer.\n if (!this.isValidObjectKey({ object, maxDepth: opts.maxFolderDepth })) {\n throw getError({\n message: `[writeStream] Invalid object name | key: ${EchoUtility.toSafeText({ value: object.key })}`,\n });\n }\n\n if (!this.isValidBucketName({ bucket })) {\n throw getError({\n message: `[storage] Invalid bucket name | bucket: ${EchoUtility.toSafeText({ value: bucket.name })}`,\n });\n }\n\n // As `upload` does: a write never creates the bucket.\n const result2 = await this.hasBucket({ bucket });\n\n if (!result2) {\n throw getError({\n message: `[writeStream] Bucket does not exist | name: ${EchoUtility.toSafeText({ value: bucket.name })}`,\n });\n }\n\n const body =\n source instanceof Response || source instanceof Request ? source : new Response(source);\n const result = await body.arrayBuffer();\n const buffer = Buffer.from(result);\n\n await this.writeObject({\n bucket,\n object,\n file: {\n originalName: object.key,\n mimetype: contentType ?? this.getMimeType({ filename: object.key }),\n buffer,\n size: buffer.length,\n },\n });\n }\n\n /** Bounded fan-out on the shared limiter; unbounded exhausts sockets and gets rate limited. */\n protected async mapWithConcurrency<Item, Result>(opts: {\n items: Item[];\n limit?: number;\n task: (taskOptions: { item: Item; index: number }) => Promise<Result>;\n }): Promise<Result[]> {\n const { items, task } = opts;\n\n if (items.length === 0) {\n return [];\n }\n\n return PromiseUtility.executeWithLimit({\n limit: Math.max(1, opts.limit ?? StorageConcurrency.DEFAULT_LIMIT),\n tasks: items.map((item, index) => () => task({ item, index })),\n });\n }\n\n /** A \"not there\" failure becomes a catalogued 404; every other failure passes through unchanged. */\n protected asStorageError(opts: IObjectLocation & { error: unknown; operation: string }): unknown {\n const { error, operation, bucket, object } = opts;\n\n if (!StorageUtility.isNotFoundError({ error })) {\n return error;\n }\n\n return getError({\n error: StorageErrors.OBJECT_NOT_FOUND,\n message: `[${operation}] Object not found | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | key: ${EchoUtility.toSafeText({ value: object.key })}`,\n });\n }\n\n // No transport for these: throwing beats returning undefined, which reads as a valid empty result.\n async copyObject(_opts: {\n bucket: IBucketRef;\n source: IObjectRef;\n destination: IObjectRef;\n }): Promise<void> {\n throw getError({\n message: `[${this.constructor.name}.copyObject] Server-side copy is not supported by this helper`,\n });\n }\n\n async presignPost(_opts: {\n bucket: IBucketRef;\n keyPrefix: string;\n maxBytes: number;\n contentType?: string;\n expiresIn?: IDuration;\n }): Promise<IPostPolicy> {\n throw getError({\n message: `[${this.constructor.name}.presignPost] Signed POST policies are not supported by this helper`,\n });\n }\n\n async presignPut(\n _opts: IObjectLocation & {\n expiresIn?: IDuration;\n tagging?: Record<string, string>;\n contentLength?: number;\n contentType?: string;\n },\n ): Promise<string> {\n throw getError({\n message: `[${this.constructor.name}.presignPut] Presigned PUT URLs are not supported by this helper`,\n });\n }\n\n async presignGet(\n _opts: IObjectLocation & { expiresIn?: IDuration; responseContentType?: string },\n ): Promise<string> {\n throw getError({\n message: `[${this.constructor.name}.presignGet] Presigned GET URLs are not supported by this helper`,\n });\n }\n\n async getObjectTags(_opts: IObjectLocation): Promise<Record<string, string>> {\n throw getError({\n message: `[${this.constructor.name}.getObjectTags] Object tagging is not supported by this helper`,\n });\n }\n\n async replaceObjectTags(\n _opts: IObjectLocation & { tags: Record<string, string> },\n ): Promise<void> {\n throw getError({\n message: `[${this.constructor.name}.replaceObjectTags] Object tagging is not supported by this helper`,\n });\n }\n\n abstract hasBucket(opts: { bucket: IBucketRef }): Promise<boolean>;\n abstract getBuckets(): Promise<IBucketInfo[]>;\n abstract getBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null>;\n abstract createBucket(opts: { bucket: IBucketRef }): Promise<IBucketInfo | null>;\n abstract removeBucket(opts: { bucket: IBucketRef }): Promise<boolean>;\n\n abstract getObject(opts: IObjectLocation & { options?: any }): Promise<Readable>;\n abstract getStat(opts: IObjectLocation): Promise<IFileStat>;\n abstract removeObject(opts: IObjectLocation): Promise<void>;\n abstract removeObjects(opts: { bucket: IBucketRef; objects: IObjectRef[] }): Promise<void>;\n abstract listObjects(opts: IListObjectsOptions): Promise<IObjectInfo[]>;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getError } from '../../error/index.js';
|
|
2
2
|
import { ErrorPrettier } from '../../logger/index.js';
|
|
3
|
+
import { EchoUtility } from '../../../utilities/echo.utility.js';
|
|
3
4
|
import { S3Client } from 'bun';
|
|
4
5
|
import { Readable } from 'node:stream';
|
|
5
6
|
import { BaseStorageHelper } from '../base.js';
|
|
@@ -50,7 +51,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
50
51
|
// The bucket becomes a label of the host, so it must be one: anything else (a dot, a slash, an `@`, a port) would steer the request to another host.
|
|
51
52
|
if (!S3_HOST_LABEL_PATTERN.test(opts.bucket)) {
|
|
52
53
|
throw getError({
|
|
53
|
-
message: `[objectEndpoint] A bucket used in a host must be one lower-case DNS label (a-z, 0-9, hyphen; 1-63 characters) | bucket: '${opts.bucket}'`,
|
|
54
|
+
message: `[objectEndpoint] A bucket used in a host must be one lower-case DNS label (a-z, 0-9, hyphen; 1-63 characters) | bucket: '${EchoUtility.toSafeText({ value: opts.bucket })}'`,
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
const parsed = new URL(host);
|
|
@@ -94,7 +95,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
94
95
|
catch (error) {
|
|
95
96
|
// A missing bucket is the answer; a credentials or network failure is not, and must not vanish.
|
|
96
97
|
if (!StorageUtility.isNotFoundError({ error })) {
|
|
97
|
-
this.logger.warn('[hasBucket] Cannot determine bucket existence - reporting false | bucket: %s | %s', name, ErrorPrettier.format({ error }));
|
|
98
|
+
this.logger.warn('[hasBucket] Cannot determine bucket existence - reporting false | bucket: %s | %s', EchoUtility.toSafeEcho({ value: name }), ErrorPrettier.format({ error }));
|
|
98
99
|
}
|
|
99
100
|
return false;
|
|
100
101
|
}
|
|
@@ -211,7 +212,7 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
211
212
|
const response = await fetch(request.url, { method: 'PUT', headers: request.headers });
|
|
212
213
|
if (!response.ok) {
|
|
213
214
|
throw getError({
|
|
214
|
-
message: `[copyObject] Copy failed | bucket: ${bucket.name} | source: ${source.key} | status: ${response.status}`,
|
|
215
|
+
message: `[copyObject] Copy failed | bucket: ${EchoUtility.toSafeText({ value: bucket.name })} | source: ${EchoUtility.toSafeText({ value: source.key })} | status: ${response.status}`,
|
|
215
216
|
});
|
|
216
217
|
}
|
|
217
218
|
}
|
|
@@ -354,7 +355,9 @@ export class BunS3Helper extends BaseStorageHelper {
|
|
|
354
355
|
const { bucket, object, source, contentType } = opts;
|
|
355
356
|
// The same depth rule `upload` applies: one object, two doors, one answer.
|
|
356
357
|
if (!this.isValidObjectKey({ object, maxDepth: opts.maxFolderDepth })) {
|
|
357
|
-
throw getError({
|
|
358
|
+
throw getError({
|
|
359
|
+
message: `[writeStream] Invalid object name | key: ${EchoUtility.toSafeText({ value: object.key })}`,
|
|
360
|
+
});
|
|
358
361
|
}
|
|
359
362
|
// Bun's `write` takes a Response, not a bare ReadableStream; wrapping streams, never buffers.
|
|
360
363
|
const body = source instanceof ReadableStream ? new Response(source) : source;
|