Skip to content

Commit 9e15875

Browse files
committed
new components
1 parent d1df610 commit 9e15875

File tree

16 files changed

+790
-608
lines changed

16 files changed

+790
-608
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import autodesk from "../../autodesk.app.mjs";
2+
3+
export default {
4+
key: "autodesk-create-folder",
5+
name: "Create Folder",
6+
description: "Creates a new folder in a project in Autodesk. [See the documentation](https://aps.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-POST/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
autodesk,
11+
hubId: {
12+
propDefinition: [
13+
autodesk,
14+
"hubId",
15+
],
16+
},
17+
projectId: {
18+
propDefinition: [
19+
autodesk,
20+
"projectId",
21+
(c) => ({
22+
hubId: c.hubId,
23+
}),
24+
],
25+
},
26+
name: {
27+
type: "string",
28+
label: "Name",
29+
description: "The name of the new folder",
30+
},
31+
parent: {
32+
propDefinition: [
33+
autodesk,
34+
"folderId",
35+
(c) => ({
36+
hubId: c.hubId,
37+
projectId: c.projectId,
38+
}),
39+
],
40+
label: "Parent Folder ID",
41+
description: "The identifier of the parent folder",
42+
},
43+
type: {
44+
type: "string",
45+
label: "Extension Type",
46+
description: "The type of folder extension. For BIM 360 Docs folders, use `folders:autodesk.bim360:Folder`. For all other services, use `folders:autodesk.core:Folder`.",
47+
options: [
48+
"folders:autodesk.core:Folder",
49+
"folders:autodesk.bim360:Folder",
50+
],
51+
default: "folders:autodesk.core:Folder",
52+
optional: true,
53+
},
54+
},
55+
async run({ $ }) {
56+
const response = await this.autodesk.createFolder({
57+
$,
58+
projectId: this.projectId,
59+
data: {
60+
jsonapi: {
61+
version: "1.0",
62+
},
63+
data: {
64+
type: "folders",
65+
attributes: {
66+
name: this.name,
67+
extension: {
68+
type: this.type,
69+
version: "1.0",
70+
},
71+
},
72+
relationships: {
73+
parent: {
74+
data: {
75+
type: "folders",
76+
id: this.parent,
77+
},
78+
},
79+
},
80+
},
81+
},
82+
});
83+
$.export("$summary", `Successfully created new folder: ${this.name}`);
84+
return response;
85+
},
86+
};

components/autodesk/actions/create-project/create-project.mjs

Lines changed: 0 additions & 36 deletions
This file was deleted.

components/autodesk/actions/update-file-metadata/update-file-metadata.mjs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,74 @@
11
import autodesk from "../../autodesk.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "autodesk-update-file-metadata",
65
name: "Update File Metadata",
7-
description: "Updates metadata for an existing file in Autodesk. [See the documentation](https://aps.autodesk.com/developer/documentation)",
8-
version: "0.0.{{ts}}",
6+
description: "Updates metadata for an existing file in Autodesk. [See the documentation](https://aps.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-items-item_id-PATCH/)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
autodesk,
12-
fileId: {
11+
hubId: {
1312
propDefinition: [
1413
autodesk,
15-
"fileId",
14+
"hubId",
1615
],
1716
},
18-
metadata: {
17+
projectId: {
18+
propDefinition: [
19+
autodesk,
20+
"projectId",
21+
(c) => ({
22+
hubId: c.hubId,
23+
}),
24+
],
25+
},
26+
parent: {
1927
propDefinition: [
2028
autodesk,
21-
"metadata",
29+
"folderId",
30+
(c) => ({
31+
hubId: c.hubId,
32+
projectId: c.projectId,
33+
}),
2234
],
35+
label: "Parent Folder ID",
36+
description: "The identifier of the file's parent folder",
37+
},
38+
fileId: {
39+
propDefinition: [
40+
autodesk,
41+
"fileId",
42+
(c) => ({
43+
projectId: c.projectId,
44+
folderId: c.parent,
45+
}),
46+
],
47+
},
48+
metadata: {
49+
type: "string",
50+
label: "Metadata",
51+
description: "An object containing key-value pairs of the attributes to update. Example: `{ \"displayName\": \"newFileName.jpg\"}`",
2352
},
2453
},
2554
async run({ $ }) {
26-
const response = await this.autodesk.updateMetadata();
55+
const response = await this.autodesk.updateMetadata({
56+
$,
57+
projectId: this.projectId,
58+
fileId: this.fileId,
59+
data: {
60+
jsonapi: {
61+
version: "1.0",
62+
},
63+
data: {
64+
type: "items",
65+
id: this.fileId,
66+
attributes: typeof this.metadata === "string"
67+
? JSON.parse(this.metadata)
68+
: this.metadata,
69+
},
70+
},
71+
});
2772
$.export("$summary", `Updated metadata for file ${this.fileId}`);
2873
return response;
2974
},
Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,118 @@
11
import autodesk from "../../autodesk.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import fs from "fs";
33

44
export default {
55
key: "autodesk-upload-file",
6-
name: "Upload File to Autodesk Project or Folder",
7-
description: "Uploads a new file to a specified project or folder in Autodesk. [See the documentation]().",
8-
version: "0.0.{{ts}}",
6+
name: "Upload File",
7+
description: "Uploads a new file to a specified folder in Autodesk. [See the documentation](https://aps.autodesk.com/en/docs/data/v2/tutorials/upload-file/).",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
autodesk,
12+
hubId: {
13+
propDefinition: [
14+
autodesk,
15+
"hubId",
16+
],
17+
},
1218
projectId: {
1319
propDefinition: [
1420
autodesk,
1521
"projectId",
22+
(c) => ({
23+
hubId: c.hubId,
24+
}),
25+
],
26+
},
27+
folderId: {
28+
propDefinition: [
29+
autodesk,
30+
"folderId",
31+
(c) => ({
32+
hubId: c.hubId,
33+
projectId: c.projectId,
34+
}),
1635
],
1736
},
1837
fileName: {
1938
type: "string",
2039
label: "File Name",
2140
description: "The name of the file to upload",
2241
},
23-
fileContent: {
42+
filePath: {
2443
type: "string",
25-
label: "File Content",
26-
description: "The content of the file to upload",
27-
},
28-
folderId: {
29-
propDefinition: [
30-
autodesk,
31-
"folderId",
32-
],
33-
optional: true,
44+
label: "File Path",
45+
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
3446
},
3547
},
3648
async run({ $ }) {
37-
this.autodesk.projectId = this.projectId;
38-
this.autodesk.fileName = this.fileName;
39-
this.autodesk.fileContent = this.fileContent;
40-
if (this.folderId) {
41-
this.autodesk.folderId = this.folderId;
42-
}
43-
44-
const response = await this.autodesk.uploadFile();
45-
46-
$.export("$summary", `Uploaded file "${this.fileName}" to project "${this.projectId}"${this.folderId
47-
? ` and folder "${this.folderId}"`
48-
: ""}.`);
49+
// Create storage location
50+
const { data } = await this.autodesk.createStorageLocation({
51+
$,
52+
projectId: this.projectId,
53+
data: {
54+
jsonapi: {
55+
version: "1.0",
56+
},
57+
data: {
58+
type: "objects",
59+
attributes: {
60+
name: this.fileName,
61+
},
62+
relationships: {
63+
target: {
64+
data: {
65+
type: "folders",
66+
id: this.folderId,
67+
},
68+
},
69+
},
70+
},
71+
},
72+
});
73+
74+
const objectId = data.id;
75+
const [
76+
bucketKey,
77+
objectKey,
78+
] = objectId.match(/^urn:adsk\.objects:os\.object:([^/]+)\/(.+)$/);
79+
80+
// Generate signed URL
81+
const {
82+
urls, uploadKey,
83+
} = await this.autodesk.generateSignedUrl({
84+
$,
85+
bucketKey,
86+
objectKey,
87+
});
88+
89+
const signedUrl = urls[0];
90+
91+
// Upload to signed URL
92+
const fileStream = fs.createReadStream(this.filePath.includes("tmp/")
93+
? this.filePath
94+
: `/tmp/${this.filePath}`);
95+
96+
await this.autodesk._makeRequest({
97+
$,
98+
url: signedUrl,
99+
data: fileStream,
100+
headers: {
101+
"Content-Type": "application/octet-stream",
102+
},
103+
});
104+
105+
// Complete the upload
106+
const response = await this.autodesk.completeUpload({
107+
$,
108+
bucketKey,
109+
objectKey,
110+
data: {
111+
uploadKey,
112+
},
113+
});
114+
115+
$.export("$summary", `Successfully uploaded file ${this.fileName}`);
49116
return response;
50117
},
51118
};

0 commit comments

Comments
 (0)