tglfs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -0
- package/dist/auth.d.ts +58 -0
- package/dist/auth.js +187 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +627 -0
- package/dist/cli.js.map +1 -0
- package/dist/crypto.d.ts +8 -0
- package/dist/crypto.js +45 -0
- package/dist/crypto.js.map +1 -0
- package/dist/download.d.ts +26 -0
- package/dist/download.js +228 -0
- package/dist/download.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -0
- package/dist/file-ops.d.ts +71 -0
- package/dist/file-ops.js +234 -0
- package/dist/file-ops.js.map +1 -0
- package/dist/gramjs.d.ts +14 -0
- package/dist/gramjs.js +70 -0
- package/dist/gramjs.js.map +1 -0
- package/dist/interactive.d.ts +11 -0
- package/dist/interactive.js +81 -0
- package/dist/interactive.js.map +1 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +4 -0
- package/dist/json.js.map +1 -0
- package/dist/progress.d.ts +16 -0
- package/dist/progress.js +62 -0
- package/dist/progress.js.map +1 -0
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.js +27 -0
- package/dist/protocol.js.map +1 -0
- package/dist/search.d.ts +23 -0
- package/dist/search.js +81 -0
- package/dist/search.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +29 -0
- package/dist/secrets.js.map +1 -0
- package/dist/shared/archive.d.ts +9 -0
- package/dist/shared/archive.js +95 -0
- package/dist/shared/archive.js.map +1 -0
- package/dist/shared/constants.d.ts +5 -0
- package/dist/shared/constants.js +6 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/file-cards.d.ts +31 -0
- package/dist/shared/file-cards.js +103 -0
- package/dist/shared/file-cards.js.map +1 -0
- package/dist/shared/telegram-files.d.ts +84 -0
- package/dist/shared/telegram-files.js +137 -0
- package/dist/shared/telegram-files.js.map +1 -0
- package/dist/shared/upload.d.ts +44 -0
- package/dist/shared/upload.js +181 -0
- package/dist/shared/upload.js.map +1 -0
- package/dist/store.d.ts +15 -0
- package/dist/store.js +97 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ufid.d.ts +8 -0
- package/dist/ufid.js +65 -0
- package/dist/ufid.js.map +1 -0
- package/dist/upload.d.ts +19 -0
- package/dist/upload.js +101 -0
- package/dist/upload.js.map +1 -0
- package/man/tglfs-delete.1 +19 -0
- package/man/tglfs-download.1 +42 -0
- package/man/tglfs-inspect.1 +34 -0
- package/man/tglfs-login.1 +53 -0
- package/man/tglfs-logout.1 +17 -0
- package/man/tglfs-receive.1 +26 -0
- package/man/tglfs-rename.1 +8 -0
- package/man/tglfs-search.1 +37 -0
- package/man/tglfs-send.1 +22 -0
- package/man/tglfs-status.1 +12 -0
- package/man/tglfs-unsend.1 +37 -0
- package/man/tglfs-upload.1 +28 -0
- package/man/tglfs.1 +70 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# tglfs
|
|
2
|
+
|
|
3
|
+
`tglfs` is a global CLI for authenticating with Telegram, uploading files, managing TGLFS file cards, transferring files between peers, searching mailboxes, and downloading current or legacy files by UFID.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g tglfs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
tglfs --help
|
|
15
|
+
tglfs help upload
|
|
16
|
+
tglfs help login
|
|
17
|
+
tglfs help search
|
|
18
|
+
tglfs help download
|
|
19
|
+
tglfs help inspect
|
|
20
|
+
tglfs upload ./file.bin
|
|
21
|
+
tglfs upload ./a.txt ./b.txt
|
|
22
|
+
tglfs login
|
|
23
|
+
tglfs status
|
|
24
|
+
tglfs search [query]
|
|
25
|
+
tglfs search [query] --peer alice
|
|
26
|
+
tglfs rename <ufid> <new-name>
|
|
27
|
+
tglfs delete <ufid...> --yes
|
|
28
|
+
tglfs send <ufid...> --to alice
|
|
29
|
+
tglfs receive alice <ufid...>
|
|
30
|
+
tglfs unsend alice <ufid...> --yes
|
|
31
|
+
tglfs inspect <ufid>
|
|
32
|
+
tglfs logout
|
|
33
|
+
tglfs download <ufid>
|
|
34
|
+
tglfs download <ufid> --legacy
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
On Unix-like systems, installed manpages are also available:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
man tglfs
|
|
41
|
+
man tglfs-login
|
|
42
|
+
man tglfs-upload
|
|
43
|
+
man tglfs-search
|
|
44
|
+
man tglfs-download
|
|
45
|
+
man tglfs-rename
|
|
46
|
+
man tglfs-delete
|
|
47
|
+
man tglfs-send
|
|
48
|
+
man tglfs-receive
|
|
49
|
+
man tglfs-unsend
|
|
50
|
+
man tglfs-inspect
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Auth Flow
|
|
54
|
+
|
|
55
|
+
Run `tglfs login` once to save:
|
|
56
|
+
|
|
57
|
+
- Telegram API ID
|
|
58
|
+
- Telegram API hash
|
|
59
|
+
- your phone number
|
|
60
|
+
- the resulting Telegram session
|
|
61
|
+
|
|
62
|
+
If you do not supply an API ID or API hash, the CLI defaults to the same bundled Telegram app credentials the web client currently uses. You can still override them with flags or environment variables.
|
|
63
|
+
|
|
64
|
+
The CLI stores config and session files in OS-standard app directories. Use `tglfs status` to inspect the current state.
|
|
65
|
+
|
|
66
|
+
## Upload And File Management
|
|
67
|
+
|
|
68
|
+
Upload one file directly:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
tglfs upload ./report.pdf
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Upload multiple files as a tar archive using the same archive naming convention as the web app:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
tglfs upload ./notes.txt ./diagram.png ./draft.md
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Optional upload password sources:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
tglfs upload ./report.pdf --password 'secret'
|
|
84
|
+
TGLFS_UPLOAD_PASSWORD='secret' tglfs upload ./report.pdf
|
|
85
|
+
printf '%s\n' 'secret' | tglfs upload ./report.pdf --password-stdin
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Owned-file management:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
tglfs rename <ufid> "new-name.pdf"
|
|
92
|
+
tglfs delete <ufid...> --yes
|
|
93
|
+
tglfs send <ufid...> --to alice
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
TTY uploads render separate UFID and upload progress bars. `--json` stays quiet until the final result so agents can parse the output safely.
|
|
97
|
+
|
|
98
|
+
## Download Flow
|
|
99
|
+
|
|
100
|
+
Download a file by UFID:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
tglfs download <ufid>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Optional flags:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
tglfs download <ufid> --output ./file.bin
|
|
110
|
+
tglfs download <ufid> --password 'secret'
|
|
111
|
+
tglfs download <ufid> --password-env
|
|
112
|
+
printf '%s\n' 'secret' | tglfs download <ufid> --password-stdin
|
|
113
|
+
tglfs download <ufid> --legacy
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Interactive TTY downloads render a progress bar. `--json` stays quiet until the final result so agents can parse the output safely.
|
|
117
|
+
|
|
118
|
+
## Search Flow
|
|
119
|
+
|
|
120
|
+
Search Saved Messages or another peer mailbox for TGLFS file cards by filename or UFID:
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
tglfs search
|
|
124
|
+
tglfs search theorydesign
|
|
125
|
+
tglfs search e5d494acbfd03de2
|
|
126
|
+
tglfs search "project docs" --limit 10 --offset-id 170397
|
|
127
|
+
tglfs search "project docs" --peer alice --limit 10
|
|
128
|
+
tglfs search --sort name_asc --json
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Plain-text output shows a table of `Name`, `Size`, `Date`, `UFID`, and `Status`. If a result page is full, the CLI prints the exact `--offset-id` command for the next page.
|
|
132
|
+
|
|
133
|
+
## Peer Transfer And Inspection
|
|
134
|
+
|
|
135
|
+
Peer values for `--to`, `<source>`, and `--peer` are passed directly to Telegram/GramJS entity resolution. Users, groups, and channels can all work. In practice, use one of:
|
|
136
|
+
|
|
137
|
+
- a public username like `alice`, `@alice`, `@mygroup`, or `@mychannel`
|
|
138
|
+
- `me` for Saved Messages
|
|
139
|
+
- a phone number your Telegram account can already resolve, typically a saved contact
|
|
140
|
+
|
|
141
|
+
Private users, groups, and channels can also work if Telegram can already resolve them for the authenticated account, which usually means that account already has access to the dialog/entity.
|
|
142
|
+
|
|
143
|
+
If Telegram cannot resolve the peer value, the command fails.
|
|
144
|
+
|
|
145
|
+
Receive files from another peer into Saved Messages:
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
tglfs receive alice <ufid...>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
For `receive` and `unsend`, `<source>` is the chat or mailbox that currently contains the TGLFS file card and chunk messages you want to operate on. It is not necessarily the original uploader's personal account.
|
|
152
|
+
|
|
153
|
+
Delete received files from another peer mailbox:
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
tglfs unsend alice <ufid...> --yes
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Inspect file-card metadata and chunk references:
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
tglfs inspect <ufid>
|
|
163
|
+
tglfs inspect <ufid> --peer alice
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Run the expensive full current-vs-legacy integrity probe only when you want it:
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
tglfs inspect <ufid> --probe
|
|
170
|
+
tglfs inspect <ufid> --password 'secret'
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Environment Variables
|
|
174
|
+
|
|
175
|
+
Login:
|
|
176
|
+
|
|
177
|
+
- `TGLFS_API_ID`
|
|
178
|
+
- `TGLFS_API_HASH`
|
|
179
|
+
- `TGLFS_PHONE`
|
|
180
|
+
- `TGLFS_LOGIN_CODE`
|
|
181
|
+
- `TGLFS_2FA_PASSWORD`
|
|
182
|
+
|
|
183
|
+
If `TGLFS_API_ID` and `TGLFS_API_HASH` are unset, `tglfs login` falls back to the bundled web-client credentials.
|
|
184
|
+
|
|
185
|
+
Upload:
|
|
186
|
+
|
|
187
|
+
- `TGLFS_UPLOAD_PASSWORD`
|
|
188
|
+
|
|
189
|
+
Download:
|
|
190
|
+
|
|
191
|
+
- `TGLFS_DOWNLOAD_PASSWORD`
|
|
192
|
+
|
|
193
|
+
Inspect:
|
|
194
|
+
|
|
195
|
+
- `TGLFS_INSPECT_PASSWORD`
|
|
196
|
+
|
|
197
|
+
## AI-Agent Use
|
|
198
|
+
|
|
199
|
+
The CLI is designed to work with interactive agents and terminal tools:
|
|
200
|
+
|
|
201
|
+
- Prefer direct subcommands instead of menus when automating.
|
|
202
|
+
- Use `--json` for machine-readable `status`, `search`, `upload`, `rename`, `delete`, `send`, `receive`, `unsend`, `inspect`, and `download` output.
|
|
203
|
+
- Use stdin or env vars for secrets in non-interactive runs.
|
|
204
|
+
- Pass `--yes` for destructive commands such as `delete` and `unsend` in non-interactive runs.
|
|
205
|
+
- If Telegram asks for an SMS or in-app code or a 2FA password and no secret source was supplied, the agent should hand off to the user to provide it.
|
|
206
|
+
|
|
207
|
+
Examples:
|
|
208
|
+
|
|
209
|
+
```sh
|
|
210
|
+
tglfs status --json
|
|
211
|
+
tglfs search --json
|
|
212
|
+
tglfs upload ./report.pdf --json
|
|
213
|
+
tglfs send <ufid> --to alice --json
|
|
214
|
+
tglfs inspect <ufid> --json
|
|
215
|
+
printf '%s\n' "$TGLFS_DOWNLOAD_PASSWORD" | tglfs download <ufid> --password-stdin --json
|
|
216
|
+
```
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { TelegramClient } from "telegram/client/TelegramClient.js";
|
|
2
|
+
import type { StringSession } from "telegram/sessions/StringSession.js";
|
|
3
|
+
import { storePaths } from "./store.js";
|
|
4
|
+
import type { PersistedConfig } from "./types.js";
|
|
5
|
+
export declare const BUNDLED_TELEGRAM_API_ID = 20227969;
|
|
6
|
+
export declare const BUNDLED_TELEGRAM_API_HASH = "3fc5e726fcc1160a81704958b2243109";
|
|
7
|
+
type LoginOptions = {
|
|
8
|
+
apiId?: string;
|
|
9
|
+
apiHash?: string;
|
|
10
|
+
phone?: string;
|
|
11
|
+
code?: string;
|
|
12
|
+
codeStdin?: boolean;
|
|
13
|
+
password?: string;
|
|
14
|
+
passwordStdin?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type TelegramIdentity = {
|
|
17
|
+
id: string;
|
|
18
|
+
firstName?: string;
|
|
19
|
+
lastName?: string;
|
|
20
|
+
username?: string;
|
|
21
|
+
phone?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function formatTwoFactorPrompt(hint?: string): string;
|
|
24
|
+
export declare function connectAuthorizedClient(): Promise<{
|
|
25
|
+
client: TelegramClient;
|
|
26
|
+
config: PersistedConfig;
|
|
27
|
+
session: StringSession;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function persistAndDisconnectClient(client: TelegramClient, session: StringSession): Promise<void>;
|
|
30
|
+
export declare function login(options: LoginOptions): Promise<{
|
|
31
|
+
config: PersistedConfig;
|
|
32
|
+
me: TelegramIdentity;
|
|
33
|
+
paths: {
|
|
34
|
+
configDir: string;
|
|
35
|
+
dataDir: string;
|
|
36
|
+
configFile: string;
|
|
37
|
+
sessionFile: string;
|
|
38
|
+
};
|
|
39
|
+
}>;
|
|
40
|
+
export declare function status(): Promise<{
|
|
41
|
+
configured: boolean;
|
|
42
|
+
sessionPresent: boolean;
|
|
43
|
+
authorized: boolean;
|
|
44
|
+
identity?: TelegramIdentity | undefined;
|
|
45
|
+
paths: typeof storePaths;
|
|
46
|
+
phone?: string | undefined;
|
|
47
|
+
error?: string | undefined;
|
|
48
|
+
}>;
|
|
49
|
+
export declare function logout(removeConfig?: boolean): Promise<{
|
|
50
|
+
removedConfig: boolean;
|
|
51
|
+
paths: {
|
|
52
|
+
configDir: string;
|
|
53
|
+
dataDir: string;
|
|
54
|
+
configFile: string;
|
|
55
|
+
sessionFile: string;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
58
|
+
export {};
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { CliError, EXIT_CODES } from "./errors.js";
|
|
2
|
+
import { createQuietTelegramClient, createStringSession } from "./gramjs.js";
|
|
3
|
+
import { isInteractiveSession, promptPassword, promptText, readTrimmedStdin } from "./interactive.js";
|
|
4
|
+
import { BUNDLED_CHUNK_SIZE } from "./shared/constants.js";
|
|
5
|
+
import { clearPersistedState, loadConfig, loadSessionString, saveConfig, saveSessionString, sessionExists, storePaths } from "./store.js";
|
|
6
|
+
export const BUNDLED_TELEGRAM_API_ID = 20227969;
|
|
7
|
+
export const BUNDLED_TELEGRAM_API_HASH = "3fc5e726fcc1160a81704958b2243109";
|
|
8
|
+
export function formatTwoFactorPrompt(hint) {
|
|
9
|
+
return hint ? `Telegram 2FA password (Hint: ${hint})` : "Telegram 2FA password";
|
|
10
|
+
}
|
|
11
|
+
function normalizeApiId(raw) {
|
|
12
|
+
const parsed = Number(raw.trim());
|
|
13
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
14
|
+
throw new CliError("invalid_api_id", "Telegram API ID must be a positive integer.", EXIT_CODES.GENERAL_ERROR);
|
|
15
|
+
}
|
|
16
|
+
return parsed;
|
|
17
|
+
}
|
|
18
|
+
async function resolveRequiredValue(label, values, promptFn) {
|
|
19
|
+
for (const value of values) {
|
|
20
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
21
|
+
return value.trim();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (!isInteractiveSession()) {
|
|
25
|
+
throw new CliError("interactive_required", `${label} is required. Provide it with a flag, environment variable, or stdin.`, EXIT_CODES.INTERACTIVE_REQUIRED);
|
|
26
|
+
}
|
|
27
|
+
return promptFn();
|
|
28
|
+
}
|
|
29
|
+
function summarizeMe(me) {
|
|
30
|
+
return {
|
|
31
|
+
id: String(me.id),
|
|
32
|
+
firstName: me.firstName,
|
|
33
|
+
lastName: me.lastName,
|
|
34
|
+
username: me.username,
|
|
35
|
+
phone: me.phone,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export async function connectAuthorizedClient() {
|
|
39
|
+
const config = await loadConfig();
|
|
40
|
+
if (!config) {
|
|
41
|
+
throw new CliError("missing_auth", "No persisted TGLFS config found. Run `tglfs login` first.", EXIT_CODES.MISSING_AUTH);
|
|
42
|
+
}
|
|
43
|
+
const sessionString = await loadSessionString();
|
|
44
|
+
if (!sessionString) {
|
|
45
|
+
throw new CliError("missing_auth", "No persisted Telegram session found. Run `tglfs login` first.", EXIT_CODES.MISSING_AUTH);
|
|
46
|
+
}
|
|
47
|
+
const session = createStringSession(sessionString);
|
|
48
|
+
const client = createQuietTelegramClient(session, config.apiId, config.apiHash);
|
|
49
|
+
await client.connect();
|
|
50
|
+
const authorized = await client.checkAuthorization();
|
|
51
|
+
if (!authorized) {
|
|
52
|
+
await client.disconnect().catch(() => { });
|
|
53
|
+
throw new CliError("missing_auth", "The saved Telegram session is not authorized. Run `tglfs login` again.", EXIT_CODES.MISSING_AUTH);
|
|
54
|
+
}
|
|
55
|
+
return { client, config, session };
|
|
56
|
+
}
|
|
57
|
+
export async function persistAndDisconnectClient(client, session) {
|
|
58
|
+
const sessionString = session.save();
|
|
59
|
+
if (sessionString.trim() !== "") {
|
|
60
|
+
await saveSessionString(sessionString);
|
|
61
|
+
}
|
|
62
|
+
await client.destroy();
|
|
63
|
+
}
|
|
64
|
+
export async function login(options) {
|
|
65
|
+
if (options.codeStdin && options.passwordStdin) {
|
|
66
|
+
throw new CliError("invalid_input", "Use only one stdin-backed secret per login command.", EXIT_CODES.GENERAL_ERROR);
|
|
67
|
+
}
|
|
68
|
+
const existingConfig = await loadConfig();
|
|
69
|
+
const apiId = normalizeApiId([options.apiId, process.env.TGLFS_API_ID, existingConfig?.apiId?.toString(), String(BUNDLED_TELEGRAM_API_ID)].find((value) => typeof value === "string" && value.trim() !== "") ?? String(BUNDLED_TELEGRAM_API_ID));
|
|
70
|
+
const apiHash = [options.apiHash, process.env.TGLFS_API_HASH, existingConfig?.apiHash, BUNDLED_TELEGRAM_API_HASH].find((value) => typeof value === "string" && value.trim() !== "") ?? BUNDLED_TELEGRAM_API_HASH;
|
|
71
|
+
const phone = await resolveRequiredValue("Telegram phone number", [options.phone, process.env.TGLFS_PHONE, existingConfig?.phone], async () => promptText("Telegram phone number", existingConfig?.phone));
|
|
72
|
+
const storedSession = (await loadSessionString()) ?? "";
|
|
73
|
+
const session = createStringSession(storedSession);
|
|
74
|
+
const client = createQuietTelegramClient(session, apiId, apiHash);
|
|
75
|
+
let sharedStdinValue;
|
|
76
|
+
const getSharedStdin = async (label) => {
|
|
77
|
+
if (sharedStdinValue !== undefined) {
|
|
78
|
+
return sharedStdinValue;
|
|
79
|
+
}
|
|
80
|
+
sharedStdinValue = await readTrimmedStdin(label);
|
|
81
|
+
return sharedStdinValue;
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
await client.start({
|
|
85
|
+
phoneNumber: phone,
|
|
86
|
+
phoneCode: async (isCodeViaApp) => {
|
|
87
|
+
if (options.code?.trim()) {
|
|
88
|
+
return options.code.trim();
|
|
89
|
+
}
|
|
90
|
+
if (process.env.TGLFS_LOGIN_CODE?.trim()) {
|
|
91
|
+
return process.env.TGLFS_LOGIN_CODE.trim();
|
|
92
|
+
}
|
|
93
|
+
if (options.codeStdin) {
|
|
94
|
+
return getSharedStdin("Telegram login code is required on stdin.");
|
|
95
|
+
}
|
|
96
|
+
if (!isInteractiveSession()) {
|
|
97
|
+
throw new CliError("interactive_required", "Telegram login code is required. Provide `--code`, `TGLFS_LOGIN_CODE`, or `--code-stdin`.", EXIT_CODES.INTERACTIVE_REQUIRED);
|
|
98
|
+
}
|
|
99
|
+
return promptText(isCodeViaApp
|
|
100
|
+
? "Telegram login code (sent in-app)"
|
|
101
|
+
: "Telegram login code (sent by Telegram)");
|
|
102
|
+
},
|
|
103
|
+
password: async (hint) => {
|
|
104
|
+
if (options.password !== undefined) {
|
|
105
|
+
return options.password;
|
|
106
|
+
}
|
|
107
|
+
if (process.env.TGLFS_2FA_PASSWORD !== undefined) {
|
|
108
|
+
return process.env.TGLFS_2FA_PASSWORD;
|
|
109
|
+
}
|
|
110
|
+
if (options.passwordStdin) {
|
|
111
|
+
return getSharedStdin("Telegram 2FA password is required on stdin.");
|
|
112
|
+
}
|
|
113
|
+
if (!isInteractiveSession()) {
|
|
114
|
+
throw new CliError("interactive_required", "Telegram 2FA password is required. Provide `--password`, `TGLFS_2FA_PASSWORD`, or `--password-stdin`.", EXIT_CODES.INTERACTIVE_REQUIRED);
|
|
115
|
+
}
|
|
116
|
+
return promptPassword(formatTwoFactorPrompt(hint));
|
|
117
|
+
},
|
|
118
|
+
onError: async (error) => {
|
|
119
|
+
if (error instanceof CliError) {
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
return !isInteractiveSession();
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const config = {
|
|
126
|
+
apiId,
|
|
127
|
+
apiHash,
|
|
128
|
+
phone,
|
|
129
|
+
chunkSize: existingConfig?.chunkSize ?? BUNDLED_CHUNK_SIZE,
|
|
130
|
+
};
|
|
131
|
+
const me = await client.getMe();
|
|
132
|
+
await saveConfig(config);
|
|
133
|
+
await saveSessionString(session.save());
|
|
134
|
+
return {
|
|
135
|
+
config,
|
|
136
|
+
me: summarizeMe(me),
|
|
137
|
+
paths: storePaths,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
await client.destroy().catch(() => { });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export async function status() {
|
|
145
|
+
const config = await loadConfig();
|
|
146
|
+
const hasSession = await sessionExists();
|
|
147
|
+
const result = {
|
|
148
|
+
configured: Boolean(config),
|
|
149
|
+
sessionPresent: hasSession,
|
|
150
|
+
authorized: false,
|
|
151
|
+
paths: storePaths,
|
|
152
|
+
phone: config?.phone,
|
|
153
|
+
};
|
|
154
|
+
if (!config || !hasSession) {
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
const sessionString = await loadSessionString();
|
|
158
|
+
if (!sessionString) {
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
const session = createStringSession(sessionString);
|
|
162
|
+
const client = createQuietTelegramClient(session, config.apiId, config.apiHash);
|
|
163
|
+
try {
|
|
164
|
+
await client.connect();
|
|
165
|
+
result.authorized = await client.checkAuthorization();
|
|
166
|
+
if (result.authorized) {
|
|
167
|
+
const me = await client.getMe();
|
|
168
|
+
result.identity = summarizeMe(me);
|
|
169
|
+
await saveSessionString(session.save());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
result.error = error instanceof Error ? error.message : String(error);
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
await client.destroy().catch(() => { });
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
export async function logout(removeConfig = false) {
|
|
181
|
+
await clearPersistedState(removeConfig);
|
|
182
|
+
return {
|
|
183
|
+
removedConfig: removeConfig,
|
|
184
|
+
paths: storePaths,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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