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
foldersApi.getFolderRelationshipsRefs('', '', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
foldersApi.postFolder('', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
foldersApi.postFolderRelationshipsRef('', '', {}, authClientTwoLegged, authToken);
// $ExpectType HubsApi
const hubsApi = new HubsApi();
// $ExpectType Promise
hubsApi.getHub('', authClientTwoLegged, authToken);
// $ExpectType Promise
hubsApi.getHubs({}, authClientTwoLegged, authToken);
// $ExpectType ItemsApi
const itemsApi = new ItemsApi();
// $ExpectType Promise
itemsApi.getItem('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
itemsApi.getItemParentFolder('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
itemsApi.getItemRefs('', '', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
itemsApi.getItemRelationshipsRefs('', '', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
itemsApi.getItemTip('', '', authClientTwoLegged, authToken);
// $ExpectType Promise
itemsApi.getItemVersions('', '', {}, authClientTwoLegged, authToken);
// $ExpectType Promise
itemsApi.postItem('', { included: [{ type: '', id: '' }] }, authClientTwoLegged, authToken);
// $ExpectType Promise
itemsApi.postItemRelationshipsRef('', '', {}, authClientTwoLegged, authToken);
const destinateFolderId = destinateFolderParams[destinateFolderParams.length - 1];
const destinateProjectId = destinateFolderParams[destinateFolderParams.length - 3];
try {
////////////////////////////////////////////////////////////////////////////////
// get the storage of the input item version
const versionInfo = await getLatestVersionInfo(sourceProjectId, sourceFileId, req.oauth_client, req.oauth_token);
if (versionInfo === null) {
console.log('error: failed to get lastest version of the file');
res.status(500).end('failed to get lastest version of the file');
return;
}
const inputUrl = versionInfo.versionUrl;
const items = new ItemsApi();
const sourceFile = await items.getItem(sourceProjectId, sourceFileId, req.oauth_client, req.oauth_token);
if (sourceFile === null || sourceFile.statusCode !== 200) {
console.log('error: failed to get the current file item.');
res.status(500).end('failed to get the current file item');
return;
}
const fileName = sourceFile.body.data.attributes.displayName;
const itemType = sourceFile.body.data.attributes.extension.type;
const fileParams = fileName.split('.');
const fileExtension = fileParams[fileParams.length-1].toLowerCase();
if( fileExtension !== 'rvt' && fileExtension !== 'rfa' && fileExtension !== 'fte'){
console.log('info: the file format is not supported');
res.status(500).end('the file format is not supported');
return;
}
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) {
// Get the versionId out of the reply
_resolve(itemData.body.included[0].id);
})
.catch(function (error) {
console.log('postItem: failed');
_reject(error);
});
}
})
.catch(function (error) {
.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);
});
})
.catch(function (error) {
const params = fileItemId.split('/');
if( params.length < 3){
res.status(500).end('selected item id has problem');
}
const resourceName = params[params.length - 2];
if (resourceName !== 'items') {
res.status(500).end('not supported item');
return;
}
const resourceId = params[params.length - 1];
const projectId = params[params.length - 3];
try {
const items = new ItemsApi();
const folder = await items.getItemParentFolder(projectId, resourceId, req.oauth_client, req.oauth_token);
if(folder === null || folder.statusCode !== 200){
console.log('failed to get the parent folder.');
res.status(500).end('ailed to get the parent folder');
return;
}
const fileParams = fileItemName.split('.');
const fileExtension = fileParams[fileParams.length-1].toLowerCase();
if( fileExtension !== 'rvt' && fileExtension !== 'rfa' && fileExtension !== 'fte'){
console.log('info: the file format is not supported');
res.status(500).end('the file format is not supported');
return;
}
const storageInfo = await getNewCreatedStorageInfo(projectId, folder.body.data.id, fileItemName, req.oauth_client, req.oauth_token);
return;
}
var params = autodeskItem.split('/');
var itemId = params[params.length - 1];
var projectId = params[params.length - 3];
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 items = new forgeSDK.ItemsApi();
items.getItemVersions(projectId, itemId, {}, forge3legged, token.getForgeCredentials())
.then(function (versions) {
var moment = require('moment');
var lastVersionId;
var newestVersion = moment('2000-01-01');
versions.body.data.forEach(function (version) {
var versionDate = moment(version.attributes.lastModifiedTime);
if (versionDate.isAfter(newestVersion)) {
newestVersion = versionDate;
lastVersionId = version.links.self.href;
}
});
callback(lastVersionId);
})
.catch(function (error) {
function getVersions(projectId, itemId, tokenSession, res) {
var items = new forgeSDK.ItemsApi();
items.getItemVersions(projectId, itemId, {}, tokenSession.getInternalOAuth(), tokenSession.getInternalCredentials())
.then(function (versions) {
var versionsForTree = [];
versions.body.data.forEach(function (version) {
var lastModifiedTime = moment(version.attributes.lastModifiedTime);
var days = moment().diff(lastModifiedTime, 'days');
var fileType = version.attributes.fileType;
var dateFormated = (versions.body.data.length > 1 || days > 7 ? lastModifiedTime.format('MMM D, YYYY, h:mm a') : lastModifiedTime.fromNow());
var designId = (version.relationships != null && version.relationships.derivatives != null ? version.relationships.derivatives.data.id : null);
var fileName = version.attributes.fileName;
var versionst = version.id.match(/^(.*)\?version=(\d+)$/) [2];
versionsForTree.push(prepareItemForTree(
designId,
decodeURI('v' + versionst + ': ' + dateFormated + ' by ' + version.attributes.lastModifiedUserName),
'versions',
false,
function getVersions(projectId, itemId, oauthClient, credentials, res) {
var items = new forgeSDK.ItemsApi();
items.getItemVersions(projectId, itemId, {}, oauthClient, credentials)
.then(function (versions) {
var versionsForTree = [];
var moment = require('moment');
versions.body.data.forEach(function (version) {
var lastModifiedTime = moment(version.attributes.lastModifiedTime);
var days = moment().diff(lastModifiedTime, 'days')
var dateFormated = (versions.body.data.length > 1 || days > 7 ? lastModifiedTime.format('MMM D, YYYY, h:mm a') : lastModifiedTime.fromNow());
var versionst = version.id.match(/^(.*)\?version=(\d+)$/)[2];
versionsForTree.push(prepareItemForTree(
version.links.self.href,
decodeURI('v' + versionst + ': ' + dateFormated + ' by ' + version.attributes.lastModifiedUserName),
(unsupported.indexOf(version.attributes.createUserName) == -1 ? 'versions' : 'unsupported'),
false
));
});