-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlarge_files_handler.py
More file actions
600 lines (509 loc) · 26.7 KB
/
Copy pathlarge_files_handler.py
File metadata and controls
600 lines (509 loc) · 26.7 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
"""
טיפול בקבצים גדולים עם ממשק כפתורים מתקדם
Large Files Handler with Advanced Button Interface
"""
import logging
from io import BytesIO
from typing import Dict, List, Optional, Tuple
from telegram import (
InlineKeyboardButton,
InlineKeyboardMarkup,
InputFile,
Update
)
from telegram.ext import ContextTypes
from src.infrastructure.composition import get_files_facade
from utils import get_language_emoji, TextUtils
logger = logging.getLogger(__name__)
class LargeFilesHandler:
"""מנהל קבצים גדולים עם ממשק מתקדם"""
def __init__(self):
self.files_per_page = 8
self.preview_max_chars = 3500
def _facade(self):
"""גישה בטוחה ל-FilesFacade (ללא תלות ישירה ב-database מתוך handlers)."""
try:
return get_files_facade()
except Exception:
return None
def _fetch_full_large_file_content(self, user_id: int, file_data: Dict) -> Tuple[str, str]:
"""
מחזיר (content, language) ע"י שליפה מפורשת מה-DB כאשר הרשימה נטענה עם Smart Projection
(כלומר ללא השדה content).
חשוב: יש כאן בדיקת בעלות מינימלית כאשר השליפה נעשית לפי _id.
"""
file_name = file_data.get("file_name") or ""
language = (file_data.get("programming_language") or "text") if isinstance(file_data, dict) else "text"
content = file_data.get("content") if isinstance(file_data, dict) else ""
if isinstance(content, str) and content:
return content, str(language or "text")
full_doc: Optional[Dict] = None
facade = self._facade()
if facade is None:
raise RuntimeError("FilesFacade unavailable")
file_id = file_data.get("_id") if isinstance(file_data, dict) else None
if file_id:
try:
doc, is_large = facade.get_user_document_by_id(user_id=user_id, file_id=str(file_id))
if is_large and isinstance(doc, dict):
full_doc = doc
except Exception:
logger.error("שליפת מסמך קובץ גדול לפי id נכשלה", exc_info=True)
raise
if not full_doc:
try:
if file_name:
full_doc = facade.get_large_file(user_id, str(file_name))
except Exception:
logger.error("שליפת קובץ גדול לפי שם נכשלה", exc_info=True)
raise
if isinstance(full_doc, dict):
new_content = full_doc.get("content") or ""
new_lang = full_doc.get("programming_language") or language or "text"
try:
# רענון הקאש כדי למנוע "ניסיון שני עובד" ולהפוך את זה לדטרמיניסטי
file_data["content"] = new_content
if new_lang:
file_data["programming_language"] = new_lang
except Exception:
pass
return str(new_content or ""), str(new_lang or "text")
return "", str(language or "text")
async def show_large_files_menu(self, update: Update, context: ContextTypes.DEFAULT_TYPE, page: int = 1) -> None:
"""מציג תפריט קבצים גדולים עם ניווט בין עמודים"""
user_id = update.effective_user.id
# קבלת קבצים לעמוד הנוכחי
facade = self._facade()
if facade is None:
logger.error("FilesFacade unavailable while listing large files")
keyboard = [[InlineKeyboardButton("🔙 חזור", callback_data="files")]]
reply_markup = InlineKeyboardMarkup(keyboard)
text = "❌ לא ניתן לטעון כרגע את רשימת הקבצים הגדולים (בעיה במסד הנתונים)."
if hasattr(update, 'callback_query') and update.callback_query:
await update.callback_query.edit_message_text(text, reply_markup=reply_markup)
else:
await update.message.reply_text(text, reply_markup=reply_markup)
return
try:
files, total_count = facade.get_user_large_files(user_id, page=page, per_page=self.files_per_page)
except Exception:
logger.error("טעינת רשימת קבצים גדולים נכשלה (שגיאת DB)", exc_info=True)
keyboard = [[InlineKeyboardButton("🔙 חזור", callback_data="files")]]
reply_markup = InlineKeyboardMarkup(keyboard)
text = "❌ שגיאה במסד הנתונים בעת טעינת הרשימה. נסו שוב עוד רגע."
if hasattr(update, 'callback_query') and update.callback_query:
await update.callback_query.edit_message_text(text, reply_markup=reply_markup)
else:
await update.message.reply_text(text, reply_markup=reply_markup)
return
if not files and page == 1:
# אין קבצים בכלל
keyboard = [[InlineKeyboardButton("🔙 חזור", callback_data="files")]]
reply_markup = InlineKeyboardMarkup(keyboard)
text = (
"📂 **אין לך קבצים גדולים שמורים**\n\n"
"💡 **איך לשמור קבצים גדולים?**\n"
"• שלח קובץ טקסט לבוט\n"
"• הבוט ישמור אותו אוטומטית\n"
"• תמיכה עד 20MB!"
)
if hasattr(update, 'callback_query') and update.callback_query:
await update.callback_query.edit_message_text(
text, reply_markup=reply_markup, parse_mode='Markdown'
)
else:
await update.message.reply_text(
text, reply_markup=reply_markup, parse_mode='Markdown'
)
return
# חישוב מספר עמודים
total_pages = (total_count + self.files_per_page - 1) // self.files_per_page
# יצירת כפתורים לקבצים
keyboard = []
for i, file in enumerate(files):
file_name = file.get('file_name', 'קובץ ללא שם')
language = file.get('programming_language', 'text')
file_size = file.get('file_size', 0)
# שמירת מידע על הקובץ בקאש
file_index = f"lf_{page}_{i}"
if 'large_files_cache' not in context.user_data:
context.user_data['large_files_cache'] = {}
context.user_data['large_files_cache'][file_index] = file
# יצירת כפתור עם אימוג'י ומידע
emoji = get_language_emoji(language)
size_kb = file_size / 1024
button_text = f"{emoji} {file_name} ({size_kb:.1f}KB)"
# הוסף גם כפתור "שתף קוד" לתפריט מהרשימה (ObjectId מצוי במסמך)
row = [InlineKeyboardButton(
button_text,
callback_data=f"large_file_{file_index}"
)]
keyboard.append(row)
# כפתורי ניווט
nav_buttons = []
if page > 1:
nav_buttons.append(InlineKeyboardButton("⬅️ הקודם", callback_data=f"lf_page_{page-1}"))
if total_pages > 1:
nav_buttons.append(InlineKeyboardButton(f"📄 {page}/{total_pages}", callback_data="noop"))
if page < total_pages:
nav_buttons.append(InlineKeyboardButton("➡️ הבא", callback_data=f"lf_page_{page+1}"))
if nav_buttons:
keyboard.append(nav_buttons)
# כפתורים נוספים
keyboard.extend([
[InlineKeyboardButton("🔄 רענן", callback_data=f"lf_page_{page}")],
[InlineKeyboardButton("🔙 חזור", callback_data="files")]
])
reply_markup = InlineKeyboardMarkup(keyboard)
# טקסט כותרת
text = (
f"📚 **הקבצים הגדולים שלך**\n"
f"📊 סה\"כ: {total_count} קבצים\n"
f"📄 עמוד {page} מתוך {total_pages}\n\n"
"✨ לחץ על קובץ לצפייה וניהול:"
)
if hasattr(update, 'callback_query') and update.callback_query:
await update.callback_query.edit_message_text(
text, reply_markup=reply_markup, parse_mode='Markdown'
)
else:
await update.message.reply_text(
text, reply_markup=reply_markup, parse_mode='Markdown'
)
async def handle_file_selection(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""טיפול בבחירת קובץ גדול"""
query = update.callback_query
await query.answer()
# קבלת מידע על הקובץ
file_index = query.data.replace("large_file_", "")
large_files_cache = context.user_data.get('large_files_cache', {})
file_data = large_files_cache.get(file_index)
if not file_data:
await query.edit_message_text("❌ שגיאה בזיהוי הקובץ")
return
file_name = file_data.get('file_name', 'קובץ ללא שם')
language = file_data.get('programming_language', 'text')
file_size = file_data.get('file_size', 0)
lines_count = file_data.get('lines_count', 0)
created_at = file_data.get('created_at', 'לא ידוע')
# כפתורי פעולות
keyboard = [
[
InlineKeyboardButton("👁️ צפה בקובץ", callback_data=f"lf_view_{file_index}"),
InlineKeyboardButton("📥 הורד", callback_data=f"lf_download_{file_index}")
],
[
InlineKeyboardButton("📝 ערוך", callback_data=f"lf_edit_{file_index}"),
InlineKeyboardButton("🗑️ מחק", callback_data=f"lf_delete_{file_index}")
],
[
InlineKeyboardButton("📊 מידע מפורט", callback_data=f"lf_info_{file_index}")
],
[
InlineKeyboardButton("🔗 שתף קוד", callback_data=f"share_menu_id:{str(file_data.get('_id') or '')}")
],
[
InlineKeyboardButton("🔙 חזרה לרשימה", callback_data="show_large_files")
]
]
reply_markup = InlineKeyboardMarkup(keyboard)
# הכנת טקסט עם מידע על הקובץ
emoji = get_language_emoji(language)
size_kb = file_size / 1024
# בריחה בטוחה לשם קובץ בתוך Markdown: נשתמש ב-code span כדי לנטרל תווים בעייתיים
safe_file_name = str(file_name).replace('`', '\\`')
text = (
f"📄 `{safe_file_name}`\n\n"
f"{emoji} **שפה:** {language}\n"
f"💾 **גודל:** {size_kb:.1f}KB ({file_size:,} בתים)\n"
f"📏 **שורות:** {lines_count:,}\n"
f"📅 **נוצר:** {created_at}\n\n"
"🎯 בחר פעולה:"
)
await query.edit_message_text(
text,
reply_markup=reply_markup,
parse_mode='Markdown'
)
async def view_large_file(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""הצגת קובץ גדול - תצוגה מקדימה או שליחה כקובץ"""
query = update.callback_query
await query.answer()
# קבלת מידע על הקובץ
file_index = query.data.replace("lf_view_", "")
large_files_cache = context.user_data.get('large_files_cache', {})
file_data = large_files_cache.get(file_index)
if not file_data:
await query.edit_message_text("❌ שגיאה בזיהוי הקובץ")
return
user_id = update.effective_user.id
file_name = file_data.get('file_name', 'קובץ ללא שם')
try:
content, language = self._fetch_full_large_file_content(user_id, file_data)
except Exception:
logger.error("שליפת תוכן קובץ גדול נכשלה (שגיאת DB)", exc_info=True)
keyboard = [[InlineKeyboardButton("🔙 חזרה", callback_data=f"large_file_{file_index}")]]
await query.edit_message_text(
"❌ שגיאה במסד הנתונים בעת שליפת תוכן הקובץ. נסו שוב עוד רגע.",
reply_markup=InlineKeyboardMarkup(keyboard),
)
return
if not (isinstance(content, str) and content):
keyboard = [[InlineKeyboardButton("🔙 חזרה", callback_data=f"large_file_{file_index}")]]
await query.edit_message_text(
"❌ לא הצלחתי לשלוף את תוכן הקובץ (התוכן ריק או חסר).",
reply_markup=InlineKeyboardMarkup(keyboard),
)
return
# בדיקה אם הקובץ קטן מספיק להצגה בצ'אט
if len(content) <= self.preview_max_chars:
# הצגה ישירה עם Markdown ובלוק קוד; נבריח backticks כדי למנוע שבירה
safe_content = str(content).replace('```', '\\`\\`\\`')
formatted_content = f"```{language}\n{safe_content}\n```"
keyboard = [[InlineKeyboardButton("🔙 חזרה", callback_data=f"large_file_{file_index}")]]
reply_markup = InlineKeyboardMarkup(keyboard)
# בריחת שם הקובץ ל-Markdown כדי למנוע BadRequest על _ [] וכד'.
try:
safe_file_name = TextUtils.escape_markdown(file_name, version=1)
except Exception:
safe_file_name = str(file_name).replace('`', '\\`')
# נסה Markdown; אם נכשל, שלח ללא parse_mode
try:
await query.edit_message_text(
f"📄 **{safe_file_name}**\n\n{formatted_content}",
reply_markup=reply_markup,
parse_mode='Markdown'
)
except Exception:
await query.edit_message_text(
f"📄 {file_name}\n\n{content}",
reply_markup=reply_markup
)
else:
# הקובץ גדול מדי - נציג תצוגה מקדימה ונשלח כקובץ
preview = content[:self.preview_max_chars] + "\n\n... [המשך הקובץ נשלח כקובץ מצורף]"
keyboard = [[InlineKeyboardButton("🔙 חזרה", callback_data=f"large_file_{file_index}")]]
reply_markup = InlineKeyboardMarkup(keyboard)
# שליחת תצוגה מקדימה עם Markdown ובלוק קוד; נבריח backticks
safe_preview = str(preview).replace('```', '\\`\\`\\`')
formatted_preview = f"```{language}\n{safe_preview}\n```"
try:
safe_file_name = TextUtils.escape_markdown(file_name, version=1)
except Exception:
safe_file_name = str(file_name).replace('`', '\\`')
try:
await query.edit_message_text(
f"📄 **{safe_file_name}** (תצוגה מקדימה)\n\n{formatted_preview}",
reply_markup=reply_markup,
parse_mode='Markdown'
)
except Exception:
await query.edit_message_text(
f"📄 {file_name} (תצוגה מקדימה)\n\n{preview}",
reply_markup=reply_markup
)
# שליחת הקובץ המלא
file_bytes = BytesIO()
file_bytes.write(content.encode("utf-8"))
file_bytes.seek(0)
# בכיתוב של המסמך, נבריח שם קובץ ונמנע Markdown
await query.message.reply_document(
document=file_bytes,
filename=file_name,
caption=f"📄 הקובץ המלא: {file_name}",
)
async def download_large_file(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""הורדת קובץ גדול"""
query = update.callback_query
await query.answer("📥 מכין את הקובץ להורדה...")
# קבלת מידע על הקובץ
file_index = query.data.replace("lf_download_", "")
large_files_cache = context.user_data.get('large_files_cache', {})
file_data = large_files_cache.get(file_index)
if not file_data:
await query.edit_message_text("❌ שגיאה בזיהוי הקובץ")
return
user_id = update.effective_user.id
file_name = file_data.get('file_name', 'קובץ ללא שם')
try:
content, language = self._fetch_full_large_file_content(user_id, file_data)
except Exception:
logger.error("הכנת הורדה לקובץ גדול נכשלה (שגיאת DB)", exc_info=True)
keyboard = [[InlineKeyboardButton("🔙 חזרה", callback_data=f"large_file_{file_index}")]]
await query.edit_message_text(
"❌ שגיאה במסד הנתונים בעת הכנת ההורדה. נסו שוב עוד רגע.",
reply_markup=InlineKeyboardMarkup(keyboard),
)
return
if not (isinstance(content, str) and content):
keyboard = [[InlineKeyboardButton("🔙 חזרה", callback_data=f"large_file_{file_index}")]]
await query.edit_message_text(
"❌ לא הצלחתי להכין הורדה כי התוכן ריק/חסר.",
reply_markup=InlineKeyboardMarkup(keyboard),
)
return
# יצירת קובץ להורדה
file_bytes = BytesIO()
file_bytes.write(content.encode("utf-8"))
file_bytes.seek(0)
# שליחת הקובץ
await query.message.reply_document(
document=file_bytes,
filename=file_name,
caption=f"📥 {file_name}\n🔤 שפה: {language}\n💾 גודל: {len(content):,} תווים",
)
# חזרה לתפריט הקובץ
await self.handle_file_selection(update, context)
async def delete_large_file_confirm(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""אישור מחיקת קובץ גדול"""
query = update.callback_query
await query.answer()
file_index = query.data.replace("lf_delete_", "")
large_files_cache = context.user_data.get('large_files_cache', {})
file_data = large_files_cache.get(file_index)
if not file_data:
await query.edit_message_text("❌ שגיאה בזיהוי הקובץ")
return
file_name = file_data.get('file_name', 'קובץ ללא שם')
keyboard = [
[
InlineKeyboardButton("✅ כן, העבר לסל מיחזור", callback_data=f"lf_confirm_delete_{file_index}"),
InlineKeyboardButton("❌ ביטול", callback_data=f"large_file_{file_index}")
]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(
f"⚠️ **אזהרה**\n\n"
f"האם להעביר את הקובץ לסל המיחזור:\n"
f"📄 `{file_name}`?\n\n"
f"♻️ ניתן לשחזר מתוך סל המיחזור עד פקיעת התוקף",
reply_markup=reply_markup,
parse_mode='Markdown'
)
async def delete_large_file(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""מחיקת קובץ גדול"""
query = update.callback_query
await query.answer()
file_index = query.data.replace("lf_confirm_delete_", "")
large_files_cache = context.user_data.get('large_files_cache', {})
file_data = large_files_cache.get(file_index)
if not file_data:
await query.edit_message_text("❌ שגיאה בזיהוי הקובץ")
return
user_id = update.effective_user.id
file_name = file_data.get('file_name', 'קובץ ללא שם')
# מחיקת הקובץ
facade = self._facade()
if facade is None:
await query.edit_message_text("❌ לא ניתן למחוק כרגע — אין חיבור למסד הנתונים.")
return
try:
success = bool(facade.delete_large_file(user_id, file_name))
except Exception:
logger.error("מחיקת קובץ גדול נכשלה (שגיאת DB)", exc_info=True)
await query.edit_message_text("❌ שגיאה במסד הנתונים בעת מחיקת הקובץ. נסו שוב עוד רגע.")
return
if success:
# ניקוי הקאש
if file_index in large_files_cache:
del large_files_cache[file_index]
# בדוק אם נשארו קבצים פעילים
remaining_total = 0
try:
_remaining_files, remaining_total = facade.get_user_large_files(user_id, page=1, per_page=1)
except Exception:
# לא נכשיל את ה-flow על בדיקה "קוסמטית" של האם נשארו קבצים; נרשום לוג ונפול חזרה.
logger.error("בדיקת קבצים גדולים שנותרו נכשלה (שגיאת DB)", exc_info=True)
if remaining_total > 0:
keyboard = [[InlineKeyboardButton("🔙 חזרה לרשימה", callback_data="show_large_files")]]
else:
keyboard = [[InlineKeyboardButton("🔙 חזור", callback_data="files")]]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(
f"✅ **הקובץ הועבר לסל המיחזור!**\n\n"
f"📄 קובץ: `{file_name}`\n"
f"♻️ ניתן לשחזר אותו מתפריט '🗑️ סל מיחזור' עד למחיקה אוטומטית",
reply_markup=reply_markup,
parse_mode='Markdown'
)
else:
await query.edit_message_text("❌ שגיאה במחיקת הקובץ")
async def show_file_info(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""הצגת מידע מפורט על קובץ גדול"""
query = update.callback_query
await query.answer()
file_index = query.data.replace("lf_info_", "")
large_files_cache = context.user_data.get('large_files_cache', {})
file_data = large_files_cache.get(file_index)
if not file_data:
await query.edit_message_text("❌ שגיאה בזיהוי הקובץ")
return
file_name = file_data.get('file_name', 'קובץ ללא שם')
content = file_data.get('content', '')
language = file_data.get('programming_language', 'text')
file_size = file_data.get('file_size', 0)
lines_count = file_data.get('lines_count', 0)
created_at = file_data.get('created_at', 'לא ידוע')
updated_at = file_data.get('updated_at', 'לא ידוע')
tags = file_data.get('tags', [])
# חישוב סטטיסטיקות נוספות
words_count = len(content.split())
avg_line_length = len(content) // lines_count if lines_count > 0 else 0
# הכנת טקסט מידע
emoji = get_language_emoji(language)
size_kb = file_size / 1024
size_mb = size_kb / 1024
text = (
f"📊 **מידע מפורט על הקובץ**\n\n"
f"📄 **שם:** `{file_name}`\n"
f"{emoji} **שפה:** {language}\n"
f"💾 **גודל:** {size_kb:.1f}KB ({size_mb:.2f}MB)\n"
f"📏 **שורות:** {lines_count:,}\n"
f"📝 **מילים:** {words_count:,}\n"
f"🔤 **תווים:** {len(content):,}\n"
f"📐 **אורך שורה ממוצע:** {avg_line_length} תווים\n"
f"📅 **נוצר:** {created_at}\n"
f"🔄 **עודכן:** {updated_at}\n"
)
if tags:
text += f"🏷️ **תגיות:** {', '.join(tags)}\n"
keyboard = [[InlineKeyboardButton("🔙 חזרה", callback_data=f"large_file_{file_index}")]]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(
text,
reply_markup=reply_markup,
parse_mode='Markdown'
)
async def edit_large_file(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
"""התחלת תהליך עריכת קובץ גדול"""
query = update.callback_query
await query.answer()
file_index = query.data.replace("lf_edit_", "")
large_files_cache = context.user_data.get('large_files_cache', {})
file_data = large_files_cache.get(file_index)
if not file_data:
await query.edit_message_text("❌ שגיאה בזיהוי הקובץ")
from conversation_handlers import EDIT_CODE
return int(EDIT_CODE)
file_name = file_data.get('file_name', 'קובץ ללא שם')
# שמירת מידע על הקובץ לעריכה
context.user_data['editing_large_file'] = {
'file_index': file_index,
'file_name': file_name,
'file_data': file_data
}
keyboard = [[InlineKeyboardButton("❌ ביטול", callback_data=f"large_file_{file_index}")]]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(
f"✏️ **עריכת קובץ גדול**\n\n"
f"📄 קובץ: `{file_name}`\n\n"
f"⚠️ **שים לב:** עקב גודל הקובץ, העריכה תחליף את כל התוכן.\n"
f"📝 שלח את התוכן החדש המלא של הקובץ:",
reply_markup=reply_markup,
parse_mode='Markdown'
)
# החזרת מצב שיחה לעריכה
from conversation_handlers import EDIT_CODE
return int(EDIT_CODE)
# יצירת instance גלובלי
large_files_handler = LargeFilesHandler()