Skip to content

Commit

Permalink
downloading items from Team Admin Access Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Nov 12, 2021
1 parent 569d69b commit 2fd9825
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var HubsApi = new ForgeSDK.HubsApi(); //Hubs Client
var ProjectsApi = new ForgeSDK.ProjectsApi();
var BucketsApi = new ForgeSDK.BucketsApi(); //Buckets Client
var FoldersApi = new ForgeSDK.FoldersApi();
var ObjectsApi = new ForgeSDK.ObjectsApi();

async function waitUntil(hasCredentials) {
return await new Promise(resolve => {
Expand Down Expand Up @@ -71,11 +72,11 @@ async function waitUntil(hasCredentials) {

// testing

// Team Gavin Hub ID: a.YnVzaW5lc3M6cHVyZHVlMjY5Ng
// Using "Team Admin Access Test" as the test project

const gavinHubID = 'a.YnVzaW5lc3M6cHVyZHVlMjY5Ng';
const adminProjectID = 'a.YnVzaW5lc3M6cHVyZHVlMjY5NiNEMjAyMTA2MDM0MTc3NjkyMDE';
const adminProjectTopFolder = 'urn:adsk.wipprod:fs.folder:co.ExyBofyyS2qP7WOkK7YGSw';
const adminProjectID = 'a.YnVzaW5lc3M6cHVyZHVlMjY5NiMyMDIxMTEwODQ2NDQzMzk3Ng';
const adminProjectTopFolder = 'urn:adsk.wipprod:fs.folder:co.ltuYad4ZTtieJLm6j3MGuA';

HubsApi.getHubs({}, authClient, credentials).then(function(hubs) {
// console.log(hubs.body.data);
Expand All @@ -95,11 +96,54 @@ async function waitUntil(hasCredentials) {
console.log(err)
})

FoldersApi.getFolderContents(adminProjectID, adminProjectTopFolder, {}, authClient, credentials).then(function(content) {
console.log(content.body.data);
var obj;

FoldersApi.getFolderContents(adminProjectID, adminProjectTopFolder, {}, authClient, credentials).then(async function(res) {


// res.body.data includes items, res.body.included has the versions
// we will use versions to download

// items will be downloaded to /download_tests

content = res.body.included;
console.log(content);
for (var i = 0; i < content.length; i++) {
// console.log(content[i].type)
if (content[i].type == "versions") {
var loc = content[i].relationships.storage.data.id
loc = loc.substring(loc.indexOf("/") + 1)
console.log(loc) // bucket location

console.log(content[i].relationships.storage)

var fileName = content[i].attributes.displayName;
var extension = content[i].attributes.name.substring(content[i].attributes.name.indexOf("."));

if (fileName.indexOf(".") == -1) {
fileName = fileName + extension;
}

await ObjectsApi.getObject('wip.dm.prod', loc, {}, authClient, credentials)
.then(async (res) => {
// console.log(res)
await fs.writeFile(`./download_tests/${fileName}`, res.body)
})
.catch((err) => {
console.log("error while processing " + loc);
console.log(err);
});

}
}

}, function(err) {
console.log(err)
})

// var file = await obj;

// even more secret donut id: urn:adsk.wipprod:dm.lineage:VAON-KqMTpWIqGzxw9k42w


})();

0 comments on commit 2fd9825

Please sign in to comment.