microsoft-graph 3.9.0 → 3.9.1
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/cjs/operations/driveItem/createDriveItemContent.d.ts +10 -2
- package/dist/cjs/operations/driveItem/createDriveItemContent.d.ts.map +1 -1
- package/dist/cjs/operations/driveItem/createDriveItemContent.js +5 -12
- package/dist/esm/operations/driveItem/createDriveItemContent.d.ts +10 -2
- package/dist/esm/operations/driveItem/createDriveItemContent.d.ts.map +1 -1
- package/dist/esm/operations/driveItem/createDriveItemContent.js +5 -12
- package/docs/api/createDriveItemContent.md +82 -17
- package/package.json +1 -1
|
@@ -12,10 +12,18 @@ import type { DriveItemPath, DriveItemRef } from "../../models/DriveItem.ts";
|
|
|
12
12
|
* @param itemPath Path (including the filename) for the new drive item within the given parent.
|
|
13
13
|
* @param contentStream A Node.js readable stream containing the file content.
|
|
14
14
|
* @param totalSize The total size in bytes of the content to be uploaded.
|
|
15
|
-
* @param
|
|
15
|
+
* @param options Optional. Additional options for the upload operation.
|
|
16
|
+
* @param options.conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
|
|
17
|
+
* @param options.chunkSize Optional. The size of each chunk to be uploaded in bytes. Default is 10MB.
|
|
18
|
+
* @param options.progress Optional. A callback function that is called periodically with the upload progress as a percentage.
|
|
16
19
|
* @returns The newly created drive item.
|
|
17
20
|
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
|
|
18
21
|
* @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
|
|
19
22
|
*/
|
|
20
|
-
export
|
|
23
|
+
export interface CreateDriveItemContentOptions {
|
|
24
|
+
conflictBehavior?: "fail" | "replace" | "rename";
|
|
25
|
+
chunkSize?: number;
|
|
26
|
+
progress?: (pct: number) => void;
|
|
27
|
+
}
|
|
28
|
+
export default function createDriveItemContent(parentRef: DriveRef | DriveItemRef, itemPath: DriveItemPath, contentStream: NodeJS.ReadableStream, totalSize: number, options?: CreateDriveItemContentOptions): Promise<DriveItem & DriveItemRef>;
|
|
21
29
|
//# sourceMappingURL=createDriveItemContent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAkB1F
|
|
1
|
+
{"version":3,"file":"createDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAkB1F;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,6BAA6B;IAC7C,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED,wBAA8B,sBAAsB,CAAC,SAAS,EAAE,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,6BAAkC,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC,CAwGzP"}
|
|
@@ -15,18 +15,8 @@ const http_ts_1 = require("../../services/http.js");
|
|
|
15
15
|
const operationInvoker_ts_1 = require("../../services/operationInvoker.js");
|
|
16
16
|
const templatedPaths_ts_1 = require("../../services/templatedPaths.js");
|
|
17
17
|
const defaultChunkSize = 10 * 1024 * 1024;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param parentRef Reference to the parent drive or folder where the drive item will be created.
|
|
21
|
-
* @param itemPath Path (including the filename) for the new drive item within the given parent.
|
|
22
|
-
* @param contentStream A Node.js readable stream containing the file content.
|
|
23
|
-
* @param totalSize The total size in bytes of the content to be uploaded.
|
|
24
|
-
* @param conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
|
|
25
|
-
* @returns The newly created drive item.
|
|
26
|
-
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
|
|
27
|
-
* @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
|
|
28
|
-
*/
|
|
29
|
-
async function createDriveItemContent(parentRef, itemPath, contentStream, totalSize, conflictBehavior = "fail", chunkSize = defaultChunkSize) {
|
|
18
|
+
async function createDriveItemContent(parentRef, itemPath, contentStream, totalSize, options = {}) {
|
|
19
|
+
const { conflictBehavior = "fail", chunkSize = defaultChunkSize, progress } = options;
|
|
30
20
|
const pathSegment = parentRef.itemId ? "items/{item-id}" : "root";
|
|
31
21
|
const uploadSessionUrl = `${operationInvoker_ts_1.endpoint}${(0, templatedPaths_ts_1.generatePath)(`/sites/{site-id}/drives/{drive-id}/${pathSegment}:/${itemPath}:/createUploadSession`, parentRef)}`;
|
|
32
22
|
const accessToken = await parentRef.context.generateAccessToken();
|
|
@@ -78,6 +68,9 @@ async function createDriveItemContent(parentRef, itemPath, contentStream, totalS
|
|
|
78
68
|
responseType: "json",
|
|
79
69
|
});
|
|
80
70
|
position += thisChunk.length;
|
|
71
|
+
if (progress && totalSize > 0) {
|
|
72
|
+
progress(Math.min(100, (position / totalSize) * 100));
|
|
73
|
+
}
|
|
81
74
|
currentChunk = currentChunk.subarray(chunkSize);
|
|
82
75
|
if (isDriveItem(res)) {
|
|
83
76
|
driveItem = res;
|
|
@@ -12,10 +12,18 @@ import type { DriveItemPath, DriveItemRef } from "../../models/DriveItem.ts";
|
|
|
12
12
|
* @param itemPath Path (including the filename) for the new drive item within the given parent.
|
|
13
13
|
* @param contentStream A Node.js readable stream containing the file content.
|
|
14
14
|
* @param totalSize The total size in bytes of the content to be uploaded.
|
|
15
|
-
* @param
|
|
15
|
+
* @param options Optional. Additional options for the upload operation.
|
|
16
|
+
* @param options.conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
|
|
17
|
+
* @param options.chunkSize Optional. The size of each chunk to be uploaded in bytes. Default is 10MB.
|
|
18
|
+
* @param options.progress Optional. A callback function that is called periodically with the upload progress as a percentage.
|
|
16
19
|
* @returns The newly created drive item.
|
|
17
20
|
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
|
|
18
21
|
* @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
|
|
19
22
|
*/
|
|
20
|
-
export
|
|
23
|
+
export interface CreateDriveItemContentOptions {
|
|
24
|
+
conflictBehavior?: "fail" | "replace" | "rename";
|
|
25
|
+
chunkSize?: number;
|
|
26
|
+
progress?: (pct: number) => void;
|
|
27
|
+
}
|
|
28
|
+
export default function createDriveItemContent(parentRef: DriveRef | DriveItemRef, itemPath: DriveItemPath, contentStream: NodeJS.ReadableStream, totalSize: number, options?: CreateDriveItemContentOptions): Promise<DriveItem & DriveItemRef>;
|
|
21
29
|
//# sourceMappingURL=createDriveItemContent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAkB1F
|
|
1
|
+
{"version":3,"file":"createDriveItemContent.d.ts","sourceRoot":"","sources":["../../../../src/operations/driveItem/createDriveItemContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAe,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAkB1F;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,6BAA6B;IAC7C,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED,wBAA8B,sBAAsB,CAAC,SAAS,EAAE,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,6BAAkC,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC,CAwGzP"}
|
|
@@ -9,18 +9,8 @@ import { execute } from "../../services/http.js";
|
|
|
9
9
|
import { endpoint } from "../../services/operationInvoker.js";
|
|
10
10
|
import { generatePath } from "../../services/templatedPaths.js";
|
|
11
11
|
const defaultChunkSize = 10 * 1024 * 1024;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @param parentRef Reference to the parent drive or folder where the drive item will be created.
|
|
15
|
-
* @param itemPath Path (including the filename) for the new drive item within the given parent.
|
|
16
|
-
* @param contentStream A Node.js readable stream containing the file content.
|
|
17
|
-
* @param totalSize The total size in bytes of the content to be uploaded.
|
|
18
|
-
* @param conflictBehavior Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
|
|
19
|
-
* @returns The newly created drive item.
|
|
20
|
-
* @see https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
|
|
21
|
-
* @see https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
|
|
22
|
-
*/
|
|
23
|
-
export default async function createDriveItemContent(parentRef, itemPath, contentStream, totalSize, conflictBehavior = "fail", chunkSize = defaultChunkSize) {
|
|
12
|
+
export default async function createDriveItemContent(parentRef, itemPath, contentStream, totalSize, options = {}) {
|
|
13
|
+
const { conflictBehavior = "fail", chunkSize = defaultChunkSize, progress } = options;
|
|
24
14
|
const pathSegment = parentRef.itemId ? "items/{item-id}" : "root";
|
|
25
15
|
const uploadSessionUrl = `${endpoint}${generatePath(`/sites/{site-id}/drives/{drive-id}/${pathSegment}:/${itemPath}:/createUploadSession`, parentRef)}`;
|
|
26
16
|
const accessToken = await parentRef.context.generateAccessToken();
|
|
@@ -72,6 +62,9 @@ export default async function createDriveItemContent(parentRef, itemPath, conten
|
|
|
72
62
|
responseType: "json",
|
|
73
63
|
});
|
|
74
64
|
position += thisChunk.length;
|
|
65
|
+
if (progress && totalSize > 0) {
|
|
66
|
+
progress(Math.min(100, (position / totalSize) * 100));
|
|
67
|
+
}
|
|
75
68
|
currentChunk = currentChunk.subarray(chunkSize);
|
|
76
69
|
if (isDriveItem(res)) {
|
|
77
70
|
driveItem = res;
|
|
@@ -4,34 +4,99 @@
|
|
|
4
4
|
|
|
5
5
|
Creates a new drive item in the specified parent drive or folder using a stream as content.
|
|
6
6
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
### createDriveItemContent()
|
|
7
|
+
## Interfaces
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
### CreateDriveItemContentOptions
|
|
12
10
|
|
|
13
|
-
Defined in: [src/operations/driveItem/createDriveItemContent.ts:
|
|
11
|
+
Defined in: [src/operations/driveItem/createDriveItemContent.ts:42](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/operations/driveItem/createDriveItemContent.ts#L42)
|
|
14
12
|
|
|
15
13
|
Creates a new drive item in the specified parent drive or folder using a stream as content.
|
|
16
14
|
|
|
17
|
-
####
|
|
15
|
+
#### Param
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
| ------ | ------ | ------ | ------ |
|
|
21
|
-
| `parentRef` | [`DriveRef`](Drive-1.md#driveref) \| [`DriveItemRef`](DriveItem-1.md#driveitemref) | `undefined` | Reference to the parent drive or folder where the drive item will be created. |
|
|
22
|
-
| `itemPath` | [`DriveItemPath`](DriveItem-1.md#driveitempath) | `undefined` | Path (including the filename) for the new drive item within the given parent. |
|
|
23
|
-
| `contentStream` | [`ReadableStream`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/globals.d.ts#L202) | `undefined` | A Node.js readable stream containing the file content. |
|
|
24
|
-
| `totalSize` | `number` | `undefined` | The total size in bytes of the content to be uploaded. |
|
|
25
|
-
| `conflictBehavior` | `"replace"` \| `"fail"` \| `"rename"` | `"fail"` | Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'. |
|
|
26
|
-
| `chunkSize` | `number` | `defaultChunkSize` | - |
|
|
17
|
+
Reference to the parent drive or folder where the drive item will be created.
|
|
27
18
|
|
|
28
|
-
####
|
|
19
|
+
#### Param
|
|
29
20
|
|
|
30
|
-
|
|
21
|
+
Path (including the filename) for the new drive item within the given parent.
|
|
22
|
+
|
|
23
|
+
#### Param
|
|
24
|
+
|
|
25
|
+
A Node.js readable stream containing the file content.
|
|
26
|
+
|
|
27
|
+
#### Param
|
|
28
|
+
|
|
29
|
+
The total size in bytes of the content to be uploaded.
|
|
30
|
+
|
|
31
|
+
#### Param
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
Optional. Additional options for the upload operation.
|
|
34
|
+
|
|
35
|
+
#### Param
|
|
36
|
+
|
|
37
|
+
Optional. Specifies how to handle conflicts if the file already exists. Default is 'fail'.
|
|
38
|
+
|
|
39
|
+
#### Param
|
|
40
|
+
|
|
41
|
+
Optional. The size of each chunk to be uploaded in bytes. Default is 10MB.
|
|
42
|
+
|
|
43
|
+
#### Param
|
|
44
|
+
|
|
45
|
+
Optional. A callback function that is called periodically with the upload progress as a percentage.
|
|
33
46
|
|
|
34
47
|
#### See
|
|
35
48
|
|
|
36
49
|
- https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession
|
|
37
50
|
- https://learn.microsoft.com/en-us/graph/api/resources/uploadsession
|
|
51
|
+
|
|
52
|
+
#### Properties
|
|
53
|
+
|
|
54
|
+
##### chunkSize?
|
|
55
|
+
|
|
56
|
+
> `optional` **chunkSize**: `number`
|
|
57
|
+
|
|
58
|
+
Defined in: [src/operations/driveItem/createDriveItemContent.ts:44](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/operations/driveItem/createDriveItemContent.ts#L44)
|
|
59
|
+
|
|
60
|
+
##### conflictBehavior?
|
|
61
|
+
|
|
62
|
+
> `optional` **conflictBehavior**: `"replace"` \| `"fail"` \| `"rename"`
|
|
63
|
+
|
|
64
|
+
Defined in: [src/operations/driveItem/createDriveItemContent.ts:43](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/operations/driveItem/createDriveItemContent.ts#L43)
|
|
65
|
+
|
|
66
|
+
##### progress()?
|
|
67
|
+
|
|
68
|
+
> `optional` **progress**: (`pct`) => `void`
|
|
69
|
+
|
|
70
|
+
Defined in: [src/operations/driveItem/createDriveItemContent.ts:45](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/operations/driveItem/createDriveItemContent.ts#L45)
|
|
71
|
+
|
|
72
|
+
###### Parameters
|
|
73
|
+
|
|
74
|
+
| Parameter | Type |
|
|
75
|
+
| ------ | ------ |
|
|
76
|
+
| `pct` | `number` |
|
|
77
|
+
|
|
78
|
+
###### Returns
|
|
79
|
+
|
|
80
|
+
`void`
|
|
81
|
+
|
|
82
|
+
## Functions
|
|
83
|
+
|
|
84
|
+
### createDriveItemContent()
|
|
85
|
+
|
|
86
|
+
> **createDriveItemContent**(`parentRef`, `itemPath`, `contentStream`, `totalSize`, `options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`DriveItem` & [`SiteRef`](Site-1.md#siteref) & `object` & `object`\>
|
|
87
|
+
|
|
88
|
+
Defined in: [src/operations/driveItem/createDriveItemContent.ts:48](https://github.com/Future-Secure-AI/microsoft-graph/blob/main/src/operations/driveItem/createDriveItemContent.ts#L48)
|
|
89
|
+
|
|
90
|
+
#### Parameters
|
|
91
|
+
|
|
92
|
+
| Parameter | Type |
|
|
93
|
+
| ------ | ------ |
|
|
94
|
+
| `parentRef` | [`DriveRef`](Drive-1.md#driveref) \| [`DriveItemRef`](DriveItem-1.md#driveitemref) |
|
|
95
|
+
| `itemPath` | [`DriveItemPath`](DriveItem-1.md#driveitempath) |
|
|
96
|
+
| `contentStream` | [`ReadableStream`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/globals.d.ts#L202) |
|
|
97
|
+
| `totalSize` | `number` |
|
|
98
|
+
| `options` | [`CreateDriveItemContentOptions`](#createdriveitemcontentoptions) |
|
|
99
|
+
|
|
100
|
+
#### Returns
|
|
101
|
+
|
|
102
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`DriveItem` & [`SiteRef`](Site-1.md#siteref) & `object` & `object`\>
|