@directus/storage-driver-azure 10.0.10 → 10.0.12
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/index.d.ts +7 -6
- package/dist/index.js +68 -62
- package/package.json +8 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Driver, Range } from '@directus/storage';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
|
|
4
|
+
type DriverAzureConfig = {
|
|
5
5
|
containerName: string;
|
|
6
6
|
accountName: string;
|
|
7
7
|
accountKey: string;
|
|
8
8
|
root?: string;
|
|
9
9
|
endpoint?: string;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
declare class DriverAzure implements Driver {
|
|
12
12
|
private containerClient;
|
|
13
13
|
private signedCredentials;
|
|
14
14
|
private root;
|
|
@@ -26,4 +26,5 @@ export declare class DriverAzure implements Driver {
|
|
|
26
26
|
copy(src: string, dest: string): Promise<void>;
|
|
27
27
|
list(prefix?: string): AsyncGenerator<string, void, unknown>;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
export { DriverAzure, DriverAzureConfig, DriverAzure as default };
|
package/dist/index.js
CHANGED
|
@@ -1,64 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";
|
|
3
|
+
import { normalizePath } from "@directus/utils";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
var DriverAzure = class {
|
|
6
|
+
containerClient;
|
|
7
|
+
signedCredentials;
|
|
8
|
+
root;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.signedCredentials = new StorageSharedKeyCredential(config.accountName, config.accountKey);
|
|
11
|
+
const client = new BlobServiceClient(
|
|
12
|
+
config.endpoint ?? `https://${config.accountName}.blob.core.windows.net`,
|
|
13
|
+
this.signedCredentials
|
|
14
|
+
);
|
|
15
|
+
this.containerClient = client.getContainerClient(config.containerName);
|
|
16
|
+
this.root = config.root ? normalizePath(config.root, { removeLeading: true }) : "";
|
|
17
|
+
}
|
|
18
|
+
fullPath(filepath) {
|
|
19
|
+
return normalizePath(join(this.root, filepath));
|
|
20
|
+
}
|
|
21
|
+
async read(filepath, range) {
|
|
22
|
+
const { readableStreamBody } = await this.containerClient.getBlobClient(this.fullPath(filepath)).download(range?.start, range?.end ? range.end - (range.start || 0) + 1 : void 0);
|
|
23
|
+
if (!readableStreamBody) {
|
|
24
|
+
throw new Error(`No stream returned for file "${filepath}"`);
|
|
13
25
|
}
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
return readableStreamBody;
|
|
27
|
+
}
|
|
28
|
+
async write(filepath, content, type = "application/octet-stream") {
|
|
29
|
+
const blockBlobClient = this.containerClient.getBlockBlobClient(this.fullPath(filepath));
|
|
30
|
+
await blockBlobClient.uploadStream(content, void 0, void 0, {
|
|
31
|
+
blobHTTPHeaders: { blobContentType: type }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async delete(filepath) {
|
|
35
|
+
await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).deleteIfExists();
|
|
36
|
+
}
|
|
37
|
+
async stat(filepath) {
|
|
38
|
+
const props = await this.containerClient.getBlobClient(this.fullPath(filepath)).getProperties();
|
|
39
|
+
return {
|
|
40
|
+
size: props.contentLength,
|
|
41
|
+
modified: props.lastModified
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async exists(filepath) {
|
|
45
|
+
return await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).exists();
|
|
46
|
+
}
|
|
47
|
+
async move(src, dest) {
|
|
48
|
+
await this.copy(src, dest);
|
|
49
|
+
await this.containerClient.getBlockBlobClient(this.fullPath(src)).deleteIfExists();
|
|
50
|
+
}
|
|
51
|
+
async copy(src, dest) {
|
|
52
|
+
const source = this.containerClient.getBlockBlobClient(this.fullPath(src));
|
|
53
|
+
const target = this.containerClient.getBlockBlobClient(this.fullPath(dest));
|
|
54
|
+
const poller = await target.beginCopyFromURL(source.url);
|
|
55
|
+
await poller.pollUntilDone();
|
|
56
|
+
}
|
|
57
|
+
async *list(prefix = "") {
|
|
58
|
+
const blobs = this.containerClient.listBlobsFlat({
|
|
59
|
+
prefix: this.fullPath(prefix)
|
|
60
|
+
});
|
|
61
|
+
for await (const blob of blobs) {
|
|
62
|
+
yield blob.name.substring(this.root.length);
|
|
16
63
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return readableStreamBody;
|
|
25
|
-
}
|
|
26
|
-
async write(filepath, content, type = 'application/octet-stream') {
|
|
27
|
-
const blockBlobClient = this.containerClient.getBlockBlobClient(this.fullPath(filepath));
|
|
28
|
-
await blockBlobClient.uploadStream(content, undefined, undefined, {
|
|
29
|
-
blobHTTPHeaders: { blobContentType: type },
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
async delete(filepath) {
|
|
33
|
-
await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).deleteIfExists();
|
|
34
|
-
}
|
|
35
|
-
async stat(filepath) {
|
|
36
|
-
const props = await this.containerClient.getBlobClient(this.fullPath(filepath)).getProperties();
|
|
37
|
-
return {
|
|
38
|
-
size: props.contentLength,
|
|
39
|
-
modified: props.lastModified,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async exists(filepath) {
|
|
43
|
-
return await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).exists();
|
|
44
|
-
}
|
|
45
|
-
async move(src, dest) {
|
|
46
|
-
await this.copy(src, dest);
|
|
47
|
-
await this.containerClient.getBlockBlobClient(this.fullPath(src)).deleteIfExists();
|
|
48
|
-
}
|
|
49
|
-
async copy(src, dest) {
|
|
50
|
-
const source = this.containerClient.getBlockBlobClient(this.fullPath(src));
|
|
51
|
-
const target = this.containerClient.getBlockBlobClient(this.fullPath(dest));
|
|
52
|
-
const poller = await target.beginCopyFromURL(source.url);
|
|
53
|
-
await poller.pollUntilDone();
|
|
54
|
-
}
|
|
55
|
-
async *list(prefix = '') {
|
|
56
|
-
const blobs = this.containerClient.listBlobsFlat({
|
|
57
|
-
prefix: this.fullPath(prefix),
|
|
58
|
-
});
|
|
59
|
-
for await (const blob of blobs) {
|
|
60
|
-
yield blob.name.substring(this.root.length);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export default DriverAzure;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var src_default = DriverAzure;
|
|
67
|
+
export {
|
|
68
|
+
DriverAzure,
|
|
69
|
+
src_default as default
|
|
70
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directus/storage-driver-azure",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.12",
|
|
4
4
|
"description": "Azure file storage abstraction for `@directus/storage`",
|
|
5
5
|
"homepage": "https://directus.io",
|
|
6
6
|
"repository": {
|
|
@@ -22,19 +22,20 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@azure/storage-blob": "12.14.0",
|
|
25
|
-
"@directus/storage": "10.0.
|
|
26
|
-
"@directus/utils": "
|
|
25
|
+
"@directus/storage": "10.0.6",
|
|
26
|
+
"@directus/utils": "11.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@ngneat/falso": "6.4.0",
|
|
30
30
|
"@vitest/coverage-c8": "0.31.1",
|
|
31
|
-
"
|
|
31
|
+
"tsup": "7.2.0",
|
|
32
|
+
"typescript": "5.2.2",
|
|
32
33
|
"vitest": "0.31.1",
|
|
33
|
-
"@directus/tsconfig": "1.0.
|
|
34
|
+
"@directus/tsconfig": "1.0.1"
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"dev": "
|
|
37
|
+
"build": "tsup src/index.ts --format=esm --dts",
|
|
38
|
+
"dev": "tsup src/index.ts --format=esm --dts --watch",
|
|
38
39
|
"test": "vitest --watch=false"
|
|
39
40
|
}
|
|
40
41
|
}
|