Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
res.status(500).json({error: 'Cannot get Google user information, please try again.'});
return;
}
// ForgeSDK OSS Bucket Name: username + userId (no spaces, lower case)
// that way we have one bucket for each Google account using this application
var ossBucketKey =
config.credentials.client_id.toLowerCase() +
(
user.names[0].displayName.replace(/\W+/g, '') +
user.resourceName.split('/')[1]
).toLowerCase();
var buckets = new ForgeSDK.BucketsApi();
var objects = new ForgeSDK.ObjectsApi();
var postBuckets = new ForgeSDK.PostBucketsPayload();
postBuckets.bucketKey = ossBucketKey;
postBuckets.policyKey = "transient"; // expires in 24h
buckets.createBucket(postBuckets, {}, null, tokenInternal).catch(function (err) {console.log(err);}).then(function () {
// need the Google file information to get the name...
drive.files.get({
fileId: googleFileId
}, function (err, fileInfo) {
var fileName = fileInfo.title;
var ossObjectName = googleFileId + '.' + re.exec(fileName)[1]; // googleId + fileExtension (required)
// at this point the bucket exists (either created or already there)
objects.getObjects(ossBucketKey, {'limit': 100}, null, tokenInternal).then(function (response) {
var alreadyTranslated = false;
var objectsInBucket = response.body.items;
objectsInBucket.forEach(function (item) {
new Token().getTokenInternal((tokenInternal, apiInstance) => {
let buckets = new ForgeSDK.BucketsApi();
// let objects = new ForgeSDK.ObjectsApi()
let postBuckets = new ForgeSDK.PostBucketsPayload();
postBuckets.bucketKey = myBucketKey;
postBuckets.policyKey = 'persistent';
buckets.createBucket(postBuckets, null, apiInstance, tokenInternal).then(() => {
let mineType = getMineType(filePath);
let fs = require('fs');
fs.readFile(filePath, function (err, filecontent) {
if (err) { errHandler(err, res); res.status(500).end('Error occurred ...'); return; }
request({
url: 'https://developer.api.autodesk.com/oss/v2/buckets/' + myBucketKey + '/objects/' + fileName,
method: 'PUT',
headers: {
'Authorization': 'Bearer ' + tokenInternal.access_token,
'Content-Type': mineType
},