Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions components/autodesk/actions/create-folder/create-folder.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import autodesk from "../../autodesk.app.mjs";

export default {
key: "autodesk-create-folder",
name: "Create Folder",
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/)",
version: "0.0.1",
type: "action",
props: {
autodesk,
hubId: {
propDefinition: [
autodesk,
"hubId",
],
},
projectId: {
propDefinition: [
autodesk,
"projectId",
(c) => ({
hubId: c.hubId,
}),
],
},
name: {
type: "string",
label: "Name",
description: "The name of the new folder",
},
parent: {
propDefinition: [
autodesk,
"folderId",
(c) => ({
hubId: c.hubId,
projectId: c.projectId,
}),
],
label: "Parent Folder ID",
description: "The identifier of the parent folder",
},
type: {
type: "string",
label: "Extension Type",
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`.",
options: [
"folders:autodesk.core:Folder",
"folders:autodesk.bim360:Folder",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could those have a label? Such as BIM 360 Docs folders and Other folders

],
default: "folders:autodesk.core:Folder",
optional: true,
},
},
async run({ $ }) {
const response = await this.autodesk.createFolder({
$,
projectId: this.projectId,
data: {
jsonapi: {
version: "1.0",
},
data: {
type: "folders",
attributes: {
name: this.name,
extension: {
type: this.type,
version: "1.0",
},
},
relationships: {
parent: {
data: {
type: "folders",
id: this.parent,
},
},
},
},
},
});
$.export("$summary", `Successfully created new folder: ${this.name}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import autodesk from "../../autodesk.app.mjs";

export default {
key: "autodesk-update-file-metadata",
name: "Update File Metadata",
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/)",
version: "0.0.1",
type: "action",
props: {
autodesk,
hubId: {
propDefinition: [
autodesk,
"hubId",
],
},
projectId: {
propDefinition: [
autodesk,
"projectId",
(c) => ({
hubId: c.hubId,
}),
],
},
parent: {
propDefinition: [
autodesk,
"folderId",
(c) => ({
hubId: c.hubId,
projectId: c.projectId,
}),
],
label: "Parent Folder ID",
description: "The identifier of the file's parent folder",
},
fileId: {
propDefinition: [
autodesk,
"fileId",
(c) => ({
projectId: c.projectId,
folderId: c.parent,
}),
],
},
metadata: {
type: "string",
label: "Metadata",
description: "An object containing key-value pairs of the attributes to update. Example: `{ \"displayName\": \"newFileName.jpg\"}`",
},
},
async run({ $ }) {
const response = await this.autodesk.updateMetadata({
$,
projectId: this.projectId,
fileId: this.fileId,
data: {
jsonapi: {
version: "1.0",
},
data: {
type: "items",
id: this.fileId,
attributes: typeof this.metadata === "string"
? JSON.parse(this.metadata)
: this.metadata,
},
},
});
$.export("$summary", `Updated metadata for file ${this.fileId}`);
return response;
},
};
118 changes: 118 additions & 0 deletions components/autodesk/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import autodesk from "../../autodesk.app.mjs";
import fs from "fs";

export default {
key: "autodesk-upload-file",
name: "Upload File",
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/).",
version: "0.0.1",
type: "action",
props: {
autodesk,
hubId: {
propDefinition: [
autodesk,
"hubId",
],
},
projectId: {
propDefinition: [
autodesk,
"projectId",
(c) => ({
hubId: c.hubId,
}),
],
},
folderId: {
propDefinition: [
autodesk,
"folderId",
(c) => ({
hubId: c.hubId,
projectId: c.projectId,
}),
],
},
fileName: {
type: "string",
label: "File Name",
description: "The name of the file to upload",
},
filePath: {
type: "string",
label: "File Path",
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)",
},
},
async run({ $ }) {
// Create storage location
const { data } = await this.autodesk.createStorageLocation({
$,
projectId: this.projectId,
data: {
jsonapi: {
version: "1.0",
},
data: {
type: "objects",
attributes: {
name: this.fileName,
},
relationships: {
target: {
data: {
type: "folders",
id: this.folderId,
},
},
},
},
},
});

const objectId = data.id;
const [
bucketKey,
objectKey,
] = objectId.match(/^urn:adsk\.objects:os\.object:([^/]+)\/(.+)$/);

// Generate signed URL
const {
urls, uploadKey,
} = await this.autodesk.generateSignedUrl({
$,
bucketKey,
objectKey,
});

const signedUrl = urls[0];

// Upload to signed URL
const fileStream = fs.createReadStream(this.filePath.includes("tmp/")
? this.filePath
: `/tmp/${this.filePath}`);

await this.autodesk._makeRequest({
$,
url: signedUrl,
data: fileStream,
headers: {
"Content-Type": "application/octet-stream",
},
});

// Complete the upload
const response = await this.autodesk.completeUpload({
$,
bucketKey,
objectKey,
data: {
uploadKey,
},
});

$.export("$summary", `Successfully uploaded file ${this.fileName}`);
return response;
},
};
Loading
Loading