// // Name: Egnyte - Find Dead Files // Purpose: To find any files like PDF's or DOCX, XLSX in the folders stated below that have a size of 0KB // TO DO: Make this get a reporting of all of the files with 0kb // FUTURE: Make it so that the script will automatically fix the "dead" files either by looking in previous versions and restoring or by going to lbfs01 and finding the same file and uploading // Created By: Donavon McDowell // Date: 12/5/2023 // var mysql = require('mysql'); require('dotenv').config(); var connection = mysql.createConnection({ host : 'localhost', user : 'me', password : 'secret', database : 'my_db' }); const api_key = process.env.API_KEY //Select your folders here //const folders = ['/Shared/N-Data/14', '/Shared/N-Data/17']; const folders = ['/Shared/IT/Egnyte/Egnyte Testing']; const baseURL = "https://mpe.egnyte.com/pubapi/v1"; function maskMiddleCharacters(inputString) { //Used to mask the middle characters of important items such as API Keys // Check if the input is a string if (typeof inputString !== 'string') { return 'Input is not a string'; } // Get the length of the string const len = inputString.length; if (len < 6) { return inputString; } // Extract the first Four and last Four characters const firstFourChars = inputString.slice(0, 3); const lastFourChars = inputString.slice(-3); // Create a string of stars with the same length as the middle characters const middleStars = '*'.repeat(len - 6); // Concatenate the first Four, middle stars, and last Four characters const maskedString = firstFourChars + middleStars + lastFourChars; return maskedString; } function encodeURI(string){ //Used to encode the URI to be compatible with Egnyte encodedURI = encodeURIComponent(string); encodedURI = encodedURI.replaceAll("%2F" , "/"); //Adds slashs back in encodedURI = encodedURI.replaceAll("-" , "%2D"); //Encodes any "-" to %2D encodedURI = encodedURI.replace("https%3A//mpe.egnyte.com/pubapi/v1", "https://mpe.egnyte.com/pubapi/v1"); //Fixes the URL so it still works return encodedURI; } async function hitApi(base){ //Used to hit the api //To Use: Pass in a string that contains the endpoint you would like to hit I.E: /fs/Shared or /events/cursor base = encodeURI(base); //This runs the encodeURI function to encode the URL to work properly const response = await fetch(base, { method: 'get', headers: new Headers({ 'Authorization': 'Bearer ' + api_key, 'Content-Type': 'application/json' }) }); //DEBUG //console.log(await response.json()); const returnRespone = await response.json(); return returnRespone; } async function fetchData() { for(let i = 0; i < folders.length; i++) { path = baseURL + "/fs" + folders[i]; //Set your folder path here console.log("Location: " + path); data = await hitApi(path); for(let k = 0; k < data.length; i++){ currentPath = path + data.folders[k].name; console.log(currentPath); } //DEBUGGING ONLY! COMMENT THE LINE UNDER THIS OUT TO STOP THE OUTPUT console.log(data); } } console.log("*****************************"); console.log(""); console.log("Egnyte - Find Dead Files 💀"); console.log(""); console.log("API KEY: " + maskMiddleCharacters(api_key)); console.log("ASSIGNED FOLDERS: " + folders); console.log(""); console.log("*****************************"); fetchData();