Skip to content

Commit

Permalink
Connected taskRunner to fileUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
will1742 committed Feb 2, 2022
1 parent e340f70 commit 78dfebc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/localhook.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/taskRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand All @@ -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});
Expand Down Expand Up @@ -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:',
Expand Down Expand Up @@ -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]);
4 changes: 2 additions & 2 deletions src/uploadfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
Expand Down Expand Up @@ -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;
}
);
Expand Down

0 comments on commit 78dfebc

Please sign in to comment.