Skip to content

Commit 5147edd

Browse files
zanzhz1101User
andauthored
Add support for custom Telegram tdata directory path (#31)
Co-authored-by: User <user@example.com>
1 parent f241fda commit 5147edd

7 files changed

Lines changed: 60 additions & 5 deletions

File tree

docs/telegram.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ vget telegram status # Show login state
7575
- macOS: `~/Library/Application Support/Telegram Desktop/tdata/`
7676
- Linux: `~/.local/share/TelegramDesktop/tdata/`
7777
- Windows: `%APPDATA%/Telegram Desktop/tdata/`
78+
- **Custom path**: Set via `vget config set telegram.tdata_path /path/to/tdata`
7879
- Imports session using Desktop's API credentials (2040)
7980
- Session stored in `~/.config/vget/telegram/desktop-session.json`
8081

internal/cli/telegram.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/gotd/td/telegram"
1414
"github.com/gotd/td/tg"
1515
tgpkg "github.com/guiyumin/vget/internal/core/extractor/telegram"
16+
"github.com/guiyumin/vget/internal/core/config"
1617
"github.com/spf13/cobra"
1718
)
1819

@@ -63,11 +64,17 @@ func runTelegramLogin(cmd *cobra.Command, args []string) error {
6364
return nil
6465
}
6566

66-
// Find Telegram Desktop tdata directory
67-
tdataPath := getTelegramDesktopPath()
67+
// Check config for custom Telegram directory
68+
cfg := config.LoadOrDefault()
69+
tdataPath := cfg.Telegram.TDataPath
70+
71+
// If no custom path, use default locations
6872
if tdataPath == "" {
69-
return fmt.Errorf("could not find Telegram Desktop data directory.\n" +
70-
"Make sure Telegram Desktop is installed and you're logged in")
73+
tdataPath = getTelegramDesktopPath()
74+
if tdataPath == "" {
75+
return fmt.Errorf("could not find Telegram Desktop data directory.\n"+
76+
"Make sure Telegram Desktop is installed and you're logged in")
77+
}
7178
}
7279

7380
fmt.Printf("Found Telegram Desktop at: %s\n", tdataPath)

internal/core/config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ type Config struct {
8181

8282
// Bilibili configuration
8383
Bilibili BilibiliConfig `yaml:"bilibili,omitempty"`
84+
85+
// Telegram configuration
86+
Telegram TelegramConfig `yaml:"telegram,omitempty"`
8487
}
8588

8689
// BilibiliConfig holds Bilibili authentication settings
@@ -89,6 +92,12 @@ type BilibiliConfig struct {
8992
Cookie string `yaml:"cookie,omitempty"`
9093
}
9194

95+
// TelegramConfig holds Telegram authentication settings
96+
type TelegramConfig struct {
97+
// TDataPath is the custom path to Telegram Desktop tdata directory
98+
TDataPath string `yaml:"tdata_path,omitempty"`
99+
}
100+
92101
// TorrentConfig holds configuration for remote torrent client integration
93102
type TorrentConfig struct {
94103
// Enabled determines if torrent dispatch feature is active

internal/server/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,8 @@ func (s *Server) handleGetConfig(c *gin.Context) {
542542
"express": cfg.Express,
543543
"torrent_enabled": cfg.Torrent.Enabled,
544544
"bilibili_cookie": cfg.Bilibili.Cookie,
545-
},
545+
"telegram_tdata_path": cfg.Telegram.TDataPath,
546+
},
546547
Message: "config retrieved",
547548
})
548549
}
@@ -1170,6 +1171,8 @@ func (s *Server) setConfigValue(cfg *config.Config, key, value string) error {
11701171
cfg.Server.APIKey = value
11711172
case "bilibili.cookie", "bilibili_cookie":
11721173
cfg.Bilibili.Cookie = value
1174+
case "telegram.tdata_path", "telegram_tdata_path":
1175+
cfg.Telegram.TDataPath = value
11731176
default:
11741177
return fmt.Errorf("unknown config key: %s", key)
11751178
}

ui/src/components/ConfigEditor.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ interface ConfigEditorProps {
3939
initialApiKey: string;
4040
initialKuaidi100Key: string;
4141
initialKuaidi100Customer: string;
42+
initialTelegramTdataPath: string;
4243
serverPort: number;
4344
webdavServers: Record<string, WebDAVServer>;
4445
// Callbacks
@@ -62,6 +63,7 @@ export interface ConfigValues {
6263
apiKey: string;
6364
kuaidi100Key: string;
6465
kuaidi100Customer: string;
66+
telegramTdataPath: string;
6567
}
6668

6769
export function ConfigEditor({
@@ -74,6 +76,7 @@ export function ConfigEditor({
7476
initialApiKey,
7577
initialKuaidi100Key,
7678
initialKuaidi100Customer,
79+
initialTelegramTdataPath,
7780
serverPort,
7881
webdavServers,
7982
onSave,
@@ -100,6 +103,9 @@ export function ConfigEditor({
100103
const [pendingKuaidi100Customer, setPendingKuaidi100Customer] = useState(
101104
initialKuaidi100Customer || ""
102105
);
106+
const [pendingTelegramTdataPath, setPendingTelegramTdataPath] = useState(
107+
initialTelegramTdataPath || ""
108+
);
103109

104110
// WebDAV add form
105111
const [newWebDAVName, setNewWebDAVName] = useState("");
@@ -120,6 +126,7 @@ export function ConfigEditor({
120126
apiKey: pendingApiKey,
121127
kuaidi100Key: pendingKuaidi100Key,
122128
kuaidi100Customer: pendingKuaidi100Customer,
129+
telegramTdataPath: pendingTelegramTdataPath,
123130
});
124131
} finally {
125132
setSavingConfig(false);
@@ -136,6 +143,7 @@ export function ConfigEditor({
136143
setPendingApiKey(initialApiKey || "");
137144
setPendingKuaidi100Key(initialKuaidi100Key || "");
138145
setPendingKuaidi100Customer(initialKuaidi100Customer || "");
146+
setPendingTelegramTdataPath(initialTelegramTdataPath || "");
139147
// Reset WebDAV form
140148
setNewWebDAVName("");
141149
setNewWebDAVUrl("");
@@ -296,6 +304,24 @@ export function ConfigEditor({
296304
</div>
297305
</div>
298306

307+
{/* Telegram Section */}
308+
<div className="text-sm font-semibold text-zinc-900 dark:text-white mt-4 mb-2 pt-3 border-t border-zinc-300 dark:border-zinc-700">
309+
Telegram
310+
</div>
311+
<div className="flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-3">
312+
<span className="sm:min-w-25 text-sm text-zinc-700 dark:text-zinc-200">
313+
TData Path
314+
</span>
315+
<input
316+
type="text"
317+
className={inputBaseClass}
318+
placeholder="Custom Telegram Desktop tdata directory path"
319+
value={pendingTelegramTdataPath}
320+
onChange={(e) => setPendingTelegramTdataPath(e.target.value)}
321+
disabled={!isConnected || savingConfig}
322+
/>
323+
</div>
324+
299325
{/* WebDAV Servers Section */}
300326
<div className="mt-4 pt-4 border-t border-zinc-300 dark:border-zinc-700">
301327
<div className="text-sm font-semibold text-zinc-900 dark:text-white mb-3">

ui/src/context/AppContext.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ interface AppContextType {
5757
kuaidi100Customer: string;
5858
configExists: boolean;
5959
torrentEnabled: boolean;
60+
telegramTdataPath: string;
6061

6162
// Translations
6263
t: UITranslations;
@@ -112,6 +113,7 @@ export function AppProvider({ children }: { children: ReactNode }) {
112113
const [kuaidi100Key, setKuaidi100Key] = useState("");
113114
const [kuaidi100Customer, setKuaidi100Customer] = useState("");
114115
const [torrentEnabled, setTorrentEnabled] = useState(false);
116+
const [telegramTdataPath, setTelegramTdataPath] = useState("");
115117
const [toasts, setToasts] = useState<ToastData[]>([]);
116118

117119
const showToast = useCallback((type: ToastType, message: string) => {
@@ -159,6 +161,7 @@ export function AppProvider({ children }: { children: ReactNode }) {
159161
setKuaidi100Key(kuaidi100Cfg?.key || "");
160162
setKuaidi100Customer(kuaidi100Cfg?.customer || "");
161163
setTorrentEnabled(configRes.data.torrent_enabled || false);
164+
setTelegramTdataPath(configRes.data.telegram_tdata_path || "");
162165
}
163166
if (i18nRes.code === 200) {
164167
// Merge with defaults to ensure new keys are available
@@ -246,6 +249,9 @@ export function AppProvider({ children }: { children: ReactNode }) {
246249
values.kuaidi100Customer
247250
);
248251
}
252+
if (values.telegramTdataPath) {
253+
await setConfigValue("telegram.tdata_path", values.telegramTdataPath);
254+
}
249255
refresh();
250256
},
251257
[refresh]
@@ -292,6 +298,7 @@ export function AppProvider({ children }: { children: ReactNode }) {
292298
kuaidi100Customer,
293299
configExists,
294300
torrentEnabled,
301+
telegramTdataPath,
295302
t,
296303
serverT,
297304
darkMode,

ui/src/pages/ConfigPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function ConfigPage() {
1616
apiKey,
1717
kuaidi100Key,
1818
kuaidi100Customer,
19+
telegramTdataPath,
1920
webdavServers,
2021
saveConfig,
2122
addWebDAV,
@@ -52,6 +53,7 @@ export function ConfigPage() {
5253
initialApiKey={apiKey}
5354
initialKuaidi100Key={kuaidi100Key}
5455
initialKuaidi100Customer={kuaidi100Customer}
56+
initialTelegramTdataPath={telegramTdataPath}
5557
serverPort={serverPort}
5658
webdavServers={webdavServers}
5759
onSave={handleSaveConfig}

0 commit comments

Comments
 (0)