diff --git a/src/localhook.ts b/src/localhook.ts index de9bc11..be226be 100644 --- a/src/localhook.ts +++ b/src/localhook.ts @@ -1,9 +1,15 @@ import * as chokidar from 'chokidar'; +import { AuthToken } from 'forge-apis'; +import * as uploader from './uploadfile'; const polltime: number = 100; let [file, folder]: string = ""; +let credentials: AuthToken; +export function setCredentials(creds: AuthToken) { + credentials = creds; +} /* Gavin Williams | will1742 | 01/19/22 * Initialize watcher for windows file system @@ -62,7 +68,13 @@ watcher.on('add', (path: string) => { console.log("Invalid Path"); return; } - console.log(file + ' has been added to ' + folder); + console.log(file + ' locally added to ' + folder); + console.log( + '\x1b[93mlocalhook.js::add:', + '\x1b[0mAttempting upload...' + ); + + uploader.uploadFile(file, folder.toLowerCase(), credentials); }); /* Gavin Williams | will1742 | 01/19/22 diff --git a/src/taskRunner.ts b/src/taskRunner.ts index eefa8b9..21dbdf5 100644 --- a/src/taskRunner.ts +++ b/src/taskRunner.ts @@ -4,6 +4,7 @@ const downloader = require('./downloader'); const fs = require('fs'); import { AuthToken } from 'forge-apis'; import * as config from './config'; +import * as localhook from './localhook'; import * as uploader from './uploadfile'; @@ -28,7 +29,6 @@ const localPath = config.folderMap[process.argv[3]].local; const localDir = __dirname + '/FileShare' + localPath; console.log(folderID, localDir); - if (!fs.existsSync(localDir)) { console.log("Local directory:", localDir, "not found, creating it now"); fs.mkdirSync(localDir, {recursive: true}); @@ -65,6 +65,7 @@ const fetchToken = () => { // console.log(res.data); if (Object.keys(res.data).length == 5) { credentials = res.data; + localhook.setCredentials(credentials); clearInterval(initInterval); console.log( '\x1b[92mtaskRunner.js::fetchToken:', @@ -140,4 +141,4 @@ getCredentials(); // and how often it runs. We may need to test this out. // setInterval(dispatchWatcher, 5000, 7000); -setInterval(uploadTest, 5000, process.argv[2], process.argv[3]); +// setInterval(uploadTest, 5000, process.argv[2], process.argv[3]); diff --git a/src/uploadfile.ts b/src/uploadfile.ts index 54c5ee6..638d73d 100644 --- a/src/uploadfile.ts +++ b/src/uploadfile.ts @@ -154,7 +154,7 @@ function uploadFileObject(fileName: string, folderName: string, objectID: string return createItem(fileName, config.folderMap[folderName].fusionID, objectID, credentials); }, (err: ForgeSDK.ApiError) => { - console.log("Upload File Error: " + err.statusCode); + console.log("API ERROR CODE: ", err.statusCode, "\nMESSAGE: ", err.statusMessage, "\nBODY: ", err.statusBody); return false; } ); @@ -201,7 +201,7 @@ export function uploadFile(fileName: string, folderName: string, credentials: Fo return uploadFileObject(fileName, folderName, objectID, credentials); }, (err: ForgeSDK.ApiError) => { - console.log("Post Storage Error: " + err.statusCode); + console.log("API ERROR CODE: ", err.statusCode, "\nMESSAGE: ", err.statusMessage, "\nBODY: ", err.statusBody); return false; } );