Skip to content

Commit 5f129dd

Browse files
committed
3.1.4
1 parent 641a8b2 commit 5f129dd

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

app/app-login.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
3+
import fs from 'node:fs';
4+
import path from 'node:path';
5+
import { fileURLToPath } from 'node:url';
6+
7+
import {loadYaml} from './module-helper.js';
8+
import Argv from './module-argv.js';
9+
10+
import TeraBoxApp from 'terabox-api';
11+
import input from '@inquirer/input';
12+
import password from '@inquirer/password';
13+
14+
// init app
15+
let app = {};
16+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
17+
const meta = loadYaml(path.resolve(__dirname, '../package.json'));
18+
19+
console.log(`[INFO] ${meta.name_ext} v${meta.version} (Login)`);
20+
21+
const yargs = new Argv({}, []);
22+
if(yargs.getArgv('help')){
23+
yargs.showHelp();
24+
process.exit();
25+
}
26+
27+
(async () => {
28+
app = new TeraBoxApp();
29+
30+
const preLogin = await tryPreLogin();
31+
const doLogin = await tryLogin(preLogin);
32+
33+
console.log(`[AUTH] ${doLogin.displayName}: ${doLogin.ndus}`);
34+
})();
35+
36+
async function tryPreLogin(){
37+
try{
38+
const email = await input({ message: 'EMail:' });
39+
const preLoginData = await app.preLogin(email);
40+
if(preLoginData.code === 0){
41+
preLoginData.data.email = email;
42+
return preLoginData.data;
43+
}
44+
console.log('ERROR:', preLoginData);
45+
throw new Error('Bad Response');
46+
}
47+
catch(err){
48+
return await tryPreLogin();
49+
}
50+
}
51+
52+
async function tryLogin(preLogin){
53+
try{
54+
const pass = await password({ message: 'Password:' });
55+
const authData = await app.doAuth(preLogin, preLogin.email, pass);
56+
if(authData.code === 0){
57+
return authData.data;
58+
}
59+
console.log('ERROR:', authData);
60+
throw new Error('Bad Response');
61+
}
62+
catch(err){
63+
return await tryLogin(preLogin);
64+
}
65+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "terabox-node",
33
"name_ext": "TeraBox node",
4-
"version": "3.1.3",
4+
"version": "3.1.4",
55
"type": "module",
66
"bin": {
77
"tb-check": "app/app-check.js",
@@ -21,6 +21,7 @@
2121
"description": "NodeJS tool for interacting with the TeraBox cloud service without the need to use the website or app ☁️",
2222
"dependencies": {
2323
"@inquirer/input": "^4.1.12",
24+
"@inquirer/password": "^4.0.15",
2425
"@inquirer/select": "^4.2.3",
2526
"dateformat": "^5.0.3",
2627
"filesize": "^10.1.6",

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)