@milaboratories/pl-drivers 1.6.12 → 1.7.0
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/drivers/download_blob_url/driver.d.ts.map +1 -1
- package/dist/drivers/download_blob_url/url.d.ts +0 -5
- package/dist/drivers/download_blob_url/url.d.ts.map +1 -1
- package/dist/drivers/{download_url.d.ts → download_url/driver.d.ts} +25 -41
- package/dist/drivers/download_url/driver.d.ts.map +1 -0
- package/dist/drivers/download_url/task.d.ts +40 -0
- package/dist/drivers/download_url/task.d.ts.map +1 -0
- package/dist/drivers/urls/url.d.ts +13 -0
- package/dist/drivers/urls/url.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +506 -484
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/drivers/download_blob_url/driver.ts +2 -2
- package/src/drivers/download_blob_url/task.ts +1 -1
- package/src/drivers/download_blob_url/url.ts +0 -43
- package/src/drivers/{download_url.test.ts → download_url/driver.test.ts} +32 -25
- package/src/drivers/{download_url.ts → download_url/driver.ts} +55 -156
- package/src/drivers/download_url/task.ts +151 -0
- package/src/drivers/{download_blob_url → urls}/url.test.ts +26 -3
- package/src/drivers/urls/url.ts +68 -0
- package/src/index.ts +1 -1
- package/dist/drivers/download_url.d.ts.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { describe, test, expect } from 'vitest';
|
|
3
|
-
import {
|
|
3
|
+
import { getPathForBlockUIURL, getPathForFolderURL } from './url';
|
|
4
4
|
import type { Signer } from '@milaboratories/ts-helpers';
|
|
5
5
|
import { HmacSha256Signer } from '@milaboratories/ts-helpers';
|
|
6
|
-
import { FolderURL } from '@milaboratories/pl-model-common';
|
|
6
|
+
import { FolderURL, isFolderURL } from '@milaboratories/pl-model-common';
|
|
7
7
|
|
|
8
8
|
describe('isFolderURL', () => {
|
|
9
9
|
test('should return true for a valid URL', () => {
|
|
@@ -25,7 +25,6 @@ describe('isFolderURL', () => {
|
|
|
25
25
|
describe('getPathForFolderURL', () => {
|
|
26
26
|
const signer: Signer = {
|
|
27
27
|
sign: (data: string | Uint8Array) => 'signature',
|
|
28
|
-
|
|
29
28
|
verify: (data: string | Uint8Array, signature: string, validationErrorMessage?: string) => null,
|
|
30
29
|
};
|
|
31
30
|
|
|
@@ -37,3 +36,27 @@ describe('getPathForFolderURL', () => {
|
|
|
37
36
|
expect(result).toBe(path.join('/test/dir/subfolder_tgz/path/to/resource.html'));
|
|
38
37
|
});
|
|
39
38
|
});
|
|
39
|
+
|
|
40
|
+
describe('getPathForBlockUIURL', () => {
|
|
41
|
+
const signer: Signer = {
|
|
42
|
+
sign: (data: string | Uint8Array) => 'signature',
|
|
43
|
+
verify: (data: string | Uint8Array, signature: string, validationErrorMessage?: string) => null,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
test('should be ok', () => {
|
|
47
|
+
const blockUIURL = 'block-ui://signature.blockUIDir.uidir/path/to/resource.html';
|
|
48
|
+
|
|
49
|
+
const result = getPathForBlockUIURL(signer, blockUIURL, '/test/dir');
|
|
50
|
+
|
|
51
|
+
expect(result).toBe(path.join('/test/dir/blockUIDir/path/to/resource.html'));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** The function should decode url-encoded whitespaces. */
|
|
55
|
+
test('should be ok with whitespaces', () => {
|
|
56
|
+
const blockUIURL = 'block-ui://signature.blockUIDir.uidir/path/to%20whitespaces%20/resource.html';
|
|
57
|
+
|
|
58
|
+
const result = getPathForBlockUIURL(signer, blockUIURL, '/test/dir');
|
|
59
|
+
|
|
60
|
+
expect(result).toBe(path.join('/test/dir/blockUIDir/path/to whitespaces /resource.html'));
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { FolderURL, BlockUIURL } from '@milaboratories/pl-model-common';
|
|
2
|
+
import type { Signer } from '@milaboratories/ts-helpers';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
/** Creates a new plblob+folder URL. */
|
|
6
|
+
export function newFolderURL(signer: Signer, saveDir: string, fPath: string): FolderURL {
|
|
7
|
+
const p = path.relative(saveDir, fPath);
|
|
8
|
+
const sign = signer.sign(p);
|
|
9
|
+
|
|
10
|
+
return `plblob+folder://${sign}.${p}.blob`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Creates a new block-ui URL. */
|
|
14
|
+
export function newBlockUIURL(signer: Signer, saveDir: string, fPath: string): BlockUIURL {
|
|
15
|
+
const p = path.relative(saveDir, fPath);
|
|
16
|
+
const sign = signer.sign(p);
|
|
17
|
+
|
|
18
|
+
return `block-ui://${sign}.${p}.uidir`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Checks the signature and path injections.
|
|
22
|
+
* @returns the path to the file inside the root directory. */
|
|
23
|
+
export function getPathForFolderURL(signer: Signer, url: FolderURL, rootDir: string): string {
|
|
24
|
+
return getPath(signer, url, rootDir);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Checks the signature and path injections.
|
|
28
|
+
* @returns the path to the file inside the root directory. */
|
|
29
|
+
export function getPathForBlockUIURL(signer: Signer, url: BlockUIURL, rootDir: string): string {
|
|
30
|
+
return getPath(signer, url, rootDir);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Parses URL,
|
|
34
|
+
* checks the signature,
|
|
35
|
+
* gets the absolute path by the given root directory.
|
|
36
|
+
* If the path is empty, it returns the index.html file.
|
|
37
|
+
* @returns an absolute path for the user. */
|
|
38
|
+
function getPath(signer: Signer, url: string, rootDir: string): string {
|
|
39
|
+
const parsed = new URL(url);
|
|
40
|
+
const [sign, subfolder, _] = parsed.host.split('.');
|
|
41
|
+
|
|
42
|
+
signer.verify(subfolder, sign, `signature verification failed for url: ${url}, subfolder: ${subfolder}`);
|
|
43
|
+
|
|
44
|
+
// Decoding changes '%20' to ' ' for example.
|
|
45
|
+
const pathname = decodeURIComponent(parsed.pathname.slice(1));
|
|
46
|
+
|
|
47
|
+
let fPath = parseNestedPathNoEscape(path.join(rootDir, `${subfolder}`), pathname);
|
|
48
|
+
|
|
49
|
+
if (parsed.pathname == '' || parsed.pathname == '/') {
|
|
50
|
+
fPath = path.join(fPath, 'index.html');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return path.resolve(fPath);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Checks that the userInputPath is in baseDir.
|
|
57
|
+
* @returns an absolute path for the user. */
|
|
58
|
+
function parseNestedPathNoEscape(baseDir: string, userInputPath: string): string {
|
|
59
|
+
const absolutePath = path.resolve(baseDir, userInputPath);
|
|
60
|
+
|
|
61
|
+
const normalizedBase = path.resolve(baseDir);
|
|
62
|
+
|
|
63
|
+
if (!absolutePath.startsWith(normalizedBase)) {
|
|
64
|
+
throw new Error('Path validation failed.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return absolutePath;
|
|
68
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export * from './drivers/upload';
|
|
|
12
12
|
export * from './drivers/upload_task';
|
|
13
13
|
export * from './drivers/logs_stream';
|
|
14
14
|
export * from './drivers/logs';
|
|
15
|
-
export * from './drivers/download_url';
|
|
15
|
+
export * from './drivers/download_url/driver';
|
|
16
16
|
export * from './drivers/ls';
|
|
17
17
|
export * from './drivers/virtual_storages';
|
|
18
18
|
export * from './drivers/helpers/helpers';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download_url.d.ts","sourceRoot":"","sources":["../../src/drivers/download_url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACtE,O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