Skip to content

Commit

Permalink
added 'npm run docker:build' script
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Jan 19, 2022
1 parent 2828da6 commit e4250f1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 29 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"start": "node /src/server.js",
"test": "echo \"Error: no test specified\" && exit 1",
"tsc": "tsc"
"tsc": "tsc",
"docker:build": "tsc && docker-compose up --build"
},
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ const createServer = () => {
}
});

app.post('/hook', function (req: any, res: any) {
console.log(req.body);
res.status(200).end;
});

// Default endpoint
app.use((err: any, req: any, res: any, next: any) => {
console.error(err);
Expand Down
44 changes: 22 additions & 22 deletions src/taskRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,33 @@ const getCredentials = () => {
updateInterval = setInterval(fetchToken, 3300 * 1000);
};

getCredentials();

/**
* Function to dispatch the watcher
*/
const dispatchWatcher = async (interval: any) => {
if (credentials === null) {
console.log(
'\x1b[93mtaskRunner.js::dispatchWatcher:',
'\x1b[0mNo credentials'
);
return;
}
// const dispatchWatcher = async (interval: any) => {
// if (credentials === null) {
// console.log(
// '\x1b[93mtaskRunner.js::dispatchWatcher:',
// '\x1b[0mNo credentials'
// );
// return;
// }

const items = await watcher.watch(config.projectID, folderID, credentials, interval);
// const items = await watcher.watch(config.projectID, folderID, credentials, interval);

if (Object.keys(items).length == 0) {
return; // no items to download
}

for (var index in items) {
// dispatch the downloader here
downloader.download(items[index].location, items[index].name, __dirname + '/' + localDir, credentials);
}
};
// if (Object.keys(items).length == 0) {
// return; // no items to download
// }

getCredentials();
// for (var index in items) {
// // dispatch the downloader here
// downloader.download(items[index].location, items[index].name, __dirname + '/' + localDir, credentials);
// }
// };

// There should be a buffer between how far back the watcher checks
// and how often it runs. We may need to test this out.
setInterval(dispatchWatcher, 5000, 7000);
// // There should be a buffer between how far back the watcher checks
// // and how often it runs. We may need to test this out.
// setInterval(dispatchWatcher, 5000, 7000);

22 changes: 22 additions & 0 deletions src/watcher2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// const axios = require('axios');

exports.watch = (credentials: any) => {
axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/webhooks/v1/systems/data/events/dm.version.added/hooks',
headers: {
Authorization: `Bearer ${credentials.access_token}`
},
body: {
callbackUrl: "http://localhost:3000/hook",
autoReactivateHook: false,
scope: {
folder: "urn:adsk.wipprod:fs.folder:co.IxiedfeBTOGg6NSIGQhXxQ" // Gantry folder
}
}
}).then((res: any) => {
console.log(res.data);
}).catch((err: any) => {
console.log(err);
});
}

0 comments on commit e4250f1

Please sign in to comment.