@directus/storage-driver-azure 12.0.8 → 12.0.10
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 +36 -35
- package/dist/index.js +83 -99
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import { TusDriver } from
|
|
2
|
-
import {
|
|
3
|
-
import { Readable } from
|
|
1
|
+
import { TusDriver } from "@directus/storage";
|
|
2
|
+
import { ChunkedUploadContext, ReadOptions } from "@directus/types";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
4
|
|
|
5
|
+
//#region src/index.d.ts
|
|
5
6
|
type DriverAzureConfig = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
containerName: string;
|
|
8
|
+
accountName: string;
|
|
9
|
+
accountKey: string;
|
|
10
|
+
root?: string;
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
tus?: {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
chunkSize?: number;
|
|
15
|
+
};
|
|
15
16
|
};
|
|
16
17
|
declare class DriverAzure implements TusDriver {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
private containerClient;
|
|
19
|
+
private signedCredentials;
|
|
20
|
+
private root;
|
|
21
|
+
constructor(config: DriverAzureConfig);
|
|
22
|
+
private fullPath;
|
|
23
|
+
read(filepath: string, options?: ReadOptions): Promise<Readable>;
|
|
24
|
+
write(filepath: string, content: Readable, type?: string): Promise<void>;
|
|
25
|
+
delete(filepath: string): Promise<void>;
|
|
26
|
+
stat(filepath: string): Promise<{
|
|
27
|
+
size: number;
|
|
28
|
+
modified: Date;
|
|
29
|
+
}>;
|
|
30
|
+
exists(filepath: string): Promise<boolean>;
|
|
31
|
+
move(src: string, dest: string): Promise<void>;
|
|
32
|
+
copy(src: string, dest: string): Promise<void>;
|
|
33
|
+
list(prefix?: string): AsyncGenerator<string, void, unknown>;
|
|
34
|
+
get tusExtensions(): string[];
|
|
35
|
+
createChunkedUpload(filepath: string, context: ChunkedUploadContext): Promise<ChunkedUploadContext>;
|
|
36
|
+
writeChunk(filepath: string, content: Readable, offset: number, _context: ChunkedUploadContext): Promise<number>;
|
|
37
|
+
finishChunkedUpload(_filepath: string, _context: ChunkedUploadContext): Promise<void>;
|
|
38
|
+
deleteChunkedUpload(filepath: string, _context: ChunkedUploadContext): Promise<void>;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
export { DriverAzure,
|
|
40
|
+
//#endregion
|
|
41
|
+
export { DriverAzure, DriverAzure as default, DriverAzureConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,103 +1,87 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
1
|
import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";
|
|
3
2
|
import { normalizePath } from "@directus/utils";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { finished } from "stream/promises";
|
|
6
|
-
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { finished } from "node:stream/promises";
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
const MAXIMUM_CHUNK_SIZE = 104857600;
|
|
7
8
|
var DriverAzure = class {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
content.on("data", (chunk2) => {
|
|
83
|
-
bytesUploaded += chunk2.length;
|
|
84
|
-
chunks.push(chunk2);
|
|
85
|
-
});
|
|
86
|
-
await finished(content);
|
|
87
|
-
const chunk = Buffer.concat(chunks);
|
|
88
|
-
if (chunk.length > 0) {
|
|
89
|
-
await client.appendBlock(chunk, chunk.length);
|
|
90
|
-
}
|
|
91
|
-
return bytesUploaded;
|
|
92
|
-
}
|
|
93
|
-
async finishChunkedUpload(_filepath, _context) {
|
|
94
|
-
}
|
|
95
|
-
async deleteChunkedUpload(filepath, _context) {
|
|
96
|
-
await this.delete(filepath);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var index_default = DriverAzure;
|
|
100
|
-
export {
|
|
101
|
-
DriverAzure,
|
|
102
|
-
index_default as default
|
|
9
|
+
containerClient;
|
|
10
|
+
signedCredentials;
|
|
11
|
+
root;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.signedCredentials = new StorageSharedKeyCredential(config.accountName, config.accountKey);
|
|
14
|
+
this.containerClient = new BlobServiceClient(config.endpoint ?? `https://${config.accountName}.blob.core.windows.net`, this.signedCredentials).getContainerClient(config.containerName);
|
|
15
|
+
this.root = config.root ? normalizePath(config.root, { removeLeading: true }) : "";
|
|
16
|
+
if (config.tus?.enabled && config.tus.chunkSize && config.tus.chunkSize > MAXIMUM_CHUNK_SIZE) throw new Error("Invalid chunkSize provided");
|
|
17
|
+
}
|
|
18
|
+
fullPath(filepath) {
|
|
19
|
+
return normalizePath(join(this.root, filepath));
|
|
20
|
+
}
|
|
21
|
+
async read(filepath, options) {
|
|
22
|
+
const { range } = options || {};
|
|
23
|
+
const { readableStreamBody } = await this.containerClient.getBlobClient(this.fullPath(filepath)).download(range?.start, range?.end ? range.end - (range.start || 0) + 1 : void 0);
|
|
24
|
+
if (!readableStreamBody) throw new Error(`No stream returned for file "${filepath}"`);
|
|
25
|
+
return readableStreamBody;
|
|
26
|
+
}
|
|
27
|
+
async write(filepath, content, type = "application/octet-stream") {
|
|
28
|
+
await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).uploadStream(content, void 0, void 0, { blobHTTPHeaders: { blobContentType: type } });
|
|
29
|
+
}
|
|
30
|
+
async delete(filepath) {
|
|
31
|
+
await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).deleteIfExists();
|
|
32
|
+
}
|
|
33
|
+
async stat(filepath) {
|
|
34
|
+
const props = await this.containerClient.getBlobClient(this.fullPath(filepath)).getProperties();
|
|
35
|
+
return {
|
|
36
|
+
size: props.contentLength,
|
|
37
|
+
modified: props.lastModified
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async exists(filepath) {
|
|
41
|
+
return await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).exists();
|
|
42
|
+
}
|
|
43
|
+
async move(src, dest) {
|
|
44
|
+
await this.copy(src, dest);
|
|
45
|
+
await this.containerClient.getBlockBlobClient(this.fullPath(src)).deleteIfExists();
|
|
46
|
+
}
|
|
47
|
+
async copy(src, dest) {
|
|
48
|
+
const source = this.containerClient.getBlockBlobClient(this.fullPath(src));
|
|
49
|
+
await (await this.containerClient.getBlockBlobClient(this.fullPath(dest)).beginCopyFromURL(source.url)).pollUntilDone();
|
|
50
|
+
}
|
|
51
|
+
async *list(prefix = "") {
|
|
52
|
+
const blobs = this.containerClient.listBlobsFlat({ prefix: this.fullPath(prefix) });
|
|
53
|
+
for await (const blob of blobs) yield blob.name.substring(this.root.length);
|
|
54
|
+
}
|
|
55
|
+
get tusExtensions() {
|
|
56
|
+
return [
|
|
57
|
+
"creation",
|
|
58
|
+
"termination",
|
|
59
|
+
"expiration"
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
async createChunkedUpload(filepath, context) {
|
|
63
|
+
await this.containerClient.getAppendBlobClient(this.fullPath(filepath)).createIfNotExists();
|
|
64
|
+
return context;
|
|
65
|
+
}
|
|
66
|
+
async writeChunk(filepath, content, offset, _context) {
|
|
67
|
+
const client = this.containerClient.getAppendBlobClient(this.fullPath(filepath));
|
|
68
|
+
let bytesUploaded = offset || 0;
|
|
69
|
+
const chunks = [];
|
|
70
|
+
content.on("data", (chunk$1) => {
|
|
71
|
+
bytesUploaded += chunk$1.length;
|
|
72
|
+
chunks.push(chunk$1);
|
|
73
|
+
});
|
|
74
|
+
await finished(content);
|
|
75
|
+
const chunk = Buffer.concat(chunks);
|
|
76
|
+
if (chunk.length > 0) await client.appendBlock(chunk, chunk.length);
|
|
77
|
+
return bytesUploaded;
|
|
78
|
+
}
|
|
79
|
+
async finishChunkedUpload(_filepath, _context) {}
|
|
80
|
+
async deleteChunkedUpload(filepath, _context) {
|
|
81
|
+
await this.delete(filepath);
|
|
82
|
+
}
|
|
103
83
|
};
|
|
84
|
+
var src_default = DriverAzure;
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { DriverAzure, src_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directus/storage-driver-azure",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.10",
|
|
4
4
|
"description": "Azure file storage abstraction for `@directus/storage`",
|
|
5
5
|
"homepage": "https://directus.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,22 +21,22 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@azure/storage-blob": "12.
|
|
25
|
-
"@directus/
|
|
26
|
-
"@directus/
|
|
24
|
+
"@azure/storage-blob": "12.29.1",
|
|
25
|
+
"@directus/utils": "13.0.11",
|
|
26
|
+
"@directus/storage": "12.0.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@directus/tsconfig": "3.0.0",
|
|
30
30
|
"@ngneat/falso": "8.0.2",
|
|
31
31
|
"@vitest/coverage-v8": "3.2.4",
|
|
32
|
-
"
|
|
33
|
-
"typescript": "5.
|
|
32
|
+
"tsdown": "0.15.11",
|
|
33
|
+
"typescript": "5.9.3",
|
|
34
34
|
"vitest": "3.2.4",
|
|
35
|
-
"@directus/types": "13.
|
|
35
|
+
"@directus/types": "13.3.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "
|
|
39
|
-
"dev": "
|
|
38
|
+
"build": "tsdown src/index.ts --dts",
|
|
39
|
+
"dev": "tsdown src/index.ts --dts --watch",
|
|
40
40
|
"test": "vitest run",
|
|
41
41
|
"test:coverage": "vitest run --coverage"
|
|
42
42
|
}
|