@milaboratories/pl-drivers 1.3.2 → 1.3.4
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 +5 -3
- package/dist/clients/download.d.ts.map +1 -1
- package/dist/clients/progress.d.ts.map +1 -1
- package/dist/clients/upload.d.ts.map +1 -1
- package/dist/drivers/download_and_logs_blob.d.ts.map +1 -1
- package/dist/drivers/download_url.d.ts.map +1 -1
- package/dist/drivers/helpers/helpers.d.ts.map +1 -1
- package/dist/drivers/helpers/test_helpers.d.ts.map +1 -1
- package/dist/drivers/logs.d.ts.map +1 -1
- package/dist/drivers/logs_stream.d.ts.map +1 -1
- package/dist/drivers/ls.d.ts +3 -13
- package/dist/drivers/ls.d.ts.map +1 -1
- package/dist/drivers/types.d.ts +9 -0
- package/dist/drivers/types.d.ts.map +1 -1
- package/dist/drivers/virtual_storages.d.ts +3 -0
- package/dist/drivers/virtual_storages.d.ts.map +1 -0
- package/dist/helpers/download.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +768 -876
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/clients/download.test.ts +9 -5
- package/src/clients/download.ts +5 -8
- package/src/clients/progress.ts +1 -4
- package/src/clients/upload.test.ts +2 -5
- package/src/clients/upload.ts +10 -44
- package/src/drivers/download_and_logs_blob.ts +32 -109
- package/src/drivers/download_blob.test.ts +37 -55
- package/src/drivers/download_url.test.ts +1 -1
- package/src/drivers/download_url.ts +6 -25
- package/src/drivers/helpers/helpers.ts +3 -12
- package/src/drivers/helpers/test_helpers.ts +1 -3
- package/src/drivers/logs.test.ts +27 -65
- package/src/drivers/logs.ts +17 -66
- package/src/drivers/logs_stream.ts +12 -48
- package/src/drivers/ls.test.ts +2 -6
- package/src/drivers/ls.ts +37 -44
- package/src/drivers/types.ts +12 -0
- package/src/drivers/virtual_storages.ts +41 -0
- package/src/helpers/download.ts +2 -4
- package/src/index.ts +1 -0
package/src/drivers/ls.ts
CHANGED
|
@@ -19,11 +19,15 @@ import {
|
|
|
19
19
|
parseIndexHandle,
|
|
20
20
|
parseUploadHandle
|
|
21
21
|
} from './helpers/ls_list_entry';
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
import {
|
|
23
|
+
createLocalStorageHandle,
|
|
24
|
+
createRemoteStorageHandle,
|
|
25
|
+
parseStorageHandle
|
|
26
|
+
} from './helpers/ls_storage_entry';
|
|
27
|
+
import { LocalStorageProjection, VirtualLocalStorageSpec } from './types';
|
|
25
28
|
import { createLsFilesClient } from '../clients/helpers';
|
|
26
29
|
import { validateAbsolute } from '../helpers/validate';
|
|
30
|
+
import { DefaultVirtualLocalStorages } from './virtual_storages';
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
33
|
* Extends public and safe SDK's driver API with methods used internally in the middle
|
|
@@ -42,31 +46,6 @@ export type OpenFileDialogCallback = (
|
|
|
42
46
|
ops?: OpenDialogOps
|
|
43
47
|
) => Promise<undefined | string[]>;
|
|
44
48
|
|
|
45
|
-
/** Allows to add parts of local FS as virtual storages, presenting homogeneous API to UI */
|
|
46
|
-
export type VirtualLocalStorageSpec = {
|
|
47
|
-
/** Virtual storage ID, must not intersect with other storage ids */
|
|
48
|
-
readonly name: string;
|
|
49
|
-
|
|
50
|
-
/** Local path to "chroot" the API in */
|
|
51
|
-
readonly root: string;
|
|
52
|
-
|
|
53
|
-
/** Used as hint to UI controls to, set as initial path during browsing */
|
|
54
|
-
readonly initialPath: string;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export function DefaultVirtualLocalStorages(): VirtualLocalStorageSpec[] {
|
|
58
|
-
const home = os.homedir();
|
|
59
|
-
return path.sep === '/'
|
|
60
|
-
? [{ name: 'local', root: '/', initialPath: home }]
|
|
61
|
-
: [
|
|
62
|
-
{
|
|
63
|
-
name: 'local',
|
|
64
|
-
root: path.parse(home).root, // disk where home directory resides
|
|
65
|
-
initialPath: home
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
49
|
export class LsDriver implements InternalLsDriver {
|
|
71
50
|
private constructor(
|
|
72
51
|
private readonly logger: MiLogger,
|
|
@@ -180,18 +159,28 @@ export class LsDriver implements InternalLsDriver {
|
|
|
180
159
|
}
|
|
181
160
|
|
|
182
161
|
public async getStorageList(): Promise<sdk.StorageEntry[]> {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
162
|
+
const virtualStorages = [...this.virtualStoragesMap.values()].map((s) => ({
|
|
163
|
+
name: s.name,
|
|
164
|
+
handle: createLocalStorageHandle(s.name, s.root),
|
|
165
|
+
initialFullPath: s.initialPath
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
const otherStorages = Object.entries(this.storageIdToResourceId!).map(
|
|
169
|
+
([storageId, resourceId]) => ({
|
|
190
170
|
name: storageId,
|
|
191
171
|
handle: createRemoteStorageHandle(storageId, resourceId),
|
|
192
|
-
initialFullPath: '' // we don't have any additional information from where to start browsing remote storages
|
|
193
|
-
|
|
194
|
-
|
|
172
|
+
initialFullPath: '', // we don't have any additional information from where to start browsing remote storages
|
|
173
|
+
isInitialPathHome: false
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// root must be a storage so we can index any file,
|
|
178
|
+
// but for UI it's enough
|
|
179
|
+
// to have local virtual storage on *nix,
|
|
180
|
+
// and local_disk_${drive} on Windows.
|
|
181
|
+
const noRoot = otherStorages.filter((it) => it.name !== 'root');
|
|
182
|
+
|
|
183
|
+
return [...virtualStorages, ...noRoot];
|
|
195
184
|
}
|
|
196
185
|
|
|
197
186
|
public async listFiles(
|
|
@@ -213,10 +202,12 @@ export class LsDriver implements InternalLsDriver {
|
|
|
213
202
|
} else {
|
|
214
203
|
if (path.sep === '/' && fullPath === '') fullPath = '/';
|
|
215
204
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
205
|
+
if (storageData.rootPath === '') {
|
|
206
|
+
validateAbsolute(fullPath);
|
|
207
|
+
}
|
|
208
|
+
const lsRoot = path.isAbsolute(fullPath)
|
|
209
|
+
? fullPath
|
|
210
|
+
: path.join(storageData.rootPath, fullPath);
|
|
220
211
|
|
|
221
212
|
const entries: LsEntry[] = [];
|
|
222
213
|
for await (const dirent of await fsp.opendir(lsRoot)) {
|
|
@@ -243,13 +234,15 @@ export class LsDriver implements InternalLsDriver {
|
|
|
243
234
|
logger: MiLogger,
|
|
244
235
|
client: PlClient,
|
|
245
236
|
signer: Signer,
|
|
246
|
-
virtualStorages: VirtualLocalStorageSpec[],
|
|
247
237
|
/** Pl storages available locally */
|
|
248
238
|
localProjections: LocalStorageProjection[],
|
|
249
|
-
openFileDialogCallback: OpenFileDialogCallback
|
|
239
|
+
openFileDialogCallback: OpenFileDialogCallback,
|
|
240
|
+
virtualStorages?: VirtualLocalStorageSpec[]
|
|
250
241
|
): Promise<LsDriver> {
|
|
251
242
|
const lsClient = createLsFilesClient(client, logger);
|
|
252
243
|
|
|
244
|
+
if (!virtualStorages) virtualStorages = await DefaultVirtualLocalStorages();
|
|
245
|
+
|
|
253
246
|
// validating inputs
|
|
254
247
|
for (const vp of virtualStorages) validateAbsolute(vp.root);
|
|
255
248
|
for (const lp of localProjections) if (lp.localPath !== '') validateAbsolute(lp.localPath);
|
package/src/drivers/types.ts
CHANGED
|
@@ -39,3 +39,15 @@ export type LocalStorageProjection = {
|
|
|
39
39
|
* */
|
|
40
40
|
readonly localPath: string;
|
|
41
41
|
};
|
|
42
|
+
|
|
43
|
+
/** Allows to add parts of local FS as virtual storages, presenting homogeneous API to UI */
|
|
44
|
+
export type VirtualLocalStorageSpec = {
|
|
45
|
+
/** Virtual storage ID, must not intersect with other storage ids */
|
|
46
|
+
readonly name: string;
|
|
47
|
+
|
|
48
|
+
/** Local path to "chroot" the API in */
|
|
49
|
+
readonly root: string;
|
|
50
|
+
|
|
51
|
+
/** Used as hint to UI controls to, set as initial path during browsing */
|
|
52
|
+
readonly initialPath: string;
|
|
53
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import util from 'util';
|
|
4
|
+
import { exec } from 'child_process';
|
|
5
|
+
import { VirtualLocalStorageSpec } from './types';
|
|
6
|
+
|
|
7
|
+
export async function DefaultVirtualLocalStorages(): Promise<VirtualLocalStorageSpec[]> {
|
|
8
|
+
const home = os.homedir();
|
|
9
|
+
if (path.sep == '/')
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
name: 'local',
|
|
13
|
+
root: '/',
|
|
14
|
+
initialPath: home
|
|
15
|
+
}
|
|
16
|
+
];
|
|
17
|
+
else {
|
|
18
|
+
// determine the drive on which user's home folder is stored
|
|
19
|
+
const homeRoot = path.parse(home).root; // e.g. C:\
|
|
20
|
+
const homeDrive = homeRoot.replaceAll(':\\', ''); // e.g. C drive.
|
|
21
|
+
|
|
22
|
+
// code below inspired by
|
|
23
|
+
// https://stackoverflow.com/a/52411712/769192
|
|
24
|
+
|
|
25
|
+
const wmic = await util.promisify(exec)('wmic logicaldisk get name');
|
|
26
|
+
// parsing wmic output
|
|
27
|
+
const drives = wmic.stdout
|
|
28
|
+
.split('\r\n')
|
|
29
|
+
.filter((line) => line.includes(':'))
|
|
30
|
+
.map((line) => line.trim().replaceAll(':', ''));
|
|
31
|
+
|
|
32
|
+
return drives.map((drive) => {
|
|
33
|
+
const isHomeDrive = drive == homeDrive;
|
|
34
|
+
return {
|
|
35
|
+
name: `local_disk_${drive}`,
|
|
36
|
+
root: `${drive}:\\`,
|
|
37
|
+
initialPath: isHomeDrive ? home : `${drive}:\\`
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/helpers/download.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class DownloadHelper {
|
|
|
28
28
|
const webBody = Readable.toWeb(body);
|
|
29
29
|
|
|
30
30
|
if (statusCode != 200) {
|
|
31
|
-
const textBody = await text(webBody)
|
|
31
|
+
const textBody = await text(webBody);
|
|
32
32
|
const beginning = textBody.substring(0, Math.min(textBody.length, 1000));
|
|
33
33
|
|
|
34
34
|
if (400 <= statusCode && statusCode < 500) {
|
|
@@ -37,9 +37,7 @@ export class DownloadHelper {
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
throw new Error(
|
|
41
|
-
`Http error: statusCode: ${statusCode} url: ${url.toString()}`
|
|
42
|
-
);
|
|
40
|
+
throw new Error(`Http error: statusCode: ${statusCode} url: ${url.toString()}`);
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
return {
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './drivers/logs_stream';
|
|
|
11
11
|
export * from './drivers/logs';
|
|
12
12
|
export * from './drivers/download_url';
|
|
13
13
|
export * from './drivers/ls';
|
|
14
|
+
export * from './drivers/virtual_storages';
|
|
14
15
|
export * from './drivers/helpers/helpers';
|
|
15
16
|
export * from './drivers/helpers/polling_ops';
|
|
16
17
|
|