Skip to content

Commit efb7584

Browse files
authored
New Components - autodesk (#15344)
* autodesk init * new components * pnpm-lock.yaml * updates * wip * updates * fix pagination * update type prop
1 parent f3c93f8 commit efb7584

File tree

13 files changed

+929
-7
lines changed

13 files changed

+929
-7
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
{
49+
label: "BIM 360 Docs folders",
50+
value: "folders:autodesk.core:Folder",
51+
},
52+
{
53+
label: "Other folders",
54+
value: "folders:autodesk.bim360:Folder",
55+
},
56+
],
57+
default: "folders:autodesk.core:Folder",
58+
optional: true,
59+
},
60+
},
61+
async run({ $ }) {
62+
const response = await this.autodesk.createFolder({
63+
$,
64+
projectId: this.projectId,
65+
data: {
66+
jsonapi: {
67+
version: "1.0",
68+
},
69+
data: {
70+
type: "folders",
71+
attributes: {
72+
name: this.name,
73+
extension: {
74+
type: this.type,
75+
version: "1.0",
76+
},
77+
},
78+
relationships: {
79+
parent: {
80+
data: {
81+
type: "folders",
82+
id: this.parent,
83+
},
84+
},
85+
},
86+
},
87+
},
88+
});
89+
$.export("$summary", `Successfully created new folder: ${this.name}`);
90+
return response;
91+
},
92+
};
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import autodesk from "../../autodesk.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
import fs from "fs";
4+
5+
export default {
6+
key: "autodesk-upload-file",
7+
name: "Upload File",
8+
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/).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
autodesk,
13+
hubId: {
14+
propDefinition: [
15+
autodesk,
16+
"hubId",
17+
],
18+
},
19+
projectId: {
20+
propDefinition: [
21+
autodesk,
22+
"projectId",
23+
(c) => ({
24+
hubId: c.hubId,
25+
}),
26+
],
27+
},
28+
folderId: {
29+
propDefinition: [
30+
autodesk,
31+
"folderId",
32+
(c) => ({
33+
hubId: c.hubId,
34+
projectId: c.projectId,
35+
}),
36+
],
37+
},
38+
fileName: {
39+
type: "string",
40+
label: "File Name",
41+
description: "The name of the file to upload",
42+
},
43+
filePath: {
44+
type: "string",
45+
label: "File Path",
46+
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)",
47+
},
48+
type: {
49+
type: "string",
50+
label: "Extension Type",
51+
description: "The type of file extension. For BIM 360 Docs files, use `items:autodesk.bim360:File`. For all other services, use `items:autodesk.core:File`.",
52+
options: [
53+
{
54+
label: "BIM 360 Docs files",
55+
value: "items:autodesk.core:File",
56+
},
57+
{
58+
label: "Other files",
59+
value: "items:autodesk.bim360:File",
60+
},
61+
],
62+
default: "items:autodesk.core:File",
63+
optional: true,
64+
},
65+
},
66+
async run({ $ }) {
67+
// Create storage location
68+
const { data } = await this.autodesk.createStorageLocation({
69+
$,
70+
projectId: this.projectId,
71+
data: {
72+
jsonapi: {
73+
version: "1.0",
74+
},
75+
data: {
76+
type: "objects",
77+
attributes: {
78+
name: this.fileName,
79+
},
80+
relationships: {
81+
target: {
82+
data: {
83+
type: "folders",
84+
id: this.folderId,
85+
},
86+
},
87+
},
88+
},
89+
},
90+
});
91+
92+
const objectId = data.id;
93+
const [
94+
bucketKey,
95+
objectKey,
96+
] = objectId.split("os.object:")[1]?.split("/") || [];
97+
98+
// Generate signed URL
99+
const {
100+
urls, uploadKey,
101+
} = await this.autodesk.generateSignedUrl({
102+
$,
103+
bucketKey,
104+
objectKey,
105+
});
106+
107+
const signedUrl = urls[0];
108+
109+
// Upload to signed URL
110+
const filePath = this.filePath.includes("tmp/")
111+
? this.filePath
112+
: `/tmp/${this.filePath}`;
113+
const fileStream = fs.createReadStream(filePath);
114+
const fileSize = fs.statSync(filePath).size;
115+
116+
await axios($, {
117+
url: signedUrl,
118+
data: fileStream,
119+
method: "PUT",
120+
headers: {
121+
"Content-Type": "application/octet-stream",
122+
"Content-Length": fileSize,
123+
},
124+
maxContentLength: Infinity,
125+
maxBodyLength: Infinity,
126+
});
127+
128+
// Complete the upload
129+
await this.autodesk.completeUpload({
130+
$,
131+
bucketKey,
132+
objectKey,
133+
data: {
134+
uploadKey,
135+
},
136+
});
137+
138+
// Create version 1.0 of uploaded file
139+
const response = await this.autodesk.createFirstVersionOfFile({
140+
$,
141+
projectId: this.projectId,
142+
data: {
143+
jsonapi: {
144+
version: "1.0",
145+
},
146+
data: {
147+
type: "items",
148+
attributes: {
149+
displayName: this.fileName,
150+
extension: {
151+
type: this.type,
152+
version: "1.0",
153+
},
154+
},
155+
relationships: {
156+
tip: {
157+
data: {
158+
type: "versions",
159+
id: "1",
160+
},
161+
},
162+
parent: {
163+
data: {
164+
type: "folders",
165+
id: this.folderId,
166+
},
167+
},
168+
},
169+
},
170+
included: [
171+
{
172+
type: "versions",
173+
id: "1",
174+
attributes: {
175+
name: this.fileName,
176+
extension: {
177+
type: this.type.replace("items", "versions"),
178+
version: "1.0",
179+
},
180+
},
181+
relationships: {
182+
storage: {
183+
data: {
184+
type: "objects",
185+
id: objectId,
186+
},
187+
},
188+
},
189+
},
190+
],
191+
},
192+
});
193+
194+
$.export("$summary", `Successfully uploaded file ${this.fileName}`);
195+
return response;
196+
},
197+
};

0 commit comments

Comments
 (0)