first commit

This commit is contained in:
Myk
2025-07-31 23:47:20 +03:00
commit 2186b278a0
5149 changed files with 537218 additions and 0 deletions

50
node_modules/node-downloader-helper/bin/helpers.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
/*eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */
const { URL } = require('url');
const { existsSync } = require('fs');
// Console colors
module.exports.COLOR_NC = '\x1b[0m'; // No Color \e
module.exports.COLOR_RED = '\x1b[0;31m';
module.exports.COLOR_GREEN = '\x1b[0;32m';
module.exports.COLOR_YELLOW = '\x1b[0;33m';
module.exports.COLOR_BLUE = '\x1b[0;34m';
module.exports.COLOR_MAGENTA = '\x1b[0;35m';
module.exports.COLOR_CYAN = '\x1b[0;36m';
// https://gist.github.com/thomseddon/3511330
module.exports.byteHelper = function (value) {
if (value === 0) {
return '0 b';
}
const units = ['b', 'kB', 'MB', 'GB', 'TB'];
const number = Math.floor(Math.log(value) / Math.log(1024));
return (value / Math.pow(1024, Math.floor(number))).toFixed(1) + ' ' +
units[number];
};
module.exports.color = function (color, text) {
return `${color}${text}${module.exports.COLOR_NC}`;
};
module.exports.inlineLog = function (msg) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(msg);
};
module.exports.isValidUrl = function (url) {
try {
new URL(url);
return true;
} catch (_) {
return false;
}
}
module.exports.isValidPath = function (path) {
try {
return existsSync(path);
} catch (_) {
return false;
}
};

68
node_modules/node-downloader-helper/bin/ndh generated vendored Executable file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env node
/*eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */
const args = process.argv.slice(2);
const { DownloaderHelper } = require('../dist');
const { byteHelper, color, COLOR_RED, COLOR_GREEN,
COLOR_YELLOW, COLOR_CYAN, COLOR_MAGENTA,
isValidPath, isValidUrl, inlineLog
} = require('./helpers');
const pkg = require('../package.json');
// Arguments
if (!args.length || args.length < 2) {
return console.log('USAGE: ndh [destination] [url]');
}
const dest = args[0];
const url = args[1];
if (!isValidPath(dest)) {
return console.error(color(COLOR_RED, 'Please use an existing folder or valid path'));
}
if (!isValidUrl(url)) {
return console.error(color(COLOR_RED, 'Please use a valid URL'));
}
let progressLog = '';
const dl = new DownloaderHelper(url, dest, {
headers: {
'user-agent': pkg.name + '@' + pkg.version
},
});
dl
.on('end', _ =>
inlineLog(progressLog + ' - ' + color(COLOR_GREEN, 'Download Completed'))
)
.on('retry', (attempt, opts) => {
let count = Math.floor(opts.delay / 1000);
const retryLog = () => {
inlineLog(color(COLOR_YELLOW, `Retry Attempt: ${attempt}/${opts.maxRetries} | Starts on: ${count} secs`));
if (count > 0) {
setTimeout(() => retryLog(), 1000);
}
count--;
};
retryLog();
})
.on('resume', isResumed => {
if (!isResumed) {
console.warn(color(COLOR_YELLOW, "\nThis URL doesn't support resume, it will start from the beginning"));
}
})
.on('progress.throttled', stats => {
const progress = stats.progress.toFixed(1);
const speed = byteHelper(stats.speed);
const downloaded = byteHelper(stats.downloaded);
const total = byteHelper(stats.total);
const cName = color(COLOR_YELLOW, stats.name);
const cSpeed = color(COLOR_MAGENTA, speed + '/s');
const cProgress = color(COLOR_MAGENTA, progress + '%');
const cSize = color(COLOR_CYAN, `[${downloaded}/${total}]`);
progressLog = `${cName}: ${cSpeed} - ${cProgress} ${cSize}`;
inlineLog(progressLog);
});
dl.start().catch(err => console.error(color(COLOR_RED, 'Something happend'), err));