-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
const axios = require('axios'); | ||
|
||
/** | ||
* Watches given folder id in the project, dispatches downloader for any files needing to be updated | ||
* @param {String} projectId the project id | ||
* @param {String} folderId the folder id | ||
* @param {Object} credentials credentials for the call | ||
* @param {Integer} interval number of seconds used to filter the date | ||
* if an interval is not passed, watcher will loop through all files in the folder | ||
*/ | ||
exports.watch = (projectID, folderID, credentials, interval) => { | ||
|
||
var timeFilter = {}; | ||
|
||
if (interval) { | ||
var dateNow = new Date(); | ||
var dateXSecondsAgo = new Date(dateNow.getTime() - interval * 1000); | ||
timeFilter = {'filter[lastModifiedTime]-ge': dateXSecondsAgo.toISOString()} | ||
} | ||
|
||
axios({ | ||
method: 'GET', | ||
url: `https://developer.api.autodesk.com//data/v1/projects/${projectID}/folders/${folderID}/contents`, | ||
headers: { | ||
'Authorization': `Bearer ${credentials.access_token}` | ||
}, | ||
params: timeFilter, | ||
}) | ||
.then(res => { | ||
return res.data.included; | ||
}) | ||
.then(data => { | ||
if (data === undefined) { // no new files changed, return | ||
return; | ||
} | ||
|
||
for (var index in data) { | ||
// console.log(data[index]); | ||
var lastModifiedTime = data[index].attributes.lastModifiedTime; | ||
console.log(lastModifiedTime); | ||
|
||
// TODO: if item is not in db, add to db and then download | ||
|
||
// TODO: if item is in db, check and compare lastModifiedTime | ||
|
||
} | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} |