Skip to content

Commit

Permalink
Support for updating versions added. [UNTESTED]
Browse files Browse the repository at this point in the history
  • Loading branch information
will1742 committed Feb 4, 2022
1 parent 99a95f9 commit 661e355
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/uploadfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
);
}

0 comments on commit 661e355

Please sign in to comment.