From e4250f1e881454ddde9d55c97fb3e566aedfa057 Mon Sep 17 00:00:00 2001 From: pan261 Date: Wed, 19 Jan 2022 14:41:16 -0500 Subject: [PATCH] added 'npm run docker:build' script --- package-lock.json | 12 ++++++------ package.json | 3 ++- src/server.ts | 5 +++++ src/taskRunner.ts | 44 ++++++++++++++++++++++---------------------- src/watcher2.ts | 22 ++++++++++++++++++++++ 5 files changed, 57 insertions(+), 29 deletions(-) create mode 100644 src/watcher2.ts diff --git a/package-lock.json b/package-lock.json index 3f1ddbb..6f315b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1453,9 +1453,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.14.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz", - "integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==", + "version": "1.14.7", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", + "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==", "funding": [ { "type": "individual", @@ -4296,9 +4296,9 @@ "dev": true }, "follow-redirects": { - "version": "1.14.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz", - "integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==" + "version": "1.14.7", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", + "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==" }, "forever-agent": { "version": "0.6.1", diff --git a/package.json b/package.json index cc46461..9e68cc0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/server.ts b/src/server.ts index 2aa3001..ef48fe2 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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); diff --git a/src/taskRunner.ts b/src/taskRunner.ts index 1e4b9ec..2ee3c55 100644 --- a/src/taskRunner.ts +++ b/src/taskRunner.ts @@ -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); diff --git a/src/watcher2.ts b/src/watcher2.ts new file mode 100644 index 0000000..12ff73b --- /dev/null +++ b/src/watcher2.ts @@ -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); + }); +} \ No newline at end of file