Upgarade dependencies

This commit is contained in:
Mohammad Anas Fares 2024-08-29 02:37:59 +02:00
parent f211fdb484
commit 6a2fa28383
5 changed files with 2402 additions and 4000 deletions

4
app.js
View File

@ -23,7 +23,7 @@ global.BASEURL = 'https://www.terminalizer.com';
// Dependency Injection
di.require('chalk');
di.require('async');
di.require('request');
di.require('axios');
di.require('death');
di.require('path');
di.require('os');
@ -41,7 +41,7 @@ di.require('progress', 'ProgressBar');
di.require('gif-encoder', 'GIFEncoder');
di.require('inquirer');
di.set('pty', require('node-pty-prebuilt-multiarch'));
di.set('pty', require('@homebridge/node-pty-prebuilt-multiarch'));
di.set('PNG', require('pngjs').PNG);
di.set('spawn', require('child_process').spawn);
di.set('utility', require('./utility.js'));

View File

@ -1,7 +1,7 @@
/**
* Share
* Upload a recording file and get a link for an online player
*
*
* @author Mohammad Fares <faressoft.com@gmail.com>
*/
@ -11,30 +11,26 @@
* @param {String} url the url of the uploaded recording
*/
function done(url) {
console.log(di.chalk.green('Successfully Uploaded'));
console.log('The recording is available on the link:');
console.log(di.chalk.magenta(url));
process.exit();
}
/**
* Check if the value is not an empty value
*
* - Throw `Required field` if empty
*
*
* @param {String} input
* @return {Boolean}
*/
function isSet(input) {
if (!input) {
return new Error('Required field');
}
return true;
}
/**
@ -47,7 +43,6 @@ function isSet(input) {
* @return {Promise}
*/
function getToken(context) {
var token = di.utility.getToken();
// Already registered
@ -61,14 +56,12 @@ function getToken(context) {
console.log(di.chalk.dim(BASEURL + '/token?token=' + token) + '\n');
// Continue action
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
console.log('When you do it, press any key to continue');
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.once('data', function handler(data) {
// Check if CTRL+C is pressed to exit
if (data == '\u0003' || data == '\u0003') {
process.exit();
@ -79,11 +72,8 @@ function getToken(context) {
process.stdin.setRawMode(false);
resolve(token);
});
});
}
/**
@ -96,7 +86,6 @@ function getToken(context) {
* @return {Promise}
*/
function getMeta(context) {
var platform = di.utility.getOS();
// Already executed
@ -106,40 +95,39 @@ function getMeta(context) {
console.log('Please enter some details about your recording');
return di.inquirer.prompt([
{
type: 'input',
name: 'title',
message: 'Title',
validate: isSet
},
{
type: 'input',
name: 'description',
message: 'Description',
validate: isSet
},
{
type: 'input',
name: 'tags',
message: 'Tags ' + di.chalk.dim('such as git,bash,game'),
validate: isSet,
default: platform
}
]).then(function(answers) {
return di.inquirer
.prompt([
{
type: 'input',
name: 'title',
message: 'Title',
validate: isSet,
},
{
type: 'input',
name: 'description',
message: 'Description',
validate: isSet,
},
{
type: 'input',
name: 'tags',
message: 'Tags ' + di.chalk.dim('such as git,bash,game'),
validate: isSet,
default: platform,
},
])
.then(function (answers) {
var params = Object.assign({}, answers);
var params = Object.assign({}, answers);
// Add the platform
params.platform = platform;
// Add the platform
params.platform = platform;
// Print a new line
console.log();
return params;
});
// Print a new line
console.log();
return params;
});
}
/**
@ -150,12 +138,11 @@ function getMeta(context) {
* - Jump into the getToken task
*
* - Resolve with the url of the uploaded recording
*
*
* @param {Object} context
* @return {Promise}
*/
function shareRecording(context) {
var self = this;
var token = context.getToken;
var meta = context.getMeta;
@ -174,56 +161,49 @@ function shareRecording(context) {
value: di.fs.createReadStream(recordingFile),
options: {
filename: 'recording.yml',
contentType: 'application/x-yaml'
}
}
}
contentType: 'application/x-yaml',
},
},
},
};
return new Promise(function(resolve, reject) {
di.request(options, function(error, response, body) {
if (error) {
return reject(error);
}
return di
.axios(options)
.then((response) => {
// Internal server error
if (response.statusCode == 500) {
return reject(body.errors.join('\n'));
if (response.status === 500) {
throw new Error(response.data.errors.join('\n'));
}
// Invalid input
if (response.statusCode == 400) {
return reject(body.errors.join('\n'));
if (response.status === 400) {
throw new Error(response.data.errors.join('\n'));
}
// Invalid token
if (response.statusCode == 401) {
if (response.status === 401) {
di.utility.removeToken();
self.jump('getToken');
return resolve();
return;
}
// Unexpected error
if (response.statusCode != 200) {
return reject(new Error('Something went wrong, try again later'));
if (response.status !== 200) {
throw new Error('Something went wrong, try again later');
}
// Parse the response body
body = JSON.parse(body);
resolve(body.url);
// Resolve with the URL from the response body
return response.data.url;
})
.catch((error) => {
// Reject the promise with the error
throw error;
});
});
}
/**
* The command's main function
*
*
* @param {Object} argv
*/
function command(argv) {
@ -232,21 +212,21 @@ function command(argv) {
require('./init.js').handler();
}
var context = {...argv};
var context = { ...argv };
// Get a token for uploading recordings
getToken(context)
.then(function(token) {
.then(function (token) {
context.getToken = token;
// Ask the user to enter meta data about the recording
return getMeta(context);
})
.then(function(meta) {
.then(function (meta) {
context.getMeta = meta;
// Upload the recording
return shareRecording(context);
})
.then(function(url) {
.then(function (url) {
done(url);
})
.catch(di.errorHandler);
@ -276,16 +256,14 @@ module.exports.handler = command;
/**
* Builder
*
*
* @param {Object} yargs
*/
module.exports.builder = function(yargs) {
module.exports.builder = function (yargs) {
// Define the recordingFile argument
yargs.positional('recordingFile', {
describe: 'the recording file',
type: 'string',
coerce: di._.partial(di.utility.resolveFilePath, di._, 'yml')
coerce: di._.partial(di.utility.resolveFilePath, di._, 'yml'),
});
};

3909
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -41,8 +41,10 @@
"pty"
],
"dependencies": {
"@homebridge/node-pty-prebuilt-multiarch": "^0.11.14",
"async": "^2.6.3",
"async-promises": "^0.2.2",
"axios": "^1.7.5",
"chalk": "^2.4.2",
"death": "^1.1.0",
"deepmerge": "^2.2.1",
@ -52,15 +54,13 @@
"inquirer": "^6.5.2",
"js-yaml": "^3.13.1",
"lodash": "^4.17.15",
"node-pty-prebuilt-multiarch": "^0.10.1-pre.5",
"performance-now": "^2.1.0",
"pngjs": "^3.4.0",
"progress": "^2.0.3",
"request": "^2.88.2",
"require-dir": "^1.1.0",
"string-argv": "0.0.2",
"tmp": "^0.2.1",
"uuid": "^3.4.0",
"uuid": "^10.0.0",
"yargs": "^17.7.2"
},
"devDependencies": {
@ -72,6 +72,6 @@
"terminalizer-player": "^0.4.1",
"webpack": "^5.88.1",
"webpack-cli": "^4.10.0",
"xterm": "^3.14.5"
"xterm": "^v3.14.5"
}
}

2333
yarn.lock Normal file

File diff suppressed because it is too large Load Diff