@milaboratories/pl-drivers 1.5.51 → 1.5.53
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/clients/download.d.ts +4 -2
- package/dist/clients/download.d.ts.map +1 -1
- package/dist/clients/helpers.d.ts +1 -1
- package/dist/clients/helpers.d.ts.map +1 -1
- package/dist/drivers/ls.d.ts +10 -1
- package/dist/drivers/ls.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +453 -436
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/clients/download.ts +14 -5
- package/src/clients/helpers.ts +11 -2
- package/src/drivers/ls.ts +33 -0
- package/src/helpers/download.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-drivers",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.53",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20"
|
|
6
6
|
},
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"tar-fs": "^3.0.8",
|
|
31
31
|
"undici": "~7.5.0",
|
|
32
32
|
"zod": "~3.23.8",
|
|
33
|
-
"@milaboratories/pl-client": "^2.9.0",
|
|
34
|
-
"@milaboratories/computable": "^2.4.7",
|
|
35
|
-
"@milaboratories/pl-model-common": "^1.14.0",
|
|
36
33
|
"@milaboratories/ts-helpers": "^1.2.0",
|
|
37
|
-
"@milaboratories/
|
|
34
|
+
"@milaboratories/computable": "^2.4.7",
|
|
35
|
+
"@milaboratories/pl-client": "^2.9.0",
|
|
36
|
+
"@milaboratories/pl-tree": "^1.6.1",
|
|
37
|
+
"@milaboratories/pl-model-common": "^1.14.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"eslint": "^9.25.1",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
48
|
"@jest/globals": "^29.7.0",
|
|
49
49
|
"ts-jest": "^29.2.6",
|
|
50
|
-
"@milaboratories/
|
|
51
|
-
"@milaboratories/
|
|
50
|
+
"@milaboratories/eslint-config": "^1.0.4",
|
|
51
|
+
"@milaboratories/platforma-build-configs": "1.0.3"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"type-check": "tsc --noEmit --composite false",
|
package/src/clients/download.ts
CHANGED
|
@@ -40,26 +40,35 @@ export class ClientDownload {
|
|
|
40
40
|
|
|
41
41
|
close() {}
|
|
42
42
|
|
|
43
|
+
/** Gets a presign URL and downloads the file.
|
|
44
|
+
* An optional range with 2 numbers from what byte and to what byte to download can be provided. */
|
|
43
45
|
async downloadBlob(
|
|
44
46
|
info: ResourceInfo,
|
|
45
47
|
options?: RpcOptions,
|
|
46
48
|
signal?: AbortSignal,
|
|
49
|
+
fromBytes?: number,
|
|
50
|
+
toBytes?: number,
|
|
47
51
|
): Promise<DownloadResponse> {
|
|
48
52
|
const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, signal);
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
const remoteHeaders = toHeadersMap(headers, fromBytes, toBytes);
|
|
55
|
+
this.logger.info(`download blob from url ${downloadUrl}, headers: ${JSON.stringify(remoteHeaders)}`);
|
|
51
56
|
|
|
52
57
|
return isLocal(downloadUrl)
|
|
53
|
-
? await this.readLocalFile(downloadUrl)
|
|
54
|
-
: await this.remoteFileDownloader.download(downloadUrl,
|
|
58
|
+
? await this.readLocalFile(downloadUrl, fromBytes, toBytes)
|
|
59
|
+
: await this.remoteFileDownloader.download(downloadUrl, remoteHeaders, signal);
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
async readLocalFile(
|
|
62
|
+
async readLocalFile(
|
|
63
|
+
url: string,
|
|
64
|
+
fromBytes?: number,
|
|
65
|
+
toBytes?: number,
|
|
66
|
+
): Promise<DownloadResponse> {
|
|
58
67
|
const { storageId, relativePath } = parseLocalUrl(url);
|
|
59
68
|
const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);
|
|
60
69
|
|
|
61
70
|
return {
|
|
62
|
-
content: Readable.toWeb(fs.createReadStream(fullPath)),
|
|
71
|
+
content: Readable.toWeb(fs.createReadStream(fullPath, { start: fromBytes, end: toBytes })),
|
|
63
72
|
size: (await fsp.stat(fullPath)).size,
|
|
64
73
|
};
|
|
65
74
|
}
|
package/src/clients/helpers.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
export function toHeadersMap(
|
|
2
|
-
|
|
1
|
+
export function toHeadersMap(
|
|
2
|
+
headers: { name: string; value: string }[],
|
|
3
|
+
fromBytes?: number,
|
|
4
|
+
toBytes?: number,
|
|
5
|
+
): Record<string, string> {
|
|
6
|
+
const result = Object.fromEntries(headers.map(({ name, value }) => [name, value]));
|
|
7
|
+
if (fromBytes !== undefined && toBytes !== undefined) {
|
|
8
|
+
result['Range'] = `bytes=${fromBytes}-${toBytes}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return result;
|
|
3
12
|
}
|
package/src/drivers/ls.ts
CHANGED
|
@@ -42,8 +42,19 @@ export interface InternalLsDriver extends sdk.LsDriver {
|
|
|
42
42
|
* To be used in tests and in implementation of the native file selection UI API.
|
|
43
43
|
* */
|
|
44
44
|
getLocalFileHandle(localPath: string): Promise<sdk.LocalImportFileHandle>;
|
|
45
|
+
|
|
46
|
+
listRemoteFilesWithAdditionalInfo(storage: sdk.StorageHandle, fullPath: string): Promise<ListRemoteFilesResultWithAdditionalInfo>;
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
export type ListRemoteFilesResultWithAdditionalInfo = {
|
|
50
|
+
parent?: string;
|
|
51
|
+
entries: LsEntryWithAdditionalInfo[];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type LsEntryWithAdditionalInfo = LsEntry & {
|
|
55
|
+
size: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
47
58
|
export type OpenFileDialogCallback = (
|
|
48
59
|
multipleFiles: boolean,
|
|
49
60
|
ops?: OpenDialogOps
|
|
@@ -231,6 +242,28 @@ export class LsDriver implements InternalLsDriver {
|
|
|
231
242
|
return { entries };
|
|
232
243
|
}
|
|
233
244
|
|
|
245
|
+
public async listRemoteFilesWithAdditionalInfo(
|
|
246
|
+
storageHandle: sdk.StorageHandle,
|
|
247
|
+
fullPath: string,
|
|
248
|
+
): Promise<ListRemoteFilesResultWithAdditionalInfo> {
|
|
249
|
+
const storageData = parseStorageHandle(storageHandle);
|
|
250
|
+
if (!storageData.isRemote) {
|
|
251
|
+
throw new Error(`Storage ${storageData.name} is not remote`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const response = await this.lsClient.list(storageData, fullPath);
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
entries: response.items.map((e) => ({
|
|
258
|
+
type: e.isDir ? 'dir' : 'file',
|
|
259
|
+
name: e.name,
|
|
260
|
+
fullPath: e.fullName,
|
|
261
|
+
handle: createIndexImportHandle(storageData.name, e.fullName),
|
|
262
|
+
size: Number(e.size),
|
|
263
|
+
})),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
234
267
|
public async fileToImportHandle(file: sdk.FileLike): Promise<sdk.ImportFileHandle> {
|
|
235
268
|
throw new Error(
|
|
236
269
|
'Not implemented. This method must be implemented and intercepted in desktop preload script.',
|
package/src/helpers/download.ts
CHANGED
|
@@ -39,7 +39,7 @@ export class RemoteFileDownloader {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
async function checkStatusCodeOk(statusCode: number, webBody: ReadableStream, url: string) {
|
|
42
|
-
if (statusCode != 200) {
|
|
42
|
+
if (statusCode != 200 && statusCode != 206 /* partial content from range request */) {
|
|
43
43
|
const beginning = (await text(webBody)).substring(0, 1000);
|
|
44
44
|
|
|
45
45
|
if (400 <= statusCode && statusCode < 500) {
|