@lark-apaas/dataloom 0.1.5 → 0.1.6-alpha.20261019103403
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/README.md
CHANGED
|
@@ -338,6 +338,23 @@ Storage 能力以 bucket 为作用域,需要先通过 `from(bucketId)` 获取
|
|
|
338
338
|
const storage = client.storage.from('assets');
|
|
339
339
|
```
|
|
340
340
|
|
|
341
|
+
Storage path arguments use the original object key. Do not pre-encode or decode a
|
|
342
|
+
key before passing it to `upload`, `download`, or `createSignedUrl`; a literal
|
|
343
|
+
sequence such as `%2F` is part of the object key. Both single-file and batch
|
|
344
|
+
signing send keys unchanged in JSON `paths`, rather than in the signing request
|
|
345
|
+
URL. Single-file signing keeps its `{ data: { signedUrl }, error }` return shape;
|
|
346
|
+
an item-level signing failure returns an error, not a successful empty URL. Batch
|
|
347
|
+
item errors are strings and do not guarantee the error codes of the former
|
|
348
|
+
single-file route. Deletion also sends keys in JSON.
|
|
349
|
+
|
|
350
|
+
`file.name` is the original display name, `file_path` is the object key, and
|
|
351
|
+
`download_url` is a URL. For ordinary file uploads, pass the original `File` to
|
|
352
|
+
`uploadFile(file)` and use the returned `download_url` directly. Do not encode or
|
|
353
|
+
decode a returned URL as a whole. `generateDownloadUrlFromFilePath` handles URL
|
|
354
|
+
encoding when a stored attachment key must be converted to a display URL.
|
|
355
|
+
Supported legacy download URLs are parsed back to keys once; their URL query
|
|
356
|
+
and fragment are not part of the key.
|
|
357
|
+
|
|
341
358
|
## `client.storage.from(bucketId)`
|
|
342
359
|
|
|
343
360
|
#### 入参
|
|
@@ -177,7 +177,6 @@ export default class StorageFileApi {
|
|
|
177
177
|
generateDownloadUrlFromFilePath(filePath: string): string;
|
|
178
178
|
protected encodeMetadata(metadata: Record<string, unknown>): string;
|
|
179
179
|
toBase64(data: string): string;
|
|
180
|
-
private _getFinalPath;
|
|
181
180
|
private _removeEmptyFolders;
|
|
182
181
|
private _isValidDownloadUrl;
|
|
183
182
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageFileApi.d.ts","sourceRoot":"","sources":["../../../src/storage/packages/StorageFileApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAEb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,KAAK,EAA0B,MAAM,eAAe,CAAC;AASnE,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,EAElB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACf,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"StorageFileApi.d.ts","sourceRoot":"","sources":["../../../src/storage/packages/StorageFileApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAEb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,KAAK,EAA0B,MAAM,eAAe,CAAC;AASnE,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,EAElB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACf,MAAM,eAAe,CAAC;AAsDvB,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAClC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;gBAG7D,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;QAAE,CAAC,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IAuDD;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAClC;QACE,IAAI,EAAE,UAAU,EAAE,CAAC;QACnB,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IAoCD;;;;OAIG;IACG,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CACrC;QACE,IAAI,EAAE,cAAc,CAAC;QACrB,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IA6FD;;;;OAIG;IACG,IAAI,CACR,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,aAAa,EACvB,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CACN;QACE,IAAI,EAAE,UAAU,EAAE,CAAC;QACnB,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IAwCD,+BAA+B,CAAC,QAAQ,EAAE,MAAM;IAMhD,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI1D,QAAQ,CAAC,IAAI,EAAE,MAAM;IAOrB,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,mBAAmB;IAM3B;;;;OAIG;IACH,OAAO,CAAC,gCAAgC;IAwBxC;;OAEG;YACW,qBAAqB;CAuBpC"}
|
|
@@ -112,18 +112,33 @@ class StorageFileApi {
|
|
|
112
112
|
}
|
|
113
113
|
async createSignedUrl(path, expiresIn, _options) {
|
|
114
114
|
try {
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
const rawPath = this._retrieveFilePathFromDownloadUrl(path).replace(/^\/+/, '');
|
|
116
|
+
const { data, error } = await this.createSignedUrls([
|
|
117
|
+
rawPath
|
|
118
|
+
], expiresIn);
|
|
119
|
+
if (error) return {
|
|
120
|
+
data: null,
|
|
121
|
+
error: error instanceof StorageUnknownError ? new StorageUnknownError('create signed url error', error.originalError) : error
|
|
122
|
+
};
|
|
123
|
+
if (!Array.isArray(data) || 1 !== data.length || !data[0]) throw new StorageError('expected one signed URL result');
|
|
124
|
+
const signed = data[0];
|
|
125
|
+
if (signed.error) {
|
|
126
|
+
this.onRequestError?.({
|
|
127
|
+
status: 200,
|
|
128
|
+
statusText: '',
|
|
129
|
+
code: 200,
|
|
130
|
+
message: signed.error,
|
|
131
|
+
details: '',
|
|
132
|
+
hint: ''
|
|
133
|
+
});
|
|
134
|
+
throw new StorageError(signed.error);
|
|
135
|
+
}
|
|
136
|
+
if (null != signed.path && signed.path !== rawPath) throw new StorageError('signed URL result path does not match the requested path');
|
|
137
|
+
if ('string' != typeof signed.signedUrl || !signed.signedUrl) throw new StorageError('signed URL is empty');
|
|
125
138
|
return {
|
|
126
|
-
data:
|
|
139
|
+
data: {
|
|
140
|
+
signedUrl: signed.signedUrl
|
|
141
|
+
},
|
|
127
142
|
error: null
|
|
128
143
|
};
|
|
129
144
|
} catch (error) {
|
|
@@ -323,10 +338,6 @@ class StorageFileApi {
|
|
|
323
338
|
if ('undefined' != typeof Buffer) return Buffer.from(data).toString('base64');
|
|
324
339
|
return btoa(data);
|
|
325
340
|
}
|
|
326
|
-
_getFinalPath(path) {
|
|
327
|
-
const _path = this._retrieveFilePathFromDownloadUrl(path);
|
|
328
|
-
return `${this.bucketId}/${_path.replace(/^\/+/, '')}`;
|
|
329
|
-
}
|
|
330
341
|
_removeEmptyFolders(path) {
|
|
331
342
|
if (!path) return path;
|
|
332
343
|
return path.replace(/^\/|\/$/g, '').replace(/\/+/g, '/');
|
|
@@ -336,10 +347,11 @@ class StorageFileApi {
|
|
|
336
347
|
}
|
|
337
348
|
_retrieveFilePathFromDownloadUrl(url) {
|
|
338
349
|
if (!this._isValidDownloadUrl(url)) return url;
|
|
350
|
+
const pathname = url.split(/[?#]/, 1)[0];
|
|
339
351
|
const objectPath = '/object/';
|
|
340
|
-
const objectIndex =
|
|
352
|
+
const objectIndex = pathname.indexOf(objectPath);
|
|
341
353
|
if (-1 === objectIndex) return '';
|
|
342
|
-
const afterObject =
|
|
354
|
+
const afterObject = pathname.slice(objectIndex + objectPath.length);
|
|
343
355
|
const bucketEndIndex = afterObject.indexOf('/');
|
|
344
356
|
if (-1 !== bucketEndIndex) {
|
|
345
357
|
const result = afterObject.slice(bucketEndIndex + 1);
|