Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// $ExpectType Promise
projectsApi.getProject('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
projectsApi.getProjectHub('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
projectsApi.getProjectTopFolders('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
projectsApi.postStorage('', {}, authClientTwoLegged, authToken);
// $ExpectType UserProfileApi
const userProfileApi = new UserProfileApi();
// $ExpectType Promise
userProfileApi.getUserProfile(authClientTwoLegged, authToken);
// $ExpectType VersionsApi
const versionsApi = new VersionsApi();
// $ExpectType Promise
versionsApi.getVersion('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
versionsApi.getVersionItem('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
versionsApi.getVersionRefs('', '', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
versionsApi.getVersionRelationshipsRefs('', '', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
versionsApi.postVersion('', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
versionsApi.postVersion('', {}, authClientTwoLegged, authToken);
// $ExpectType WorkItemsApi
const workItemsApi = new WorkItemsApi();
// $ExpectType Promise
getVersion: function (versionUrl, req, callback) {
var params = decodeURIComponent(versionUrl).split('/');
var projectId = params[params.length - 3];
var versionId = params[params.length - 1];
var token = new Credentials(req.session);
var forge3legged = new forgeSDK.AuthClientThreeLegged(
config.forge.credentials.client_id,
config.forge.credentials.client_secret,
config.forge.callbackURL,
config.forge.scope,
true);
var versions = new forgeSDK.VersionsApi();
versions.getVersion(projectId, versionId, forge3legged, token.getForgeCredentials())
.then(function (version) {
//adam if (!version.body.data.relationships.storage || !version.body.data.relationships.storage.meta.link.href) {
// return;
//}
callback(version.body.data)
})
.catch(function (error) {
console.log(error);
});
},
.then(function (folderData) {
var item = null;
for (var key in folderData.body.data) {
item = folderData.body.data[key];
if (item.attributes.displayName === fileName) {
break;
} else {
item = null;
}
}
if (item) {
// We found it so we should create a new version
var versions = new forgeSDK.VersionsApi();
var body = versionSpecData(fileName, projectId, item.id, objectId);
versions.postVersion(projectId, body, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function (versionData) {
_resolve(versionData.body.data.id);
})
.catch(function (error) {
console.log('postVersion: failed');
_reject(error);
});
} else {
// We did not find it so we should create it
var items = new forgeSDK.ItemsApi();
var body = itemSpecData(fileName, projectId, folderId, objectId);
items.postItem(projectId, body, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function (itemData) {
return new Promise(function (_resolve, _reject) {
var tokenSession = new token(req.session);
// Ask for storage for the new file we want to upload
var versions = new forgeSDK.VersionsApi();
var body = attachmentSpecData(attachmentVersionId, projectId);
versions.postVersionRelationshipsRef(projectId, versionId, body, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function () {
_resolve();
})
.catch(function(error) {
console.log('postVersionRelationshipsRef: failed');
_reject(error);
});
});
}
return new Promise(function (_resolve, _reject) {
// Figure out the itemId of the file we want to attach the new file to
var tokenSession = new token(req.session);
var versions = new forgeSDK.VersionsApi();
versions.getVersion(projectId, versionId, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function (versionData) {
var itemId = versionData.body.data.relationships.item.data.id;
// Figure out the folderId of the file we want to attach the new file to
var items = new forgeSDK.ItemsApi();
items.getItem(projectId, itemId, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function (itemData) {
var folderId = itemData.body.data.relationships.parent.data.id;
_resolve(folderId);
})
.catch(function (error) {
console.log(error);
_reject(error);
.then(function (folderData) {
var item = null;
for (var key in folderData.body.data) {
item = folderData.body.data[key];
if (item.attributes.displayName === fileName || item.attributes.displayName === withoutExtension(fileName)) {
break;
} else {
item = null;
}
}
if (item) {
// We found it so we should create a new version
var versions = new forgeSDK.VersionsApi();
versions.postVersion(projectId, versionSpecData(fileName, projectId, item.id, objectId), forge3legged, credentials)
.then(function (versionData) {
callback()
})
.catch(function (error) {
console.log(error);
});
} else {
// We did not find it so we should create it
var items = new forgeSDK.ItemsApi();
items.postItem(projectId, itemSpecData(fileName, projectId, folderId, objectId), forge3legged, credentials)
.then(function (itemData) {
callback()
})
.catch(function (error) {
console.log(error);
} )
if( workitem === undefined ){
console.log('The workitem: ' + req.body.id+ ' to callback is not in the item list')
return;
}
let index = workitemList.indexOf(workitem);
workitemStatus.Status = 'Success';
global.MyApp.SocketIo.emit(SOCKET_TOPIC_WORKITEM, workitemStatus);
console.log("Post handle the workitem: " + workitem.workitemId);
const type = workitem.createVersionData.data.type;
try {
let version = null;
if(type === "versions"){
const versions = new VersionsApi();
version = await versions.postVersion(workitem.projectId, workitem.createVersionData, req.oauth_client, workitem.access_token_3Legged);
}else{
const items = new ItemsApi();
version = await items.postItem(workitem.projectId, workitem.createVersionData, req.oauth_client, workitem.access_token_3Legged);
}
if( version === null || version.statusCode !== 201 ){
console.log('Falied to create a new version of the file');
workitemStatus.Status = 'Failed'
}else{
console.log('Successfully created a new version of the file');
workitemStatus.Status = 'Completed';
}
global.MyApp.SocketIo.emit(SOCKET_TOPIC_WORKITEM, workitemStatus);
} catch (err) {
console.log(err);
router.get('/attachments', function (req, res) {
var tokenSession = new token(req.session);
var href = decodeURIComponent(req.query.href);
var params = href.split('/');
var projectId = params[params.length - 3];
var versionId = params[params.length - 1];
var versions = new forgeSDK.VersionsApi();
versions.getVersionRelationshipsRefs(projectId, versionId, {}, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function (relationshipsData) {
var versionRequests = [];
for (var key in relationshipsData.body.data) {
var item = relationshipsData.body.data[key];
if (item.meta.extension.type === "auxiliary:autodesk.core:Attachment") {
(function (relationshipItem) {
var versionRequest = new Promise(function (_resolve, _reject) {
versions.getVersion(projectId, relationshipItem.id, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function (versionData) {
relationshipItem.displayName =
versionData.body.data.attributes.displayName +
" (v" + versionData.body.data.attributes.versionNumber + ")";
_resolve();
})
.catch(function (error) {
constructor(config) {
super(config)
this._projectsAPI = new Forge.ProjectsApi()
this._versionsAPI = new Forge.VersionsApi()
this._foldersAPI = new Forge.FoldersApi()
this._itemsAPI = new Forge.ItemsApi()
this._hubsAPI = new Forge.HubsApi()
}
constructor(config) {
super(config)
this._projectsAPI = new Forge.ProjectsApi()
this._versionsAPI = new Forge.VersionsApi()
this._foldersAPI = new Forge.FoldersApi()
this._itemsAPI = new Forge.ItemsApi()
this._hubsAPI = new Forge.HubsApi()
}