-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfiles.js
34 lines (27 loc) · 1.03 KB
/
files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const recursive = require("recursive-readdir");
const fs = require("fs");
const path = require("path");
const getFiles = async (filePath) => {
const pathToCheck = path.resolve(filePath);
try {
const fileList = await recursive(pathToCheck);
return await fileList.filter(filePath => path.extname(filePath) === ".mp4");
}
catch (error) {
console.log(`Failed to traverse directories: ${ error }`);
}
};
const removeFile = (filePath) => {
const pathToDelete = path.resolve(filePath);
fs.unlink(pathToDelete, (error) => {
if(error) return console.log(`Failed to delete file: ${ error }`);
console.log(path.basename(pathToDelete) + " deleted...");
});
};
const writeLogFile = async (path, contents) => {
const { uploadStatus, file, urlID } = contents;
const log = fs.createWriteStream(path, { flags: "a" });
log.write(`${ file } - https://youtu.be/${ urlID } - ${ uploadStatus }\n`);
log.end();
};
module.exports = { getFiles, removeFile, writeLogFile };