Skip to content

Commit

Permalink
js to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Dec 2, 2021
1 parent f9b79db commit 3b8c3de
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 218 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
node_modules

credentials.json
download_tests
download_tests
dist
36 changes: 0 additions & 36 deletions src/config.js

This file was deleted.

25 changes: 7 additions & 18 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,28 @@ export const authClient = new ForgeAuthClient(
true
);

export const fileShareProjectID = "a.YnVzaW5lc3M6cHVyZHVlMjY5NiMyMDIxMTExNTQ2Njg0NTI1MQ";
export const projectID = "a.YnVzaW5lc3M6cHVyZHVlMjY5NiMyMDIxMTExNTQ2Njg0NTI1MQ";

export const folderMap = {
export const folderMap: any = {
gantry: {
fusionID: "urn:adsk.wipprod:fs.folder:co.IxiedfeBTOGg6NSIGQhXxQ",
local: "File Share/Gantry"
local: "../../File Share/Gantry"
},
lathe: {
fusionID: "urn:adsk.wipprod:fs.folder:co.FDWCeyBGQX2rv8xSNWo5lg",
local: "File Share/Lathe"
local: "../../File Share/Lathe"
},
mill: {
fusionID: "urn:adsk.wipprod:fs.folder:co.nEihcpHUSW-ZsVzU-__1iw",
local: "File Share/Mill"
local: "../../File Share/Mill"
},
waterjet: {
fusionID: "urn:adsk.wipprod:fs.folder:co.vJLXAKGbQQayeljr-nwztQ",
local: "File Share/Waterjet"
local: "../../File Share/Waterjet"
}
};

export const port = process.env.PORT;
export const forgeClientId = process.env.FORGE_CLIENT_ID;
export const forgeClientSecret = process.env.FORGE_CLIENT_SECRET;
export const forgeCallbackURL = process.env.FORGE_CALLBACK_URL;

// export = {
// authClient: authClient,
// scopes: scopes,
// projectID: fileShareProjectID,
// folderMap: folderMap,
// port: process.env.PORT,
// forgeClientId: process.env.FORGE_CLIENT_ID,
// forgeClientSecret: process.env.FORGE_CLIENT_SECRET,
// forgeCallbackURL: process.env.FORGE_CALLBACK_URL
// }
export const forgeCallbackURL = process.env.FORGE_CALLBACK_URL;
16 changes: 8 additions & 8 deletions src/downloader.js → src/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ const config = require('./config');
const ObjectsApi = new ForgeSDK.ObjectsApi();

/**
* Kevin Pan | pan261@purdue.edu | Last Modified: 11/30/2021
* Kevin Pan | pan261@purdue.edu | Last Modified: 12/2/2021
*
* Downloads a file by using the Forge SDK to make a GET request
* on the storageLocation and then saves the file as `filename` under the `destination` directory
* @param {String} storageLocation
* @param {String} fileName
* @param {String} destination
* @param {string} storageLocation
* @param {string} fileName
* @param {string} destination
* @param {Object} credentials
*/
exports.download = (storageLocation, fileName, destination, credentials) => {
exports.download = (storageLocation: string, fileName: string, destination: string, credentials: any) => {

ObjectsApi.getObject('wip.dm.prod', storageLocation, {}, config.authClient, credentials)
.then((res) => {
.then((res: any) => {
console.log(res)
fs.writeFile(`./${destination}/${fileName}`, res.body)
fs.writeFile(`${__dirname}/${destination}/${fileName}`, res.body)
})
.catch((err) => {
.catch((err: any) => {
console.log("error while processing " + storageLocation);
console.log(err);
});
Expand Down
129 changes: 0 additions & 129 deletions src/server.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as express from 'express';
import express = require('express');
import * as config from './config';


/**
* Kevin Pan | pan261@purdue.edu | Last Modified: 11/22/2021
* Kevin Pan | pan261@purdue.edu | Last Modified: 12/2/2021
*
* Authentication server used to perform 3-legged auth through browser.
*
Expand Down
33 changes: 18 additions & 15 deletions src/taskRunner.js → src/taskRunner.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const axios = require('axios');
const watcher = require('./watcher');
const downloader = require('./downloader');
const config = require('./config');
import * as config from './config';


/**
* Kevin Pan | pan261@purdue.edu | Last Modified: 11/30/2021
* Kevin Pan | pan261@purdue.edu | Last Modified: 12/2/2021
*
* This file will be responsible for managing the watcher
* as well as fetching the credentials from the server
Expand All @@ -19,15 +20,17 @@ const projectID = ""

// parse command line arguments from docker-compose to get folder ID

const folderID = config.folderIdMap[process.argv[2]];
console.log(folderID);
const folderID = config.folderMap[process.argv[2]].fusionID;
const localDir = config.folderMap[process.argv[2]].local;

console.log(folderID, localDir);

const adminProjectID = 'a.YnVzaW5lc3M6cHVyZHVlMjY5NiMyMDIxMTEwODQ2NDQzMzk3Ng';
const adminProjectTopFolder = 'urn:adsk.wipprod:fs.folder:co.ltuYad4ZTtieJLm6j3MGuA';
// const adminProjectID = 'a.YnVzaW5lc3M6cHVyZHVlMjY5NiMyMDIxMTEwODQ2NDQzMzk3Ng';
// const adminProjectTopFolder = 'urn:adsk.wipprod:fs.folder:co.ltuYad4ZTtieJLm6j3MGuA';

let credentials = null;
let initInterval = null;
let updateInterval = null;
let credentials: any = null;
let initInterval: any = null;
let updateInterval: any = null;

/**
* Sends GET request to get token from auth server
Expand All @@ -41,7 +44,7 @@ const fetchToken = () => {
method: 'GET',
url: 'http://localhost:3000/credentials'
})
.then(res => {
.then((res: any) => {
// console.log(res.data);
if (Object.keys(res.data).length == 5) {
credentials = res.data;
Expand All @@ -57,7 +60,7 @@ const fetchToken = () => {
);
}
})
.catch(err => {
.catch((err: any) => {
console.log(
'\x1b[91mtaskRunner.js::fetchToken:',
'\x1b[0mError accessing localhost:3000/credentials'
Expand Down Expand Up @@ -85,7 +88,7 @@ const getCredentials = () => {
/**
* Function to dispatch the watcher
*/
const dispatchWatcher = async (interval) => {
const dispatchWatcher = async (interval: any) => {
if (credentials === null) {
console.log(
'\x1b[93mtaskRunner.js::dispatchWatcher:',
Expand All @@ -94,15 +97,15 @@ const dispatchWatcher = async (interval) => {
return;
}

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

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

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

Expand Down
Loading

0 comments on commit 3b8c3de

Please sign in to comment.