MiWatchKleaner/lib/files.js

46 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-04-24 20:42:45 +01:00
const fs = require('fs');
const path = require('path');
2020-04-25 16:56:23 +01:00
const dl = require('download-file-with-progressbar');
2020-04-24 20:42:45 +01:00
module.exports = {
getCurrentDirectoryBase: () => {
return path.basename(process.cwd());
},
directoryExists: (filePath) => {
return fs.existsSync(filePath);
2020-04-25 10:27:17 +01:00
},
writeIpAddress: (value) => {
const data = {
ipAddress: value
}
try {
fs.writeFileSync('./data/MiWatch.json', JSON.stringify(data))
} catch (err) {
console.log(err)
}
},
2020-04-25 10:44:12 +01:00
loadPackageList: () => {
try {
const packageList = JSON.parse(fs.readFileSync('./data/packageList.json', 'utf8'));
return packageList
} catch (err) {
console.log(err)
}
},
2020-04-25 16:56:23 +01:00
downloadFile: async (element) => {
option = {
dir: './data/apps',
onDone: (info)=>{
console.log(element.name + ' Downloaded')
},
onError: (err) => {
console.log('error', err);
},
onProgress: (curr, total) => {
},
}
var dd = dl(element.url, option);
}
2020-04-24 20:42:45 +01:00
};