From 661e355de3379d131125324b9a33c6942b43e114 Mon Sep 17 00:00:00 2001 From: "Williams, Gavin J" Date: Fri, 4 Feb 2022 09:47:51 -0500 Subject: [PATCH] Support for updating versions added. [UNTESTED] --- src/uploadfile.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/uploadfile.ts b/src/uploadfile.ts index 638d73d..5f373ed 100644 --- a/src/uploadfile.ts +++ b/src/uploadfile.ts @@ -2,10 +2,11 @@ import * as ForgeSDK from 'forge-apis'; import * as config from './config'; import * as fs from 'fs'; +const jsonVersion: ForgeSDK.JsonApiVersionJsonapi = {version: "1.0"} const projectsAPI = new ForgeSDK.ProjectsApi(); +const versionsAPI = new ForgeSDK.VersionsApi(); const objectsAPI = new ForgeSDK.ObjectsApi(); const itemsAPI = new ForgeSDK.ItemsApi(); -const jsonVersion: ForgeSDK.JsonApiVersionJsonapi = {version: "1.0"} function getCreateStorageDataObject(fileName: string, folderID: string): ForgeSDK.CreateStorageData { const content: ForgeSDK.CreateStorageData = { @@ -81,6 +82,31 @@ function getCreateItemIncludedObject(fileName: string, objectID: string): ForgeS return content; } +function getCreateVersionData(fileName: string, itemID: string):ForgeSDK.CreateVersionData { + const data:ForgeSDK.CreateVersionData = { + type: "versions", + attributes: { + name: fileName, + extension: { + type: "versions:autodesk.core:File", + version: "1.0", + schema: { + href: "" + } + } + }, + relationships: { + storage: { + data: { + type: "items", + id: itemID + } + } + } + } + return data; +} + /** * Wrapper for: @function ItemsApi.postItem() * Builds JSON to link bucket data to fusion folders @@ -205,4 +231,26 @@ export function uploadFile(fileName: string, folderName: string, credentials: Fo return false; } ); +} + + + +export function newVersion(fileName: string, folderName: string, credentials: ForgeSDK.AuthToken) { + const folderID: string = config.folderMap[folderName].fusionID; + const body: ForgeSDK.CreateVersion = { + jsonapi: jsonVersion, + data: getCreateVersionData(fileName, "") + } + versionsAPI.postVersion(folderID, body, config.authClient, credentials).then( + (resp: ForgeSDK.ApiResponse) => { + if (resp.statusCode != 201) { + console.log("Allocate Storage Error: ", resp.statusCode); + return true; + } + }, + (err: ForgeSDK.ApiError) => { + console.log("API ERROR CODE: ", err.statusCode, "\nMESSAGE: ", err.statusMessage, "\nBODY: ", err.statusBody); + return false; + } + ); } \ No newline at end of file