Repository navigation
Expand file tree
/
Copy pathauth.js
More file actions
executable file
·92 lines (89 loc) · 3.76 KB
/
Copy pathauth.js
File metadata and controls
executable file
·92 lines (89 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const { spawnSync } = require('child_process');
const { loadDotEnv } = require('../lib/env');
const { defaultAuthOutputPath } = require('./auth_import');
const ROOT = path.resolve(__dirname, '..');
loadDotEnv(path.join(ROOT, '.env'));
const AUTH_PATH = defaultAuthOutputPath(process.env, ROOT);
const PROFILE_DIR = process.env.DEEPSEEK_CHROME_PROFILE || path.join(ROOT, '.chrome-for-testing-profile-deepseek');
const WATERMARK = 't.me/forgetmeai';
function prompt(question) {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
return new Promise(resolve => rl.question(question, ans => { rl.close(); resolve(ans); }));
}
function divider() { console.log('======================================================'); }
function watermark(prefix = 'ForgetMeAI') { return `${prefix}: ${WATERMARK}`; }
function loadAuth() {
try { return JSON.parse(fs.readFileSync(AUTH_PATH, 'utf8')); }
catch { return null; }
}
function status() {
const auth = loadAuth();
console.log('\nDeepSeek account:');
if (!auth) {
console.log(' ❌ deepseek-auth.json not found');
} else {
console.log(` ✅ auth file: ${AUTH_PATH}`);
console.log(` token: ${auth.token ? 'OK (' + String(auth.token).length + ' chars)' : 'MISSING'}`);
console.log(` cookies: ${auth.cookie ? 'OK' : 'MISSING'}`);
console.log(` Chrome profile: ${fs.existsSync(PROFILE_DIR) ? PROFILE_DIR : 'not found'}`);
}
}
function runDirectAuth() {
const script = path.join(__dirname, 'deepseek_chrome_auth.js');
return spawnSync(process.execPath, [script], { stdio: 'inherit', env: process.env }).status === 0;
}
function runImportAuth() {
const script = path.join(__dirname, 'auth_import.js');
return spawnSync(process.execPath, [script], { stdio: 'inherit', env: process.env }).status === 0;
}
function removeLocalAuth() {
if (fs.existsSync(AUTH_PATH)) fs.rmSync(AUTH_PATH, { force: true });
console.log('Removed deepseek-auth.json. Chrome profile kept so the browser is not logged out unnecessarily.');
}
function printHelp() {
divider();
console.log('FreeDeepseekAPI — DeepSeek Web login manager');
console.log(watermark());
divider();
console.log('Options:');
console.log(' --login Open Chrome and refresh auth');
console.log(' --import Import an existing deepseek-auth.json / browser cookies');
console.log(' --status Show auth status');
console.log(' --remove Delete the local deepseek-auth.json');
console.log(' --help Help');
console.log('Runs an interactive menu when no options are given.');
divider();
}
async function menu() {
while (true) {
divider();
console.log(watermark());
status();
divider();
console.log('Menu:');
console.log('1 - Log in / refresh DeepSeek login');
console.log('2 - Import auth file / cookies');
console.log('3 - Show status');
console.log('4 - Delete the local auth file');
console.log('5 - Exit');
const choice = (await prompt('Your choice (Enter = 5): ')) || '5';
if (choice === '1') runDirectAuth();
else if (choice === '2') runImportAuth();
else if (choice === '3') { status(); await prompt('\nPress Enter to return to the menu...'); }
else if (choice === '4') removeLocalAuth();
else if (choice === '5') break;
}
}
(async () => {
const args = new Set(process.argv.slice(2));
if (args.has('--help') || args.has('-h')) return printHelp();
if (args.has('--login') || args.has('--add') || args.has('--relogin')) return void runDirectAuth();
if (args.has('--import')) return void runImportAuth();
if (args.has('--status') || args.has('--list')) return status();
if (args.has('--remove')) return removeLocalAuth();
await menu();
})();