mirror of
https://github.com/sydev/decrypt-dlc-cli
synced 2026-01-03 16:28:01 +00:00
44 lines
1.3 KiB
JavaScript
Executable File
44 lines
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const decrypt = require('decrypt-dlc');
|
|
const fs = require('fs-extra');
|
|
const isFile = require('is-file');
|
|
const isUrl = require('is-url');
|
|
const path = require('path');
|
|
const program = require('commander');
|
|
const signale = require('signale');
|
|
|
|
|
|
program
|
|
.version('1.0.0')
|
|
.usage('[options] <file|url>')
|
|
.option('-o, --output <file>', 'File to store decrypted urls in. (Default: urls.txt)', path.join(process.cwd(), 'urls.txt'))
|
|
.parse(process.argv);
|
|
|
|
/**
|
|
* Check if a filepath has an allowed extension. Allowed are `.dlc`, `.ccf` and `.rsdf`.
|
|
* @param {String} filepath The filepath to check
|
|
* @returns {Boolean}
|
|
*/
|
|
const hasAllowedExtension = (filepath = '') => ['.dlc', '.ccf', '.rsdf'].indexOf(path.extname(filepath)) > -1;
|
|
|
|
const run = async () => {
|
|
const filepath = path.isAbsolute(program.output) ? program.output : path.resolve(process.cwd(), program.output);
|
|
const input = program.args[0];
|
|
|
|
let links = [];
|
|
|
|
try {
|
|
if (isFile(input) && hasAllowedExtension(input)) links = await decrypt.upload(input);
|
|
else if (isUrl(input)) links = await decrypt.container(input);
|
|
else throw new Error('Positional argument must be a filepath or an url.');
|
|
|
|
await fs.outputFile(filepath, links.join('\n'));
|
|
signale.success(`Urls stored at ${filepath}`);
|
|
} catch (err) {
|
|
signale.fatal(err);
|
|
}
|
|
};
|
|
|
|
run();
|